Permalink
Browse files

Merge pull request #7 from fedora-infra/feature/tmpdir

Feature/tmpdir
  • Loading branch information...
2 parents a1f3cca + 40fb257 commit ab6feea5bd120ca2fcb4f5d9b6846b40d78903df @ralphbean ralphbean committed Feb 19, 2014
Showing with 10 additions and 7 deletions.
  1. 0 downloads/.placeholder
  2. +0 −1 fedmsg.d/example-config.py
  3. +6 −1 summershum/core.py
  4. +4 −5 summershum/utils.py
View
No changes.
@@ -7,7 +7,6 @@
'summershum.sqlalchemy.url': 'sqlite:////var/tmp/summershum.sqlite',
'summershum.lookaside': 'http://pkgs.fedoraproject.org/lookaside/pkgs/',
'summershum.datagrepper': 'https://apps.fedoraproject.org/datagrepper/',
- 'summershum.tmpdir': 'downloads',
# Here is where we will publish our status
'endpoints': {
View
@@ -3,10 +3,14 @@
import fedmsg
import logging
+import tempfile
+import os
+import shutil
log = logging.getLogger("summershum")
def ingest(session, msg, config, force=False):
+ tmpdir = tempfile.mkdtemp()
try:
found = summershum.model.File.by_tar_sum(session, msg['md5sum'])
@@ -21,7 +25,6 @@ def ingest(session, msg, config, force=False):
)
lookaside_url = config['summershum.lookaside']
- tmpdir = config['summershum.tmpdir']
summershum.utils.download_lookaside(msg, lookaside_url, tmpdir)
summershum.utils.calculate_sums(session, msg, tmpdir)
@@ -41,3 +44,5 @@ def ingest(session, msg, config, force=False):
topic='ingest.complete',
msg=dict(original=msg),
)
+ if tmpdir and os.path.exists(tmpdir):
+ shutil.rmtree(tmpdir)
View
@@ -1,13 +1,11 @@
import hashlib
import os
-import shutil
-import sys
import requests
from subprocess import Popen, PIPE
-from model import File, create_session
+from model import File
import logging
log = logging.getLogger("summershum")
@@ -38,6 +36,7 @@ def calculate_sums(session, message, tmpdir):
and browse the sources of the specified package and for each of the
files in the sources get their sha256sum, sha1sum, and md5sum.
"""
+
local_filename = "/".join([tmpdir, message['filename']])
if not os.path.exists(local_filename):
@@ -65,6 +64,7 @@ def calculate_sums(session, message, tmpdir):
for fname, sha256sum, sha1sum, md5sum in walk_directory(filename):
count = count + 1
pkgobj = File.exists(session, message['md5sum'], fname)
+ fname = fname.replace(tmpdir, '')
if not pkgobj:
pkgobj = File(
pkg_name=message['name'],
@@ -81,8 +81,7 @@ def calculate_sums(session, message, tmpdir):
pass
session.commit()
- if filename and os.path.exists(filename):
- shutil.rmtree(filename)
+ if local_filename and os.path.exists(local_filename):
os.unlink(local_filename)
log.info("Stored %i of %i files" % (stored, count))

0 comments on commit ab6feea

Please sign in to comment.