recoll-we-move-files: do not accept downloadsdir parameter, add -c configdir option
The parameter was not used by recollindex anyway and the script NEEDS access to the config for retrieving other values. This can also be set with RECOLL_CONFDIR (which recollindex does).
This commit is contained in:
parent
8deed63be6
commit
422d24e94e
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/python3
|
||||||
# Copyright (C) 2017 J.F.Dockes
|
# Copyright (C) 2017-2022 J.F.Dockes
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -31,6 +31,7 @@ but it can also be run by hand.
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import getopt
|
||||||
try:
|
try:
|
||||||
from hashlib import md5 as md5
|
from hashlib import md5 as md5
|
||||||
except:
|
except:
|
||||||
@ -94,28 +95,44 @@ def list_all_files(dir):
|
|||||||
return mfiles,cfiles
|
return mfiles,cfiles
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
|
def msg(s):
|
||||||
|
print(f"{s}", file=sys.stderr)
|
||||||
def usage():
|
def usage():
|
||||||
print("Usage: recoll-we-move-files.py [<downloadsdir>]", file=sys.stderr)
|
msg("Usage: recoll-we-move-files.py [-c <recollconfigdir>]")
|
||||||
|
msg(" The script needs the recoll configuration directory. This can be set either through")
|
||||||
|
msg(" the RECOLL_CONFDIR environment variable or the '-c' command line option (which takes")
|
||||||
|
msg(" precedence). If none is set, the default configuration directory will be used.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
config = rclconfig.RclConfig()
|
|
||||||
|
|
||||||
# The directory where we find the files created by the browser extension is given as parameter, else
|
opts, args = getopt.getopt(sys.argv[1:], "c:")
|
||||||
# comes from the configuration else we use the default Downloads directory:
|
if not len(args) == 0:
|
||||||
if len(sys.argv) == 2:
|
|
||||||
downloadsdir = sys.argv[1]
|
|
||||||
elif len(sys.argv) == 1:
|
|
||||||
downloadsdir = config.getConfParam("webdownloadsdir")
|
|
||||||
if not downloadsdir:
|
|
||||||
downloadsdir = "~/Downloads"
|
|
||||||
downloadsdir = os.path.expanduser(downloadsdir)
|
|
||||||
else:
|
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
|
configdir = None
|
||||||
|
for opt,val in opts:
|
||||||
|
#logdeb(f"opt {opt} val {val}")
|
||||||
|
if opt == "-c":
|
||||||
|
configdir = val
|
||||||
|
if not os.path.isdir(val):
|
||||||
|
msg(f"{val} is not a directory")
|
||||||
|
usage()
|
||||||
|
else:
|
||||||
|
usage()
|
||||||
|
|
||||||
|
config = rclconfig.RclConfig(argcnf=configdir)
|
||||||
|
|
||||||
|
# Get the directory where the browser extension creates the page files. Our user can set it as a
|
||||||
|
# subdirectory of the default Downloads directory, for tidyness
|
||||||
|
downloadsdir = config.getConfParam("webdownloadsdir")
|
||||||
|
if not downloadsdir:
|
||||||
|
downloadsdir = "~/Downloads"
|
||||||
|
downloadsdir = os.path.expanduser(downloadsdir)
|
||||||
if not os.path.isdir(downloadsdir):
|
if not os.path.isdir(downloadsdir):
|
||||||
usage()
|
msg(f"Downloads directory {downloadsdir} does not exist")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Get the target webqueue recoll directory from the recoll configuration
|
# Get the target recoll webqueue directory, into which we are going to move the downloaded files.
|
||||||
webqueuedir = config.getConfParam("webqueuedir")
|
webqueuedir = config.getConfParam("webqueuedir")
|
||||||
if not webqueuedir:
|
if not webqueuedir:
|
||||||
if _mswindows:
|
if _mswindows:
|
||||||
@ -125,7 +142,8 @@ if not webqueuedir:
|
|||||||
webqueuedir = os.path.expanduser(webqueuedir)
|
webqueuedir = os.path.expanduser(webqueuedir)
|
||||||
os.makedirs(webqueuedir, exist_ok = True)
|
os.makedirs(webqueuedir, exist_ok = True)
|
||||||
|
|
||||||
# logdeb("webqueuedir is %s" % webqueuedir)
|
|
||||||
|
#logdeb(f"recoll confdir [{configdir}] downloadsdir [{downloadsdir}] webqueuedir [{webqueuedir}]")
|
||||||
|
|
||||||
# Get the lists of all files created by the browser addon
|
# Get the lists of all files created by the browser addon
|
||||||
mfiles, cfiles = list_all_files(downloadsdir)
|
mfiles, cfiles = list_all_files(downloadsdir)
|
||||||
@ -143,7 +161,7 @@ cfiles = delete_previous_instances(cfiles, downloadsdir)
|
|||||||
# The old plugin created the data first, so we move data then meta
|
# The old plugin created the data first, so we move data then meta
|
||||||
for hash in cfiles.keys():
|
for hash in cfiles.keys():
|
||||||
if hash in mfiles.keys():
|
if hash in mfiles.keys():
|
||||||
newname = "firefox-recoll-web-"+hash
|
newname = "firefox-recoll-web-" + hash
|
||||||
shutil.move(os.path.join(downloadsdir, cfiles[hash]),
|
shutil.move(os.path.join(downloadsdir, cfiles[hash]),
|
||||||
os.path.join(webqueuedir, newname))
|
os.path.join(webqueuedir, newname))
|
||||||
shutil.move(os.path.join(downloadsdir, mfiles[hash]),
|
shutil.move(os.path.join(downloadsdir, mfiles[hash]),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user