summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--g_common/g_common.py70
1 files changed, 62 insertions, 8 deletions
diff --git a/g_common/g_common.py b/g_common/g_common.py
index 216ca06..dfe8da7 100644
--- a/g_common/g_common.py
+++ b/g_common/g_common.py
@@ -75,6 +75,65 @@ def list_packages(repo_location):
return os.system(driver_conf['exec']+" "+repo_location+" list-packages")
+def parse_manifest(manifest_file):
+ manifest=open(manifest_file)
+ digests={}
+ for line in manifest:
+ parts=line.split(' ')
+ type=parts[0]
+ file=parts[1]
+ size=parts[2]
+ hashes={}
+ for i in range((len(parts)-3)/2):
+ hashes[parts[3+i*2]]=parts[4+i*2]
+ digests[file]=(type,file,size,hashes)
+ manifest.close()
+ return digests
+
+def generate_digest(dir,entry,type):
+ import hashlib
+ full_name=os.path.join(dir,entry)
+ return (type,os.path.relpath(full_name,dir),os.path.getsize(full_name),{'SHA1':hashlib.sha1(open(full_name).read()).hexdigest()})
+
+def write_manifest(manifest,filename):
+ manifest_file=open(filename,'w')
+ for file, data in manifest.items():
+ hashes=[key+' '+value for key,value in data[3].items()]
+ manifest_file.write("%s %s %d %s\n" % (data[0], data[1], int(data[2]), ' '.join(hashes)))
+ manifest_file.close()
+
+def populate_manifest(manifest_file,dir):
+ import hashlib
+ ebuild_file=settings.COMMON_EBUILD_FILE #get from settings
+ ebuild_digest=hashlib.sha1(open(ebuild_file).read()).hexdigest()
+
+ if os.path.exists(manifest_file):
+ manifest=parse_manifest(manifest_file)
+ else:
+ manifest={}
+ for entry in os.listdir(dir):
+ full_entry=os.path.join(dir,entry)
+ if not os.path.isfile(full_entry): #we don't deal with dirs and stuff
+ continue
+ elif entry[0]=='.': #hidden file, skip
+ continue
+ elif entry[-len('.ebuild'):]=='.ebuild': #ends in .ebuild
+ manifest[entry]=('EBUILD',entry,os.path.getsize(full_entry),{'SHA1':ebuild_digest})
+ elif entry=='ChangeLog' or entry=='metadata.xml':
+ manifest[entry]=generate_digest(dir,entry,'MISC')
+ else:
+ raise NotImplementedError #can't deduce file type
+ files_dir=os.path.join(dir,'files')
+ if os.path.exists(files_dir):
+ for entry in os.listdir(files_dir):
+ full_entry=os.path.join(files_dir,entry)
+ if not os.path.isfile(full_entry): #don't process dirs
+ continue
+ else:
+ digest=generate_digest(files_dir,entry,'AUX')
+ manifest[digest[1]]=digest
+ write_manifest(manifest,manifest_file)
+
#generate a tree of ebuilds... note that we only link ebuild files, instead of generating them
#we will, however, generate metadata.xml and Manifest files
def generate_tree(repo_location,generate_manifest,generate_metadata):
@@ -82,10 +141,6 @@ def generate_tree(repo_location,generate_manifest,generate_metadata):
repo_conf=read_repo_config(repo_location)
driver_conf=read_driver_config(repo_conf['driver'])
- ebuild_file=settings.COMMON_EBUILD_FILE #get from settings
- ebuild_digest=hashlib.sha1(open(ebuild_file).read()).hexdigest()
- Manifest="EBUILD %s "+str(os.path.getsize(ebuild_file))+" SHA1 "+ebuild_digest
-
#clean repo
visible_files=[x for x in os.listdir(repo_location) if x[0]!='.']
import shutil
@@ -116,6 +171,7 @@ def generate_tree(repo_location,generate_manifest,generate_metadata):
if returncode:
return returncode
+ ebuild_file=settings.COMMON_EBUILD_FILE #get from settings
#write symlinks
for line in packages:
category=line[:line.find("/")]
@@ -124,10 +180,6 @@ def generate_tree(repo_location,generate_manifest,generate_metadata):
ebuild_dir=os.path.join(repo_location,category,package)
package_file=package+'-'+version+'.ebuild'
os.symlink(ebuild_file,os.path.join(ebuild_dir,package_file))
- if generate_manifest:
- manifest_file=open(os.path.join(ebuild_dir,'Manifest'),"w")
- manifest_file.write(Manifest % package_file)
- manifest_file.close()
if generate_metadata:
metadata_file=open(os.path.join(ebuild_dir,'metadata.xml'),'w')
metadata_file.write("""
@@ -137,6 +189,8 @@ def generate_tree(repo_location,generate_manifest,generate_metadata):
</pkgmetadata>
""") #write minimalistic metadata.xml
metadata_file.close()
+ if generate_manifest:
+ populate_manifest(os.path.join(ebuild_dir,'Manifest'),ebuild_dir)
#write repo metadata
if not os.path.exists(os.path.join(repo_location,'profiles','repo_name')):
import string