3 # expected argument is a URL on build.onelab.eu
4 # this would then update the alpha node repo from that place
6 # the actual list of rpms that are needed or nodes is hard-coded
8 import sys, os, os.path, glob, commands
9 from optparse import OptionParser
11 standard_repo = '/var/www/html/install-rpms/onelab-i386'
12 alpha_repo = '%s-alpha'%standard_repo
14 #################### from module-tools
15 def prompt (question,default=True):
18 if default is True: choices.append('[y]')
19 else : choices.append('y')
20 if default is False: choices.append('[n]')
21 else : choices.append('n')
24 answer=raw_input(question + " " + "/".join(choices) + " ? ")
27 answer=answer[0].lower()
32 return prompt(question,default)
37 def run (command,options,force=False):
38 if ( force or not options.dry_run):
39 print 'Running',command
42 print 'Would run',command
44 # rewrite the http part into a rsync part
45 def http_to_rsync (http):
46 result = http.replace ('http://build.onelab.eu/','root@build.onelab.eu:/build/')
47 # canonicalize : strip last / if present
48 while (result[-1]=='/'): result=result[0:-1]
51 def rsync_xfer(http,repo,options):
53 command='mkdir -p %s' % xfer
57 if options.dry_run: command += ' -n'
58 command += ' ' + http_to_rsync(http) + ' ' + xfer
61 def rpm_name (rpm_file):
62 status,output = commands.getstatusoutput("rpm -q --qf '%%{NAME}' -p %s " % rpm_file)
65 def extract_contents (standard):
66 patt= '%s/*.rpm' % standard
67 rpm_files=glob.glob(patt)
68 contents = [ rpm_name(rpm_file) for rpm_file in rpm_files]
71 def install_xfer (repo,rpm_name,options):
72 xfer_patt= '%s/xfer/RPMS/*/%s*.rpm' % (repo, rpm_name);
73 xfer_rpm_names=glob.glob(xfer_patt)
74 for xfer_rpm_name in xfer_rpm_names:
75 command = 'mv %s %s' % ( xfer_rpm_name, repo)
76 if prompt('Adopt %s'%os.path.basename(xfer_rpm_name)):
79 def remaining_rpms (root):
80 command="find %s -name '*.rpm'"%root
81 status,output = commands.getstatusoutput(command)
82 return output.split("\n")
84 def scan_remaining (repo,options):
85 for rpm in remaining_rpms('%s/xfer' % repo):
86 basename=os.path.basename(rpm)
87 command="mv %s %s/%s"%(rpm,repo,basename)
88 if prompt('Adopt %s'%basename,False):
92 usage="Usage:%prog http://build.onelab.eu/.../RPMS"
93 parser=OptionParser(usage=usage)
94 parser.add_option("-n","--dry-run",action="store_true",dest="dry_run",default=False,
96 parser.add_option("-r","--repo",action="store",dest="repo",default=alpha_repo,
97 help="the repo to populate")
98 parser.add_option("-s","--std",action="store",dest="standard",default=standard_repo,
99 help="the standard repo, used to compute the set of rpms")
100 (options, args) = parser.parse_args()
107 standard=options.standard
110 if os.path.isdir(xfer):
111 if prompt('Want to clean up %s'%xfer,False):
112 run('rm -rf %s'%xfer,options)
114 if prompt ('Need to fetch rpms from %s ' % http):
115 rsync_xfer(http,repo,options)
117 if prompt ('Install yumgroups'):
118 command="mv %s/xfer/RPMS/yumgroups.xml %s/"%(repo,repo)
121 if prompt ('Get list of standard rpms from %s ' % standard):
122 rpm_names=extract_contents(standard)
124 if prompt ('Moving standard rpms to %s' % repo):
125 for rpm_name in rpm_names:
126 install_xfer(repo,rpm_name,options)
128 # once here, we have moved all the rpms that belonged to the standard noderepo
129 # let's manually scan the other ones as there might be new rpms needed
130 # the list proposed here contains mostly server-side rpms,
131 # so the prompt default is False
132 if prompt ('Scan remaining rpms for double-check'):
133 scan_remaining(repo,options)
135 if prompt ('Nuke repodata (force complete reindexing)'):
136 command="rm -rf %s/repodata %s/signed-stamps"%(repo,repo)
139 if prompt ('Reindex'):
140 run('service plc start packages',options)
142 if __name__ == '__main__':