summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Borretti <eudoxiahp@gmail.com>2015-01-15 19:47:30 -0200
committerFernando Borretti <eudoxiahp@gmail.com>2015-01-15 19:47:30 -0200
commit529829cc3509a9b7975cd0334151f93714f87b55 (patch)
tree1271cdc51364217a7f8951ae5ee50ee25088ad5a
parentf28b1eb11518bf43da5a82d92f29a0d5894f256c (diff)
downloadpaperbot-529829cc3509a9b7975cd0334151f93714f87b55.tar.gz
paperbot-529829cc3509a9b7975cd0334151f93714f87b55.zip
Clean up paperbot.storage
-rw-r--r--paperbot/storage.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/paperbot/storage.py b/paperbot/storage.py
index bae0717..86bebc3 100644
--- a/paperbot/storage.py
+++ b/paperbot/storage.py
@@ -16,12 +16,14 @@ if not os.path.exists(DEFAULT_STORAGE_PATH):
DEFAULT_STORAGE_PATH = "/tmp/"
STORAGE_PATH = os.environ.get("STORAGE_PATH", DEFAULT_STORAGE_PATH)
+
def make_random_string(bits=128):
"""
Make a random string suitable as a filename.
"""
return "%0.2x" % random.getrandbits(bits)
+
def make_hash(content):
"""
Calculate md5 sum of the content.
@@ -30,6 +32,7 @@ def make_hash(content):
md5sum.update(content)
return md5sum.hexdigest()
+
def make_pdf_filename(paper, pdfcontent=None):
"""
Construct a filename for the pdf of this paper.
@@ -47,12 +50,14 @@ def make_pdf_filename(paper, pdfcontent=None):
return pdf_filename
+
def make_full_path(filename, storage_path=STORAGE_PATH):
"""
Construct a full path including the filename.
"""
return os.path.join(storage_path, filename)
+
def store_json(paper, storage_path=STORAGE_PATH):
"""
Store paper metadata somewhere.
@@ -76,6 +81,7 @@ def store_json(paper, storage_path=STORAGE_PATH):
return jsonpath
+
def store_logs(paper, templogpath):
"""
Store logs near other paper files. Return the path.
@@ -92,6 +98,7 @@ def store_logs(paper, templogpath):
return desiredpath
+
def store(paper, pdfcontent=None):
"""
Save a paper to the file system.