aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJauhien Piatlicki <piatlicki@gmail.com>2013-07-15 18:32:54 +0200
committerJauhien Piatlicki <jpiatlicki@zertisa.com>2013-07-15 18:32:54 +0200
commit83644c95ac2cf6e020663bf51a85b9411e25020c (patch)
tree41bc506e645ba7e27cc628ddfca6ac7ebeefb412 /g_sorcery/fileutils.py
parentg_sorcery/backend: fix, thanks to dol-sen (diff)
downloadg-sorcery-83644c95ac2cf6e020663bf51a85b9411e25020c.tar.gz
g-sorcery-83644c95ac2cf6e020663bf51a85b9411e25020c.tar.bz2
g-sorcery-83644c95ac2cf6e020663bf51a85b9411e25020c.zip
g_sorcery/fileutils: fast_manifest
Diffstat (limited to 'g_sorcery/fileutils.py')
-rw-r--r--g_sorcery/fileutils.py47
1 files changed, 46 insertions, 1 deletions
diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py
index 478570d..067ea42 100644
--- a/g_sorcery/fileutils.py
+++ b/g_sorcery/fileutils.py
@@ -11,7 +11,11 @@
:license: GPL-2, see LICENSE for more details.
"""
-import json, os, shutil
+import glob
+import json
+import hashlib
+import os
+import shutil
from .exceptions import FileJSONError
from .g_collections import Package, elist
@@ -153,3 +157,44 @@ def get_pkgpath(root = None):
if os.path.islink(root):
root = os.path.realpath(root)
return os.path.dirname(os.path.abspath(root))
+
+class ManifestEntry:
+ def __init__(self, directory, name, ftype):
+ self.directory = directory
+ self.name = name
+ self.ftype = ftype
+ self.digest()
+
+ def digest(self):
+ h_sha256 = hashlib.new('SHA256')
+ h_sha512 = hashlib.new('SHA512')
+ h_whirlpool = hashlib.new('whirlpool')
+ with open(os.path.join(self.directory, self.name), 'rb') as f:
+ src = f.read()
+ h_sha256.update(src)
+ h_sha512.update(src)
+ h_whirlpool.update(src)
+ self.size = str(len(src))
+ self.sha256 = h_sha256.hexdigest()
+ self.sha512 = h_sha512.hexdigest()
+ self.whirlpool = h_whirlpool.hexdigest()
+
+
+def fast_manifest(directory):
+ manifest = []
+ metadata = os.path.join(directory, "metadata.xml")
+
+ for aux in glob.glob(os.path.join(directory, "files/*")):
+ manifest.append(ManifestEntry(os.path.dirname(aux), os.path.basename(aux), "AUX"))
+ for ebuild in glob.glob(os.path.join(directory, "*.ebuild")):
+ manifest.append(ManifestEntry(directory, os.path.basename(ebuild), "EBUILD"))
+ if (os.path.isfile(metadata)):
+ manifest.append(ManifestEntry(directory, "metadata.xml", "MISC"))
+
+ manifest = [" ".join([m.ftype, m.name, m.size,
+ "SHA256", m.sha256, "SHA512", m.sha512,
+ "WHIRLPOOL", m.whirlpool])
+ for m in manifest]
+
+ with open(os.path.join(directory, "Manifest"), 'w') as f:
+ f.write('\n'.join(manifest))