#!/usr/bin/python ### Copyright 2004, Matthew Schick ### Licensed As-Is ### ### Simple prog to rsync from various 3rd party ebuild servers. ### Portage-ng will include this functionality, but until then.... ### ### Todo: ### Add using cvs to sync ### Update portage cache after sync ### Add overlay dirs defined in /etc/conf.d/gensync to /etc/make.conf import fileinput,portage,sys from optparse import OptionParser conf_file='/etc/conf.d/gensync' sync_dict={} # Options setup usage = "usage: %prog [options] repo1 repo2" parser=OptionParser(usage=usage, version="GenSync 0.1") parser.add_option('-l','--list', help='List rsync sources and overlay directories', action='store_true', dest='list_repos') parser.add_option('-n','--noportage', help='Do not sync (emerge sync) after rsyncing overlays.', action='store_true', dest='no_portage') (options, args) = parser.parse_args() ### Taken from emerge mytimeout=180 if portage.settings.has_key("RSYNC_TIMEOUT"): try: mytimeout=int(portage.settings["RSYNC_TIMEOUT"]) except: pass rsynccommand="/usr/bin/rsync -rlptDvz --progress --delete --delete-after --timeout="+str(mytimeout)+" --exclude='distfiles/*' --exclude='local/*' --exclude='packages/*' " def process_line(line): """ Processes conf file, returns a dictionary with the repo name as the key and two-part list of rsync url and overlay dir respectively """ if line[:1] == "#": pass else: line=line.strip() line_lst=line.split('=') sync_name=line_lst[0] sync=line_lst[1].strip('"') sync=sync.split(' ') sync_dict[sync_name]=sync def strip_dict(sync_dict,args): """ Parses commandline args and returns dictionary of repositories """ out_dict={} for x in args: if sync_dict.has_key(x): out_dict[x]=sync_dict[x] if not out_dict: print "Please select a valid repository name!" sys.exit() return out_dict def dosync(sync_dict,args=''): """ Does the rsyncing """ if args: sync_dict=strip_dict(sync_dict,args) for name,lst in sync_dict.iteritems(): url=lst[0] overlay=lst[1] mycommand=rsynccommand+" "+url+"/* "+overlay print '\nSyncing '+name+'...' exitcode=portage.spawn(mycommand,portage.settings,free=1) if exitcode != 0: print "Rsync error!" sys.exit(1) if not options.no_portage: exitcode=portage.spawn("/usr/bin/emerge sync",portage.settings,free=1) if exitcode != 0: print "Rsync error!" sys.exit(1) else: print "Skipping portage sync..." def print_list(sync_dict): """ Prints list of rsync sources and their overlays """ for name,lst in sync_dict.iteritems(): url=lst[0] dir=lst[1] print 'Name: '+name print 'Overlay: '+dir print 'Rsync URL: '+url+'\n' try: for line in fileinput.input(conf_file): process_line(line) except: print conf_file+' missing or unreadable!' if options.list_repos: print_list(sync_dict) sys.exit() dosync(sync_dict,args) ## getopt method... deprecated for now #def usage(): # print "Usage: gensync.py options reponame" # print "-l --list List your rsync urls and local directories" # print "-h --help This message" #try: # opts,args=getopt.getopt(sys.argv[1:], "lh", ["list", "help"]) # print opts,args #except getopt.GetoptError: # usage() # sys.exit(2) #for o,a in opts: # if o in ("-h", "--help"): # usage() # sys.exit() # if o in ("-l", "--list"): # print_list(sync_dict) #