diff options
author | Auke Booij (tulcod) <auke@tulcod.com> | 2010-06-09 00:13:55 +0200 |
---|---|---|
committer | Auke Booij (tulcod) <auke@tulcod.com> | 2010-06-09 00:13:55 +0200 |
commit | c002d6b716636c36af7979730f91b481a202a054 (patch) | |
tree | af62c6f6077c04e70cca7e1c9e5fcfef935e3be0 | |
parent | Initial commit (diff) | |
download | g-cran-c002d6b716636c36af7979730f91b481a202a054.tar.gz g-cran-c002d6b716636c36af7979730f91b481a202a054.tar.bz2 g-cran-c002d6b716636c36af7979730f91b481a202a054.zip |
Some rfc822 black magic, let's hope this keeps working during the next few weeks...
-rwxr-xr-x | g-cran.py | 158 |
1 files changed, 93 insertions, 65 deletions
@@ -29,78 +29,104 @@ class Package(): self.restrict=[] self.properties='' + +class EmptyLinesFile: + def __init__(self,myfile): + self.file=myfile + self.eof=False + self.lines=self.generate_lines() + def generate_lines(self,size=-1): + for line in self.file: + yield line + self.eof=True + def readline(self): + try: + return self.lines.next() + except StopIteration: + return '' + #This function is not being used anywhere and may be removed -def read_settings(repo_location): - try: - settings_file=open(os.path.join(repo_location,REPO_MYDIR,REPO_CONFFILE),'r') - settings={} - for line in settings_file: - parts=string.split(line,'=') - if len(parts)==1: - raise ValueError - settings[parts[0]]='='.join(parts[1:]) - return settings - except IOError: - print "Could not open settings file at "+settings_file - print "If you haven't synced this repository yet, please append the remote repository's URI" - sys.exit(0) +#def read_settings(repo_location): +# try: +# settings_file=open(os.path.join(repo_location,REPO_MYDIR,REPO_CONFFILE),'r') +# settings={} +# for line in settings_file: +# parts=string.split(line,'=') +# if len(parts)==1: +# raise ValueError +# settings[parts[0]]='='.join(parts[1:]) +# return settings +# except IOError: +# print "Could not open settings file at "+settings_file +# print "If you haven't synced this repository yet, please append the remote repository's URI" +# sys.exit(0) #Parse package options into values we can work with in accordance with PMS -def pmsify_packages_data(datadict): - data=datadict +def pmsify_packages_data(data): #fix settings: - if not re.match('[a-zA-Z0-9+_].*',data['Package']): #package name may not be valid according to PMS - data['Package']='_'+package_name - if re.match('.*-[0-9]+',data['Package']): - data['Package']=package_name+'_' - #data['Package']=data['Package'] - if 'Version' not in data: #set a version even if we have none - data['Version']='0' + if 'package' not in data: + data['package']='test' + if not re.match('[a-zA-Z0-9+_].*',data['package']): #package name may not be valid according to PMS + data['package']='_'+package_name + if re.match('.*-[0-9]+',data['package']): + data['package']=package_name+'_' + #data['package']=data['package'] + if 'version' not in data: #set a version even if we have none + data['version']='0' else: - data['Version']=data['Version'].replace('-','.') #some CRAN-style versions have the form 0.1-1, which we transform into 0.1.1 - if 'Depends' in data: - #dependencies=re.split('([a-zA-Z0-9+_-]+[ \t]+\(.+?\)[ \t]+)',data['Depends']) - dependencies=re.split(r'([a-zA-Z0-9+_-]+[ \t]+\\(.+?\\))|([a-zA-Z0-9+_-]+)[ \t]+',data['Depends']) #split into packages + versions - data['Depends']=['dev-lang/R',]+dependencies #fixme check + data['version']=data['version'].replace('-','.') #some CRAN-style versions have the form 0.1-1, which we transform into 0.1.1 + if 'depends' in data: + #dependencies=re.split('([a-zA-Z0-9+_-]+[ \t]+\(.+?\)[ \t]+)',data['depends']) + dependencies=re.split(r'([a-zA-Z0-9+_-]+[ \t]+\\(.+?\\))|([a-zA-Z0-9+_-]+)[ \t]+',data['depends']) #split into packages + versions + data['depends']=['dev-lang/R',]+dependencies #fixme check else: #some packages don't set dependencies - data['Depends']=['dev-lang/R',] + data['depends']=['dev-lang/R',] return data def read_packages(package_filename): - try: - packages_file=open(package_filename) - packages={} - data={} - package_name='' - current_variable='' - #current_value='' - for line in packages_file: - if len(line)==0: #empty line, process settings - pmsify_packages_data(data) - continue - matches=re.match('^\s*([a-zA-Z0-9_-])\s*:\s*(.+?)\s*',line) - if matches!=None: #new setting is starting - current_variable=matches.group(1) - data[current_variable]=matches.group(2)000 - pass - else: #append setting data to current setting - data[current_variable]+=line - #if len(line)==0: - # if package_name!='': - # data={} - # package_name='' - # continue - #parts=string.split(line,':') - #variable=parts[0].strip() - #value=':'.join(parts[1:]).strip() - #if package_name=='' and variable=='Package': - # package_name=value - #else: - # data[variable]=value - except IOError: - print "Could not open PACKAGES file at "+package_filename - print "If you haven't synced this repository yet, please do so first" - sys.exit(0) +# try: +# packages_file=open(package_filename) +# packages={} +# data={} +# package_name='' +# current_variable='' +# #current_value='' +# for line in packages_file: +# if len(line)==0: #empty line, process settings +# pmsify_packages_data(data) +# continue +# matches=re.match('^\s*([a-zA-Z0-9_-])\s*:\s*(.+?)\s*',line) +# if matches!=None: #new setting is starting +# current_variable=matches.group(1) +# data[current_variable]=matches.group(2)000 +# pass +# else: #append setting data to current setting +# data[current_variable]+=line +# #if len(line)==0: +# # if package_name!='': +# # data={} +# # package_name='' +# # continue +# #parts=string.split(line,':') +# #variable=parts[0].strip() +# #value=':'.join(parts[1:]).strip() +# #if package_name=='' and variable=='package': +# # package_name=value +# #else: +# # data[variable]=value +# except IOError: +# print "Could not open PACKAGES file at "+package_filename +# print "If you haven't synced this repository yet, please do so first" +# sys.exit(0) + packages_file=open(package_filename,"r") + file_parts=EmptyLinesFile(packages_file) #this is where we split the PACKAGES file into several file parts + packages=[] + import rfc822 + while not file_parts.eof: + new_package=dict(rfc822.Message(file_parts).items()) #read part of PACKAGES file + pmsify_packages_data(new_package) #fix values + packages.append(new_package) #store in dict + print packages def action_sync(repo_location,remote_uri): if not os.path.isdir(os.path.join(repo_location, REPO_MYDIR)): @@ -108,7 +134,9 @@ def action_sync(repo_location,remote_uri): os.mkdir(os.path.join(repo_location,REPO_MYDIR)) else: raise IOError - urllib.urlretrieve(remote_uri+'/src/contrib/PACKAGES',os.path.join(repo_location, REPO_MYDIR, 'PACKAGES')) + packages_filename=os.path.join(repo_location, REPO_MYDIR, 'PACKAGES') + urllib.urlretrieve(remote_uri+'/src/contrib/PACKAGES',packages_filename) + read_packages(packages_filename) raise NotImplementedError def list_categories(repo_location): @@ -117,7 +145,7 @@ def list_categories(repo_location): def list_packages(repo_location): package_file=read_packages(os.path.join(repo_location,REPO_MYDIR,'PACKAGES')) for package, package_metadata in package_file.items(): - print "dev-R/"+package+"-"+package_metadata['Version'] + print "dev-R/"+package+"-"+package_metadata['version'] def usage(): print __doc__ |