From 38f2a84e8e1802268eeaff78cf6e0b884b807bfe Mon Sep 17 00:00:00 2001 From: dsheyp Date: Tue, 21 Oct 2014 16:38:06 +0200 Subject: [PATCH 1/7] set expires-attribute for cookies Internet Explorer needs the expires-attribute to be present in order to make the cookies persistent. --- webui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index 425884d..fc7d764 100755 --- a/webui.py +++ b/webui.py @@ -342,10 +342,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=3153600000) 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=3153600000) bottle.redirect('./') #}}} #{{{ osd From 3504092c209472360457c955c04d94bf58942ebb Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Thu, 1 Jan 2015 08:56:24 +0100 Subject: [PATCH 2/7] Changed the value of set_cookie() 'expires' from 3x10**9 3x10**8 (10 years) The initial value was triggering 2038 issues or some platforms (or pure integer overflows, did not check). Also admit long as param type inside set_cookie() as there does not seem to be any reason not to. --- bottle.py | 2 +- webui.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bottle.py b/bottle.py index 5bbbbd1..399c3b1 100644 --- a/bottle.py +++ b/bottle.py @@ -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 diff --git a/webui.py b/webui.py index fc7d764..4fa9d27 100755 --- a/webui.py +++ b/webui.py @@ -342,10 +342,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, expires=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, expires=3153600000) + bottle.response.set_cookie(cookie_name, str(bottle.request.query.get('mount_%s' % d)), max_age=3153600000, expires=315360000) bottle.redirect('./') #}}} #{{{ osd From 1a249aa52fdbb87fa5f63c0b4a187ce40ef90e41 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Mon, 10 Nov 2014 22:45:32 +0100 Subject: [PATCH 3/7] Change directory only if needed --- webui-standalone.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webui-standalone.py b/webui-standalone.py index 6c8684c..d808555 100755 --- a/webui-standalone.py +++ b/webui-standalone.py @@ -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) From 451f6001593d1b7269e1eb588ff94ed8c8e8824c Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Wed, 12 Nov 2014 21:53:12 +0100 Subject: [PATCH 4/7] Set Content-Length header in /download --- webui.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webui.py b/webui.py index 4fa9d27..4d9c5ad 100755 --- a/webui.py +++ b/webui.py @@ -296,6 +296,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) @@ -358,3 +359,4 @@ def main(): return {'url': url} #}}} # vim: fdm=marker:tw=80:ts=4:sw=4:sts=4:et + From 967590b6204509b0c56f257b390486d3c0c579f5 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Wed, 12 Nov 2014 21:54:56 +0100 Subject: [PATCH 5/7] Create a .gitignore to hide .pyc files from git --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc From 66321af8a3985e9719d35436db3bf0f0ee4a6782 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 30 Apr 2016 08:48:09 +0200 Subject: [PATCH 6/7] Let the user choose the fields included for CSV extraction --- views/settings.tpl | 3 +++ webui.py | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/views/settings.tpl b/views/settings.tpl index 3d24214..2d3490c 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -22,6 +22,9 @@ {{d}} %end
+ CSV fields ({{fields}})
+ +
Add to browser
Register recoll into browser search engines diff --git a/webui.py b/webui.py index 4d9c5ad..980a6d9 100755 --- a/webui.py +++ b/webui.py @@ -38,6 +38,7 @@ 'maxchars': 500, 'maxresults': 0, 'perpage': 25, + 'csvfields': 'filename title author size time mtype url', } # sort fields/labels @@ -111,6 +112,11 @@ def get_config(): 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']: @@ -175,7 +181,7 @@ def endMatch(self): return '' #}}} #{{{ recoll_search -def recoll_search(q): +def recoll_search(q, dosnippets=True): config = get_config() tstart = datetime.datetime.now() results = [] @@ -213,7 +219,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 @@ -317,18 +324,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") From cfb65646f469e43f1b2c789a0d49e0300f58fbbc Mon Sep 17 00:00:00 2001 From: koniu Date: Mon, 23 May 2016 13:15:39 +0100 Subject: [PATCH 7/7] Expand tilde in topdirs (fixes #50) Topdirs in recoll.conf starting with ~ wouldn't show in 'Folder' dropdown because glob.glob() doesn't do tilde expansion. Explicit os.path.expanduser() added. --- webui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 980a6d9..15f326a 100755 --- a/webui.py +++ b/webui.py @@ -106,7 +106,8 @@ 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():