5 import sys, os, os.path
9 from optparse import OptionParser
11 # e.g. other_choices = [ ('d','iff') , ('g','uess') ] - lowercase
12 def prompt (question,default=True,other_choices=[],allow_outside=False):
13 if not isinstance (other_choices,list):
14 other_choices = [ other_choices ]
15 chars = [ c for (c,rest) in other_choices ]
19 if default is True: choices.append('[y]')
20 else : choices.append('y')
22 if default is False: choices.append('[n]')
23 else : choices.append('n')
25 for (char,choice) in other_choices:
27 choices.append("["+char+"]"+choice)
29 choices.append("<"+char+">"+choice)
31 answer=raw_input(question + " " + "/".join(choices) + " ? ")
34 answer=answer[0].lower()
36 if 'y' in chars: return 'y'
39 if 'n' in chars: return 'n'
42 for (char,choice) in other_choices:
47 return prompt(question,default,other_choices)
53 editor = os.environ['EDITOR']
59 def __init__ (self,command,options):
62 self.tmp="/tmp/command-%d"%os.getpid()
65 if self.options.verbose and self.options.mode not in Main.silent_modes:
66 print '+',self.command
68 return os.system(self.command)
70 def run_silent (self):
71 if self.options.verbose:
72 print '+',self.command,' .. ',
74 retcod=os.system(self.command + " &> " + self.tmp)
76 print "FAILED ! -- output quoted below "
77 os.system("cat " + self.tmp)
78 print "FAILED ! -- end of quoted output"
79 elif self.options.verbose:
85 if self.run_silent() !=0:
86 raise Exception,"Command %s failed"%self.command
88 # returns stdout, like bash's $(mycommand)
89 def output_of (self,with_stderr=False):
90 tmp="/tmp/status-%d"%os.getpid()
91 if self.options.debug:
92 print '+',self.command,' .. ',
101 result=file(tmp).read()
103 if self.options.debug:
108 def __init__(self,path,options):
112 def url_exists (self):
113 return os.system("svn list %s &> /dev/null"%self.path) == 0
115 def dir_needs_revert (self):
116 command="svn status %s"%self.path
117 return len(Command(command,self.options).output_of(True)) != 0
118 # turns out it's the same implem.
119 def file_needs_commit (self):
120 command="svn status %s"%self.path
121 return len(Command(command,self.options).output_of(True)) != 0
125 svn_magic_line="--This line, and those below, will be ignored--"
127 redirectors=[ # ('module_name_varname','name'),
128 ('module_version_varname','version'),
129 ('module_taglevel_varname','taglevel'), ]
131 # where to store user's config
132 config_storage="CONFIG"
137 configKeys=[ ('svnpath',"Enter your toplevel svnpath",
138 "svn+ssh://%s@svn.planet-lab.org/svn/"%commands.getoutput("id -un")),
139 ("build", "Enter the name of your build module","build"),
140 ('username',"Enter your firstname and lastname for changelogs",""),
141 ("email","Enter your email address for changelogs",""),
145 def prompt_config ():
146 for (key,message,default) in Module.configKeys:
147 Module.config[key]=""
148 while not Module.config[key]:
149 Module.config[key]=raw_input("%s [%s] : "%(message,default)).strip() or default
152 # for parsing module spec name:branch
153 matcher_branch_spec=re.compile("\A(?P<name>[\w-]+):(?P<branch>[\w\.-]+)\Z")
154 matcher_rpm_define=re.compile("%(define|global)\s+(\S+)\s+(\S*)\s*")
156 def __init__ (self,module_spec,options):
158 attempt=Module.matcher_branch_spec.match(module_spec)
160 self.name=attempt.group('name')
161 self.branch=attempt.group('branch')
163 self.name=module_spec
167 self.moddir="%s/%s"%(options.workdir,self.name)
169 def friendly_name (self):
173 return "%s:%s"%(self.name,self.branch)
177 return "%s/trunk"%(self.moddir)
179 return "%s/branches/%s"%(self.moddir,self.branch)
182 return "%s/tags"%(self.moddir)
184 def run (self,command):
185 return Command(command,self.options).run()
186 def run_fatal (self,command):
187 return Command(command,self.options).run_fatal()
188 def run_prompt (self,message,command):
189 if not self.options.verbose:
191 choice=prompt(message,True,('s','how'))
195 elif choice is False:
198 print 'About to run:',command
200 question=message+" - want to run " + command
201 if prompt(question,True):
205 def init_homedir (options):
206 topdir=options.workdir
207 if options.verbose and options.mode not in Main.silent_modes:
208 print 'Checking for',topdir
209 storage="%s/%s"%(topdir,Module.config_storage)
210 # sanity check. Either the topdir exists AND we have a config/storage
211 # or topdir does not exist and we create it
212 # to avoid people use their own daily svn repo
213 if os.path.isdir(topdir) and not os.path.isfile(storage):
214 print """The directory %s exists and has no CONFIG file
215 If this is your regular working directory, please provide another one as the
216 module-* commands need a fresh working dir. Make sure that you do not use
217 that for other purposes than tagging"""%topdir
219 if not os.path.isdir (topdir):
220 print "Cannot find",topdir,"let's create it"
221 Module.prompt_config()
222 print "Checking ...",
223 Command("svn co -N %s %s"%(Module.config['svnpath'],topdir),options).run_fatal()
224 Command("svn co -N %s/%s %s/%s"%(Module.config['svnpath'],
225 Module.config['build'],
227 Module.config['build']),options).run_fatal()
232 for (key,message,default) in Module.configKeys:
233 f.write("%s=%s\n"%(key,Module.config[key]))
236 print 'Stored',storage
237 Command("cat %s"%storage,options).run()
241 for line in f.readlines():
242 (key,value)=re.compile("^(.+)=(.+)$").match(line).groups()
243 Module.config[key]=value
245 if options.verbose and options.mode not in Main.silent_modes:
246 print '******** Using config'
247 for (key,message,default) in Module.configKeys:
248 print '\t',key,'=',Module.config[key]
250 def init_moddir (self):
251 if self.options.verbose:
252 print 'Checking for',self.moddir
253 if not os.path.isdir (self.moddir):
254 self.run_fatal("svn up -N %s"%self.moddir)
255 if not os.path.isdir (self.moddir):
256 raise Exception, 'Cannot find %s - check module name'%self.moddir
258 def init_subdir (self,fullpath):
259 if self.options.verbose:
260 print 'Checking for',fullpath
261 if not os.path.isdir (fullpath):
262 self.run_fatal("svn up -N %s"%fullpath)
264 def revert_subdir (self,fullpath):
265 if self.options.fast_checks:
266 if self.options.verbose: print 'Skipping revert of %s'%fullpath
268 if self.options.verbose:
269 print 'Checking whether',fullpath,'needs being reverted'
270 if Svnpath(fullpath,self.options).dir_needs_revert():
271 self.run_fatal("svn revert -R %s"%fullpath)
273 def update_subdir (self,fullpath):
274 if self.options.fast_checks:
275 if self.options.verbose: print 'Skipping update of %s'%fullpath
277 if self.options.verbose:
278 print 'Updating',fullpath
279 self.run_fatal("svn update -N %s"%fullpath)
281 def init_edge_dir (self):
282 # if branch, edge_dir is two steps down
284 self.init_subdir("%s/branches"%self.moddir)
285 self.init_subdir(self.edge_dir())
287 def revert_edge_dir (self):
288 self.revert_subdir(self.edge_dir())
290 def update_edge_dir (self):
291 self.update_subdir(self.edge_dir())
293 def main_specname (self):
294 attempt="%s/%s.spec"%(self.edge_dir(),self.name)
295 if os.path.isfile (attempt):
299 return glob("%s/*.spec"%self.edge_dir())[0]
301 raise Exception, 'Cannot guess specfile for module %s'%self.name
303 def all_specnames (self):
304 return glob("%s/*.spec"%self.edge_dir())
306 def parse_spec (self, specfile, varnames):
307 if self.options.verbose:
308 print 'Parsing',specfile,
314 for line in f.readlines():
315 attempt=Module.matcher_rpm_define.match(line)
317 (define,var,value)=attempt.groups()
321 if self.options.debug:
322 print 'found',len(result),'keys'
323 for (k,v) in result.iteritems():
327 # stores in self.module_name_varname the rpm variable to be used for the module's name
328 # and the list of these names in self.varnames
329 def spec_dict (self):
330 specfile=self.main_specname()
331 redirector_keys = [ varname for (varname,default) in Module.redirectors]
332 redirect_dict = self.parse_spec(specfile,redirector_keys)
333 if self.options.debug:
334 print '1st pass parsing done, redirect_dict=',redirect_dict
336 for (varname,default) in Module.redirectors:
337 if redirect_dict.has_key(varname):
338 setattr(self,varname,redirect_dict[varname])
339 varnames += [redirect_dict[varname]]
341 setattr(self,varname,default)
342 varnames += [ default ]
343 self.varnames = varnames
344 result = self.parse_spec (specfile,self.varnames)
345 if self.options.debug:
346 print '2st pass parsing done, varnames=',varnames,'result=',result
349 def patch_spec_var (self, patch_dict,define_missing=False):
350 for specfile in self.all_specnames():
351 # record the keys that were changed
352 changed = dict ( [ (x,False) for x in patch_dict.keys() ] )
353 newspecfile=specfile+".new"
354 if self.options.verbose:
355 print 'Patching',specfile,'for',patch_dict.keys()
357 new=open(newspecfile,"w")
359 for line in spec.readlines():
360 attempt=Module.matcher_rpm_define.match(line)
362 (define,var,value)=attempt.groups()
363 if var in patch_dict.keys():
364 if self.options.debug:
365 print 'rewriting %s as %s'%(var,patch_dict[var])
366 new.write('%%%s %s %s\n'%(define,var,patch_dict[var]))
371 for (key,was_changed) in changed.iteritems():
373 if self.options.debug:
374 print 'rewriting missed %s as %s'%(key,patch_dict[key])
375 new.write('%%define %s %s\n'%(key,patch_dict[key]))
378 os.rename(newspecfile,specfile)
380 def unignored_lines (self, logfile):
382 exclude="Tagging module %s"%self.name
383 for logline in file(logfile).readlines():
384 if logline.strip() == Module.svn_magic_line:
386 if logline.find(exclude) < 0:
387 result += [ logline ]
390 def insert_changelog (self, logfile, oldtag, newtag):
391 for specfile in self.all_specnames():
392 newspecfile=specfile+".new"
393 if self.options.verbose:
394 print 'Inserting changelog from %s into %s'%(logfile,specfile)
396 new=open(newspecfile,"w")
397 for line in spec.readlines():
399 if re.compile('%changelog').match(line):
400 dateformat="* %a %b %d %Y"
401 datepart=time.strftime(dateformat)
402 logpart="%s <%s> - %s"%(Module.config['username'],
403 Module.config['email'],
405 new.write(datepart+" "+logpart+"\n")
406 for logline in self.unignored_lines(logfile):
407 new.write("- " + logline)
411 os.rename(newspecfile,specfile)
413 def show_dict (self, spec_dict):
414 if self.options.verbose:
415 for (k,v) in spec_dict.iteritems():
419 return "%s/%s"%(Module.config['svnpath'],self.name)
423 return "%s/trunk"%(self.mod_url())
425 return "%s/branches/%s"%(self.mod_url(),self.branch)
427 def tag_name (self, spec_dict):
429 return "%s-%s-%s"%(#spec_dict[self.module_name_varname],
431 spec_dict[self.module_version_varname],
432 spec_dict[self.module_taglevel_varname])
434 raise Exception, 'Something is wrong with module %s, cannot determine %s - exiting'%(self.name,err)
436 def tag_url (self, spec_dict):
437 return "%s/tags/%s"%(self.mod_url(),self.tag_name(spec_dict))
439 def check_svnpath_exists (self, url, message):
440 if self.options.fast_checks:
442 if self.options.verbose:
443 print 'Checking url (%s) %s'%(url,message),
444 ok=Svnpath(url,self.options).url_exists()
446 if self.options.verbose: print 'exists - OK'
448 if self.options.verbose: print 'KO'
449 raise Exception, 'Could not find %s URL %s'%(message,url)
451 def check_svnpath_not_exists (self, url, message):
452 if self.options.fast_checks:
454 if self.options.verbose:
455 print 'Checking url (%s) %s'%(url,message),
456 ok=not Svnpath(url,self.options).url_exists()
458 if self.options.verbose: print 'does not exist - OK'
460 if self.options.verbose: print 'KO'
461 raise Exception, '%s URL %s already exists - exiting'%(message,url)
463 # locate specfile, parse it, check it and show values
465 ##############################
466 def do_version (self):
469 self.revert_edge_dir()
470 self.update_edge_dir()
471 spec_dict = self.spec_dict()
472 for varname in self.varnames:
473 if not spec_dict.has_key(varname):
474 print 'Could not find %%define for %s'%varname
477 print "%-16s %s"%(varname,spec_dict[varname])
478 if self.options.show_urls:
479 print "%-16s %s"%('edge url',self.edge_url())
480 print "%-16s %s"%('latest tag url',self.tag_url(spec_dict))
481 if self.options.verbose:
482 print "%-16s %s"%('main specfile:',self.main_specname())
483 print "%-16s %s"%('specfiles:',self.all_specnames())
485 ##############################
487 # print 'verbose',self.options.verbose
488 # print 'list_tags',self.options.list_tags
489 # print 'list_branches',self.options.list_branches
490 # print 'all_modules',self.options.all_modules
492 (verbose,branches,pattern,exact) = (self.options.verbose,self.options.list_branches,
493 self.options.list_pattern,self.options.list_exact)
501 if verbose: grep="%s/$"%exact
502 else: grep="^%s$"%exact
505 extra_command=" | grep %s"%grep
506 extra_message=" matching %s"%grep
509 message="==================== tags for %s"%self.friendly_name()
511 if verbose: command+="--verbose "
512 command += "%s/tags"%self.mod_url()
513 command += extra_command
514 message += extra_message
515 if verbose: print message
519 message="==================== branches for %s"%self.friendly_name()
521 if verbose: command+="--verbose "
522 command += "%s/branches"%self.mod_url()
523 command += extra_command
524 message += extra_message
525 if verbose: print message
528 ##############################
529 sync_warning="""*** WARNING
530 The module-init function has the following limitations
531 * it does not handle changelogs
532 * it does not scan the -tags*.mk files to adopt the new tags"""
535 if self.options.verbose:
536 print Module.sync_warning
537 if not prompt('Want to proceed anyway'):
542 self.revert_edge_dir()
543 self.update_edge_dir()
544 spec_dict = self.spec_dict()
546 edge_url=self.edge_url()
547 tag_name=self.tag_name(spec_dict)
548 tag_url=self.tag_url(spec_dict)
549 # check the tag does not exist yet
550 self.check_svnpath_not_exists(tag_url,"new tag")
552 if self.options.message:
553 svnopt='--message "%s"'%self.options.message
555 svnopt='--editor-cmd=%s'%self.options.editor
556 self.run_prompt("Create initial tag",
557 "svn copy %s %s %s"%(svnopt,edge_url,tag_url))
559 ##############################
560 def do_diff (self,compute_only=False):
563 self.revert_edge_dir()
564 self.update_edge_dir()
565 spec_dict = self.spec_dict()
566 self.show_dict(spec_dict)
568 edge_url=self.edge_url()
569 tag_url=self.tag_url(spec_dict)
570 self.check_svnpath_exists(edge_url,"edge track")
571 self.check_svnpath_exists(tag_url,"latest tag")
572 command="svn diff %s %s"%(tag_url,edge_url)
574 if self.options.verbose:
575 print 'Getting diff with %s'%command
576 diff_output = Command(command,self.options).output_of()
577 # if used as a utility
579 return (spec_dict,edge_url,tag_url,diff_output)
580 # otherwise print the result
581 if self.options.list:
585 if not self.options.only or diff_output:
586 print 'x'*30,'module',self.friendly_name()
587 print 'x'*20,'<',tag_url
588 print 'x'*20,'>',edge_url
591 ##############################
592 # using fine_grain means replacing only those instances that currently refer to this tag
593 # otherwise, <module>-SVNPATH is replaced unconditionnally
594 def patch_tags_file (self, tagsfile, oldname, newname,fine_grain=True):
595 newtagsfile=tagsfile+".new"
597 new=open(newtagsfile,"w")
600 # fine-grain : replace those lines that refer to oldname
602 if self.options.verbose:
603 print 'Replacing %s into %s\n\tin %s .. '%(oldname,newname,tagsfile),
604 matcher=re.compile("^(.*)%s(.*)"%oldname)
605 for line in tags.readlines():
606 if not matcher.match(line):
609 (begin,end)=matcher.match(line).groups()
610 new.write(begin+newname+end+"\n")
612 # brute-force : change uncommented lines that define <module>-SVNPATH
614 if self.options.verbose:
615 print 'Setting %s-SVNPATH for using %s\n\tin %s .. '%(self.name,newname,tagsfile),
616 pattern="\A\s*%s-SVNPATH\s*(=|:=)\s*(?P<url_main>[^\s]+)/%s/[^\s]+"\
617 %(self.name,self.name)
618 matcher_module=re.compile(pattern)
619 for line in tags.readlines():
620 attempt=matcher_module.match(line)
622 svnpath="%s-SVNPATH"%self.name
623 replacement = "%-32s:= %s/%s/tags/%s\n"%(svnpath,attempt.group('url_main'),self.name,newname)
624 new.write(replacement)
630 os.rename(newtagsfile,tagsfile)
631 if self.options.verbose: print "%d changes"%matches
637 self.revert_edge_dir()
638 self.update_edge_dir()
640 spec_dict = self.spec_dict()
641 self.show_dict(spec_dict)
644 edge_url=self.edge_url()
645 old_tag_name = self.tag_name(spec_dict)
646 old_tag_url=self.tag_url(spec_dict)
647 if (self.options.new_version):
648 # new version set on command line
649 spec_dict[self.module_version_varname] = self.options.new_version
650 spec_dict[self.module_taglevel_varname] = 0
653 new_taglevel = str ( int (spec_dict[self.module_taglevel_varname]) + 1)
654 spec_dict[self.module_taglevel_varname] = new_taglevel
657 new_tag_name = self.tag_name(spec_dict)
658 new_tag_url=self.tag_url(spec_dict)
659 self.check_svnpath_exists (edge_url,"edge track")
660 self.check_svnpath_exists (old_tag_url,"previous tag")
661 self.check_svnpath_not_exists (new_tag_url,"new tag")
664 diff_output=Command("svn diff %s %s"%(old_tag_url,edge_url),
665 self.options).output_of()
666 if len(diff_output) == 0:
667 if not prompt ("No difference in trunk for module %s, want to tag anyway"%self.name,False):
670 # side effect in trunk's specfile
671 self.patch_spec_var(spec_dict)
673 # prepare changelog file
674 # we use the standard subversion magic string (see svn_magic_line)
675 # so we can provide useful information, such as version numbers and diff
677 changelog="/tmp/%s-%d.txt"%(self.name,os.getpid())
678 file(changelog,"w").write("""Tagging module %s - %s
681 Please write a changelog for this new tag in the section above
682 """%(self.name,new_tag_name,Module.svn_magic_line))
684 if not self.options.verbose or prompt('Want to see diffs while writing changelog',True):
685 file(changelog,"a").write('DIFF=========\n' + diff_output)
687 if self.options.debug:
691 self.run("%s %s"%(self.options.editor,changelog))
692 # insert changelog in spec
693 if self.options.changelog:
694 self.insert_changelog (changelog,old_tag_name,new_tag_name)
698 buildname=Module.config['build']
701 build = Module(buildname,self.options)
703 build.init_edge_dir()
704 build.revert_edge_dir()
705 build.update_edge_dir()
707 tagsfiles=glob(build.edge_dir()+"/*-tags*.mk")
708 tagsdict=dict( [ (x,'todo') for x in tagsfiles ] )
711 for (tagsfile,status) in tagsdict.iteritems():
712 basename=os.path.basename(tagsfile)
713 print ".................... Dealing with %s"%basename
714 while tagsdict[tagsfile] == 'todo' :
715 choice = prompt ("insert %s in %s "%(new_tag_name,basename),default_answer,
716 [ ('y','es'), ('n', 'ext'), ('f','orce'),
717 ('d','iff'), ('r','evert'), ('h','elp') ] ,
720 self.patch_tags_file(tagsfile,old_tag_name,new_tag_name,fine_grain=True)
722 print 'Done with %s'%os.path.basename(tagsfile)
723 tagsdict[tagsfile]='done'
725 self.patch_tags_file(tagsfile,old_tag_name,new_tag_name,fine_grain=False)
727 self.run("svn diff %s"%tagsfile)
729 self.run("svn revert %s"%tagsfile)
732 print """y: change %(name)s-SVNPATH only if it currently refers to %(old_tag_name)s
733 f: unconditionnally change any line setting %(name)s-SVNPATH to using %(new_tag_name)s
734 d: show current diff for this tag file
735 r: revert that tag file
736 n: move to next file"""%locals()
738 if prompt("Want to review changes on tags files",False):
739 tagsdict = dict ( [ (x, 'todo') for tagsfile in tagsfiles ] )
745 paths += self.edge_dir() + " "
746 paths += build.edge_dir() + " "
747 self.run_prompt("Review trunk and build","svn diff " + paths)
748 self.run_prompt("Commit trunk and build","svn commit --file %s %s"%(changelog,paths))
749 self.run_prompt("Create tag","svn copy --file %s %s %s"%(changelog,edge_url,new_tag_url))
751 if self.options.debug:
752 print 'Preserving',changelog
756 ##############################
757 def do_branch (self):
759 # save self.branch if any, as a hint for the new branch
760 # do this before anything else and restore .branch to None,
761 # as this is part of the class's logic
764 new_trunk_name=self.branch
767 # compute diff - a way to initialize the whole stuff
768 # do_diff already does edge_dir initialization
769 # and it checks that edge_url and tag_url exist as well
770 (spec_dict,edge_url,tag_url,diff_listing) = self.do_diff(compute_only=True)
772 # the version name in the trunk becomes the new branch name
773 branch_name = spec_dict[self.module_version_varname]
775 # figure new branch name (the one for the trunk) if not provided on the command line
776 if not new_trunk_name:
777 # heuristic is to assume 'version' is a dot-separated name
778 # we isolate the rightmost part and try incrementing it by 1
779 version=spec_dict[self.module_version_varname]
781 m=re.compile("\A(?P<leftpart>.+)\.(?P<rightmost>[^\.]+)\Z")
782 (leftpart,rightmost)=m.match(version).groups()
783 incremented = int(rightmost)+1
784 new_trunk_name="%s.%d"%(leftpart,incremented)
786 raise Exception, 'Cannot figure next branch name from %s - exiting'%version
788 # record starting point tagname
789 latest_tag_name = self.tag_name(spec_dict)
792 print "Using starting point %s (%s)"%(tag_url,latest_tag_name)
793 print "Creating branch %s & moving trunk to %s"%(branch_name,new_trunk_name)
796 # print warning if pending diffs
798 print """*** WARNING : Module %s has pending diffs on its trunk
799 It is safe to proceed, but please note that branch %s
800 will be based on latest tag %s and *not* on the current trunk"""%(self.name,branch_name,latest_tag_name)
802 answer = prompt ('Are you sure you want to proceed with branching',True,('d','iff'))
805 elif answer is False:
806 raise Exception,"User quit"
808 print '<<<< %s'%tag_url
809 print '>>>> %s'%edge_url
812 branch_url = "%s/%s/branches/%s"%(Module.config['svnpath'],self.name,branch_name)
813 self.check_svnpath_not_exists (branch_url,"new branch")
816 spec_dict[self.module_version_varname]=new_trunk_name
817 spec_dict[self.module_taglevel_varname]='0'
818 # remember this in the trunk for easy location of the current branch
819 spec_dict['module_current_branch']=branch_name
820 self.patch_spec_var(spec_dict,True)
822 # create commit log file
823 tmp="/tmp/branching-%d"%os.getpid()
825 f.write("Branch %s for module %s created from tag %s\n"%(new_trunk_name,self.name,latest_tag_name))
828 # we're done, let's commit the stuff
829 command="svn diff %s"%self.edge_dir()
830 self.run_prompt("Review changes in trunk",command)
831 command="svn copy --file %s %s %s"%(tmp,self.edge_url(),branch_url)
832 self.run_prompt("Create branch",command)
833 command="svn commit --file %s %s"%(tmp,self.edge_dir())
834 self.run_prompt("Commit trunk",command)
835 new_tag_url=self.tag_url(spec_dict)
836 command="svn copy --file %s %s %s"%(tmp,self.edge_url(),new_tag_url)
837 self.run_prompt("Create initial tag in trunk",command)
840 ##############################
843 usage="""Usage: %prog options module_desc [ .. module_desc ]
845 manage subversion tags and specfile
846 requires the specfile to define *version* and *taglevel*
848 redirection variables module_version_varname / module_taglevel_varname
850 by default, the trunk of modules is taken into account
851 in this case, just mention the module name as <module_desc>
853 if you wish to work on a branch rather than on the trunk,
854 you can use something like e.g. Mom:2.1 as <module_desc>
856 see http://svn.planet-lab.org/wiki/ModuleTools
860 'list' : "displays a list of available tags or branches",
861 'version' : "check latest specfile and print out details",
862 'diff' : "show difference between trunk and latest tag",
863 'tag' : """increment taglevel in specfile, insert changelog in specfile,
864 create new tag and and monitor its adoption in build/*-tags*.mk""",
865 'branch' : """create a branch for this module, from the latest tag on the trunk,
866 and change trunk's version number to reflect the new branch name;
867 you can specify the new branch name by using module:branch""",
868 'sync' : """create a tag from the trunk
869 this is a last resort option, mostly for repairs""",
872 silent_modes = ['list']
877 for function in Main.modes.keys():
878 if sys.argv[0].find(function) >= 0:
882 print "Unsupported command",sys.argv[0]
885 Main.usage += "\nmodule-%s : %s"%(mode,Main.modes[mode])
886 all_modules=os.path.dirname(sys.argv[0])+"/modules.list"
888 parser=OptionParser(usage=Main.usage,version=subversion_id)
891 parser.add_option("-b","--branches",action="store_true",dest="list_branches",default=False,
892 help="list branches")
893 parser.add_option("-t","--tags",action="store_false",dest="list_branches",
895 parser.add_option("-m","--match",action="store",dest="list_pattern",default=None,
896 help="grep pattern for filtering output")
897 parser.add_option("-x","--exact-match",action="store",dest="list_exact",default=None,
898 help="exact grep pattern for filtering output")
899 if mode == "tag" or mode == 'branch':
900 parser.add_option("-s","--set-version",action="store",dest="new_version",default=None,
901 help="set new version and reset taglevel to 0")
903 parser.add_option("-c","--no-changelog", action="store_false", dest="changelog", default=True,
904 help="do not update changelog section in specfile when tagging")
905 if mode == "tag" or mode == "sync" :
906 parser.add_option("-e","--editor", action="store", dest="editor", default=default_editor(),
907 help="specify editor")
909 parser.add_option("-m","--message", action="store", dest="message", default=None,
910 help="specify log message")
912 parser.add_option("-o","--only", action="store_true", dest="only", default=False,
913 help="report diff only for modules that exhibit differences")
915 parser.add_option("-l","--list", action="store_true", dest="list", default=False,
916 help="just list modules that exhibit differences")
918 if mode == 'version':
919 parser.add_option("-u","--url", action="store_true", dest="show_urls", default=False,
922 # default verbosity depending on function - temp
923 parser.add_option("-a","--all",action="store_true",dest="all_modules",default=False,
924 help="run on all modules as found in %s"%all_modules)
925 verbose_default=False
926 if mode in ['tag','sync'] : verbose_default = True
927 parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=verbose_default,
928 help="run in verbose mode")
929 if mode not in ['version','list']:
930 parser.add_option("-q","--quiet", action="store_false", dest="verbose",
931 help="run in quiet (non-verbose) mode")
932 parser.add_option("-w","--workdir", action="store", dest="workdir",
933 default="%s/%s"%(os.getenv("HOME"),"modules"),
934 help="""name for dedicated working dir - defaults to ~/modules
935 ** THIS MUST NOT ** be your usual working directory""")
936 parser.add_option("-f","--fast-checks",action="store_true",dest="fast_checks",default=False,
937 help="skip safety checks, such as svn updates -- use with care")
938 parser.add_option("-d","--debug", action="store_true", dest="debug", default=False,
939 help="debug mode - mostly more verbose")
940 (options, args) = parser.parse_args()
944 if options.all_modules:
945 args=Command("grep -v '#' %s"%all_modules,options).output_of().split()
949 Module.init_homedir(options)
951 module=Module(modname,options)
952 if len(args)>1 and mode not in Main.silent_modes:
953 print '========================================',module.friendly_name()
954 # call the method called do_<mode>
955 method=Module.__dict__["do_%s"%mode]
959 print 'Skipping failed %s - %r'%(modname,e)
961 if __name__ == "__main__" :
964 except KeyboardInterrupt: