Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syncing fork dsheyp/recoll-webui with upstream repository koniu/recoll-webui. #1

Merged
merged 9 commits into from
Jul 11, 2016
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
2 changes: 1 addition & 1 deletion bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ def set_cookie(self, name, value, secret=None, **options):
if key == 'expires':
if isinstance(value, (datedate, datetime)):
value = value.timetuple()
elif isinstance(value, (int, float)):
elif isinstance(value, (int, long, float)):
value = time.gmtime(value)
value = time.strftime("%a, %d %b %Y %H:%M:%S GMT", value)
self._cookies[name][key.replace('_', '-')] = value
Expand Down
3 changes: 3 additions & 0 deletions views/settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<small>{{d}}</small><input name="mount_{{d}}" value={{mounts[d]}}>
%end
<hr>
<b>CSV fields</b> <small class="gray">({{fields}})</small><br>
<input name="csvfields" value="{{csvfields}}">
<hr>
<b>Add to browser</b>
<br>
<a href="#" onClick="addOpenSearch();return false">Register recoll into browser search engines</a>
Expand Down
3 changes: 2 additions & 1 deletion webui-standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
args = parser.parse_args()

# change to webui's directory and import
os.chdir(os.path.dirname(__file__))
if os.path.dirname(__file__) != "":
os.chdir(os.path.dirname(__file__))

# set up webui and run in own http server
webui.bottle.debug(True)
Expand Down
28 changes: 20 additions & 8 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'maxchars': 500,
'maxresults': 0,
'perpage': 25,
'csvfields': 'filename title author size time mtype url',
}

# sort fields/labels
Expand Down Expand Up @@ -105,12 +106,18 @@ def get_config():
# get useful things from recoll.conf
rclconf = rclconfig.RclConfig()
config['confdir'] = rclconf.getConfDir()
config['dirs'] = shlex.split(rclconf.getConfParam('topdirs'))
config['dirs'] = [os.path.expanduser(d) for d in
shlex.split(rclconf.getConfParam('topdirs'))]
config['stemlang'] = rclconf.getConfParam('indexstemminglanguages')
# get config from cookies or defaults
for k, v in DEFAULTS.items():
value = select([bottle.request.get_cookie(k), v])
config[k] = type(v)(value)
# Fix csvfields: get rid of invalid ones to avoid needing tests in the dump function
cf = config['csvfields'].split()
ncf = [f for f in cf if f in FIELDS]
config['csvfields'] = ' '.join(ncf)
config['fields'] = ' '.join(FIELDS)
# get mountpoints
config['mounts'] = {}
for d in config['dirs']:
Expand Down Expand Up @@ -175,7 +182,7 @@ def endMatch(self):
return '</span>'
#}}}
#{{{ recoll_search
def recoll_search(q):
def recoll_search(q, dosnippets=True):
config = get_config()
tstart = datetime.datetime.now()
results = []
Expand Down Expand Up @@ -213,7 +220,8 @@ def recoll_search(q):
d['label'] = select([d['title'], d['filename'], '?'], [None, ''])
d['sha'] = hashlib.sha1(d['url']+d['ipath']).hexdigest()
d['time'] = timestr(d['mtime'], config['timefmt'])
d['snippet'] = query.makedocabstract(doc, highlighter).encode('utf-8')
if dosnippets:
d['snippet'] = query.makedocabstract(doc, highlighter).encode('utf-8')
results.append(d)
tend = datetime.datetime.now()
return results, nres, tend - tstart
Expand Down Expand Up @@ -296,6 +304,7 @@ def edit(resnum):
bottle.response.headers['Content-Disposition'] = \
'attachment; filename="%s"' % os.path.basename(path).encode('utf-8')
path = path.encode('utf-8')
bottle.response.headers['Content-Length'] = os.stat(path).st_size
f = open(path, 'r')
if pathismine:
os.unlink(path)
Expand All @@ -316,18 +325,20 @@ def get_json():
#{{{ csv
@bottle.route('/csv')
def get_csv():
config = get_config()
query = get_query()
query['page'] = 0
qs = query_to_recoll_string(query)
bottle.response.headers['Content-Type'] = 'text/csv'
bottle.response.headers['Content-Disposition'] = 'attachment; filename=recoll-%s.csv' % normalise_filename(qs)
res, nres, timer = recoll_search(query)
res, nres, timer = recoll_search(query, False)
si = StringIO.StringIO()
cw = csv.writer(si)
cw.writerow(FIELDS)
fields = config['csvfields'].split()
cw.writerow(fields)
for doc in res:
row = []
for f in FIELDS:
for f in fields:
row.append(doc[f])
cw.writerow(row)
return si.getvalue().strip("\r\n")
Expand All @@ -342,10 +353,10 @@ def settings():
def set():
config = get_config()
for k, v in DEFAULTS.items():
bottle.response.set_cookie(k, str(bottle.request.query.get(k)), max_age=3153600000)
bottle.response.set_cookie(k, str(bottle.request.query.get(k)), max_age=3153600000, expires=315360000)
for d in config['dirs']:
cookie_name = 'mount_%s' % urllib.quote(d, '')
bottle.response.set_cookie(cookie_name, str(bottle.request.query.get('mount_%s' % d)), max_age=3153600000)
bottle.response.set_cookie(cookie_name, str(bottle.request.query.get('mount_%s' % d)), max_age=3153600000, expires=315360000)
bottle.redirect('./')
#}}}
#{{{ osd
Expand All @@ -358,3 +369,4 @@ def main():
return {'url': url}
#}}}
# vim: fdm=marker:tw=80:ts=4:sw=4:sts=4:et