--- a/alexandria.py Mon Jul 14 12:56:57 2008 -0400
+++ b/alexandria.py Mon Jul 14 13:09:22 2008 -0400
@@ -44,10 +44,7 @@
m.update(fd.read())
fd.close()
- path = os.path.abspath(path)
- commonpath = os.path.commonprefix([options.commonpath, path])
- path = path[len(commonpath):]
- path = path.strip('/')
+ path = _short_path(path, options)
p = Paper.get_by(path = path) or Paper.get_by(md5 = m.hexdigest())
if p is not None:
print _colorize_string('error', "Paper already exists, use update")
@@ -64,6 +61,7 @@
def update(args, options):
"""update paper by hash"""
p = Paper.query.filter(Paper.md5.startswith(args[0])).one()
+ if len(args) > 1: p.path = _short_path(args[1], options)
_set_options(p, options)
session.flush()
_show_paper(p)
@@ -166,10 +164,7 @@
if len(args) == 0:
print _colorize_string('error', 'Need path to check as an argument.')
- path = os.path.abspath(args[0])
- commonpath = os.path.commonprefix([options.commonpath, path])
- path = path[len(commonpath):]
- path = path.strip('/')
+ path = _short_path(args[0], options)
paper = Paper.get_by(path = path)
if paper:
@@ -177,6 +172,13 @@
else:
print "No such path %s found" % _colorize_string('path', path)
+def _short_path(path, options):
+ path = os.path.abspath(path)
+ commonpath = os.path.commonprefix([options.commonpath, path])
+ path = path[len(commonpath):]
+ path = path.strip('/')
+ return path
+
def _set_options(p, options, required = []):
title = options.title or ('title' in required) and raw_input("Enter title: ")
if title: