|
a/src/filters/recoll-we-move-files.py |
|
b/src/filters/recoll-we-move-files.py |
|
... |
|
... |
40 |
try:
|
40 |
try:
|
41 |
from recoll import rclconfig
|
41 |
from recoll import rclconfig
|
42 |
except:
|
42 |
except:
|
43 |
import rclconfig
|
43 |
import rclconfig
|
44 |
|
44 |
|
|
|
45 |
verbosity = 0
|
45 |
def logdeb(s):
|
46 |
def logdeb(s):
|
|
|
47 |
if verbosity >= 4:
|
46 |
print("%s"%s, file=sys.stderr)
|
48 |
print("%s"%s, file=sys.stderr)
|
47 |
|
49 |
|
48 |
# # wnloaded instances of the same page are suffixed with (nn) by the
|
50 |
# # wnloaded instances of the same page are suffixed with (nn) by the
|
49 |
# browser. We are passed a list of (hash, instancenum, filename)
|
51 |
# browser. We are passed a list of (hash, instancenum, filename)
|
50 |
# triplets, sort it, and keep only the latest file.
|
52 |
# triplets, sort it, and keep only the latest file.
|
51 |
def delete_previous_instances(l, downloadsdir):
|
53 |
def delete_previous_instances(l, downloadsdir):
|
|
... |
|
... |
92 |
#######################
|
94 |
#######################
|
93 |
def usage():
|
95 |
def usage():
|
94 |
print("Usage: recoll-we-move-files.py [<downloaddir>]", file=sys.stderr)
|
96 |
print("Usage: recoll-we-move-files.py [<downloaddir>]", file=sys.stderr)
|
95 |
sys.exit(1)
|
97 |
sys.exit(1)
|
96 |
|
98 |
|
|
|
99 |
config = rclconfig.RclConfig()
|
|
|
100 |
|
97 |
# Source dir is parameter, else default Downloads directory
|
101 |
# Source dir is parameter, else from config else default Downloads directory
|
|
|
102 |
downloadsdir = config.getConfParam("webdownloadsdir")
|
|
|
103 |
if not downloadsdir:
|
98 |
downloadsdir = os.path.expanduser("~/Downloads")
|
104 |
downloadsdir = os.path.expanduser("~/Downloads")
|
99 |
if len(sys.argv) == 2:
|
105 |
if len(sys.argv) == 2:
|
100 |
mydir = sys.argv[1]
|
106 |
mydir = sys.argv[1]
|
101 |
elif len(sys.argv) == 1:
|
107 |
elif len(sys.argv) == 1:
|
102 |
mydir = downloadsdir
|
108 |
mydir = downloadsdir
|
103 |
else:
|
109 |
else:
|
104 |
usage()
|
110 |
usage()
|
105 |
if not os.path.isdir(mydir):
|
111 |
if not os.path.isdir(mydir):
|
106 |
usage()
|
112 |
usage()
|
107 |
|
113 |
|
108 |
# Get target webqueue recoll directory from recoll configuration
|
114 |
# Get target webqueue recoll directory from recoll configuration
|
109 |
config = rclconfig.RclConfig()
|
|
|
110 |
webqueuedir = config.getConfParam("webqueuedir")
|
115 |
webqueuedir = config.getConfParam("webqueuedir")
|
111 |
if not webqueuedir:
|
116 |
if not webqueuedir:
|
112 |
webqueuedir = "~/.recollweb/ToIndex"
|
117 |
webqueuedir = "~/.recollweb/ToIndex"
|
113 |
webqueuedir = os.path.expanduser(webqueuedir)
|
118 |
webqueuedir = os.path.expanduser(webqueuedir)
|
|
|
119 |
os.makedirs(webqueuedir, exist_ok = True)
|
|
|
120 |
|
114 |
logdeb("webqueuedir is %s" % webqueuedir)
|
121 |
# logdeb("webqueuedir is %s" % webqueuedir)
|
115 |
|
122 |
|
116 |
# Get the lists of all files created by the browser addon
|
123 |
# Get the lists of all files created by the browser addon
|
117 |
mfiles, cfiles = list_all_files(mydir)
|
124 |
mfiles, cfiles = list_all_files(mydir)
|
118 |
|
125 |
|
119 |
# Only keep the last version
|
126 |
# Only keep the last version
|
|
... |
|
... |
128 |
# happen that a data file is missing, keep them for next pass.
|
135 |
# happen that a data file is missing, keep them for next pass.
|
129 |
# The old plugin created the data first, so we move data then meta
|
136 |
# The old plugin created the data first, so we move data then meta
|
130 |
for hash in cfiles.keys():
|
137 |
for hash in cfiles.keys():
|
131 |
if hash in mfiles.keys():
|
138 |
if hash in mfiles.keys():
|
132 |
newname = "firefox-recoll-web-"+hash
|
139 |
newname = "firefox-recoll-web-"+hash
|
133 |
shutil.move(cfiles[hash], os.path.join(webqueuedir, newname))
|
140 |
shutil.move(os.path.join(downloadsdir, cfiles[hash]),
|
134 |
shutil.move(mfiles[hash], os.path.join(webqueuedir, "." + newname))
|
141 |
os.path.join(webqueuedir, newname))
|
|
|
142 |
shutil.move(os.path.join(downloadsdir, mfiles[hash]),
|
|
|
143 |
os.path.join(webqueuedir, "." + newname))
|
135 |
|
144 |
|
136 |
|
145 |
|