summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAuke Booij (tulcod) <auke@tulcod.com>2010-08-03 00:34:59 +0200
committerAuke Booij (tulcod) <auke@tulcod.com>2010-08-03 00:51:29 +0200
commitc95004403d0bfdf7c8d6a88932161acd51dcbf3c (patch)
treeede60bd6f06a5954ce546c2d9c12c3cacda89283
parentUgh, ebuild function fix (diff)
downloadg-cran-c95004403d0bfdf7c8d6a88932161acd51dcbf3c.tar.gz
g-cran-c95004403d0bfdf7c8d6a88932161acd51dcbf3c.tar.bz2
g-cran-c95004403d0bfdf7c8d6a88932161acd51dcbf3c.zip
Write metadata.xml, clean repo, populate profiles/, call drivers' generate-manifest action
-rw-r--r--g_common/g_common.py62
1 files changed, 58 insertions, 4 deletions
diff --git a/g_common/g_common.py b/g_common/g_common.py
index 1d942e5..e7c8ca1 100644
--- a/g_common/g_common.py
+++ b/g_common/g_common.py
@@ -82,27 +82,80 @@ def generate_tree(repo_location,generate_manifest,generate_metadata):
repo_conf=read_repo_config(repo_location)
driver_conf=read_driver_config(repo_conf['driver'])
- if generate_metadata:
- raise NotImplementedError
-
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
+ for dir in visible_files:
+ try:
+ shutil.rmtree(os.path.join(repo_location,dir))
+ except:
+ pass
+
+ #create directory structure
packages_list_pipe=subprocess.Popen(driver_conf['exec']+' '+repo_location+' list-packages',shell=True,stdout=subprocess.PIPE)
os.waitpid(packages_list_pipe.pid,0)
+ if packages_list_pipe.returncode:
+ return returncode
+ packages=[]
for line in packages_list_pipe.stdout:
category=line[:line.find("/")]
package=line[line.find("/")+1:line.find(" ")]
version=line[line.find(" ")+1:-1]
ebuild_dir=os.path.join(repo_location,category,package)
- if not os.path.exists(ebuild_dir):
+ packages.append(line)
+ if not os.path.exists(ebuild_dir): #obvious race condition, but whatever
os.makedirs(ebuild_dir)
+ os.makedirs(os.path.join(repo_location,'profiles'))
+
+ #call driver generate-metadata to give it a chance to fill up the repo
+ returncode=os.system(driver_conf['exec']+" "+repo_location+" generate-metadata")
+ if returncode:
+ return returncode
+
+ #write symlinks
+ for line in packages:
+ category=line[:line.find("/")]
+ package=line[line.find("/")+1:line.find(" ")]
+ version=line[line.find(" ")+1:-1]
+ 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("""
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+ <pkgmetadata>
+ </pkgmetadata>
+ """) #write minimalistic metadata.xml
+ metadata_file.close()
+ #write repo metadata
+ if not os.path.exists(os.path.join(repo_location,'profiles','repo_name')):
+ #make up a name
+ #as a lucky guess, use the last part of the repo_location directory location
+ repo_location_parts=os.path.split(repo_location)
+ if len(repo_location_parts): #repo might be locaten in /... unlikely, but i was in a good mood while typing this
+ raw_name=repo_location_parts[-1]
+ name=''.join([x for x in raw_name if x.isalnum() or x=='_' or x=='-']) #hope that there won't be any utf8 issues
+ if name[0]=='-': #name may not begin with a hyphen
+ name=name[1:]
+ else:
+ name='common-repo' #fallback
+ repo_name_file=open(os.path.join(repo_location,'profiles','repo_name'),'w')
+ repo_name_file.write(name)
+ repo_name_file.close()
+ if not os.path.exists(os.path.join(repo_location,'profiles','categories')):
+ categories_file=open(os.path.join(repo_location,'profiles','categories'),'w')
+ categories_file.write('\n'.join(list(set([package[:package.find('/')] for package in packages])))) #now isn't that a readable oneliner
+ categories_file.close()
return 0
#list package details, in PMS's format
@@ -112,6 +165,7 @@ def action_package(repo_location,package_name):
return os.system(driver_conf['exec']+" "+repo_location+" package "+package_name)
+#do one of the ebuild phases
def exec_phase(repo_location,phase):
repo_conf=read_repo_config(repo_location)
driver_conf=read_driver_config(repo_conf['driver'])