diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc 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/views/settings.tpl b/views/settings.tpl index 3d24214..2d3490c 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -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> 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) diff --git a/webui.py b/webui.py index 425884d..15f326a 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 @@ -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']: @@ -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 = [] @@ -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 @@ -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) @@ -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") @@ -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 @@ -358,3 +369,4 @@ def main(): return {'url': url} #}}} # vim: fdm=marker:tw=80:ts=4:sw=4:sts=4:et +