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)
52 def __init__ (self,command,options):
55 self.tmp="/tmp/command-%d"%os.getpid()
58 if self.options.verbose and self.options.mode not in Main.silent_modes:
59 print '+',self.command
61 return os.system(self.command)
63 def run_silent (self):
64 if self.options.verbose:
65 print '+',self.command,' .. ',
67 retcod=os.system(self.command + " &> " + self.tmp)
69 print "FAILED ! -- output quoted below "
70 os.system("cat " + self.tmp)
71 print "FAILED ! -- end of quoted output"
72 elif self.options.verbose:
78 if self.run_silent() !=0:
79 raise Exception,"Command %s failed"%self.command
81 # returns stdout, like bash's $(mycommand)
82 def output_of (self,with_stderr=False):
83 tmp="/tmp/status-%d"%os.getpid()
84 if self.options.debug:
85 print '+',self.command,' .. ',
94 result=file(tmp).read()
96 if self.options.debug:
101 def __init__(self,path,options):
105 def url_exists (self):
106 return os.system("svn list %s &> /dev/null"%self.path) == 0
108 def dir_needs_revert (self):
109 command="svn status %s"%self.path
110 return len(Command(command,self.options).output_of(True)) != 0
111 # turns out it's the same implem.
112 def file_needs_commit (self):
113 command="svn status %s"%self.path
114 return len(Command(command,self.options).output_of(True)) != 0
118 svn_magic_line="--This line, and those below, will be ignored--"
120 redirectors=[ # ('module_name_varname','name'),
121 ('module_version_varname','version'),
122 ('module_taglevel_varname','taglevel'), ]
124 # where to store user's config
125 config_storage="CONFIG"
130 configKeys=[ ('svnpath',"Enter your toplevel svnpath",
131 "svn+ssh://%s@svn.planet-lab.org/svn/"%commands.getoutput("id -un")),
132 ("build", "Enter the name of your build module","build"),
133 ('username',"Enter your firstname and lastname for changelogs",""),
134 ("email","Enter your email address for changelogs",""),
138 def prompt_config ():
139 for (key,message,default) in Module.configKeys:
140 Module.config[key]=""
141 while not Module.config[key]:
142 Module.config[key]=raw_input("%s [%s] : "%(message,default)).strip() or default
145 # for parsing module spec name:branch
146 matcher_branch_spec=re.compile("\A(?P<name>[\w-]+):(?P<branch>[\w\.]+)\Z")
147 matcher_rpm_define=re.compile("%(define|global)\s+(\S+)\s+(\S*)\s*")
149 def __init__ (self,module_spec,options):
151 attempt=Module.matcher_branch_spec.match(module_spec)
153 self.name=attempt.group('name')
154 self.branch=attempt.group('branch')
156 self.name=module_spec
160 self.moddir="%s/%s"%(options.workdir,self.name)
162 def friendly_name (self):
166 return "%s:%s"%(self.name,self.branch)
170 return "%s/trunk"%(self.moddir)
172 return "%s/branches/%s"%(self.moddir,self.branch)
175 return "%s/tags"%(self.moddir)
177 def run (self,command):
178 return Command(command,self.options).run()
179 def run_fatal (self,command):
180 return Command(command,self.options).run_fatal()
181 def run_prompt (self,message,command):
182 if not self.options.verbose:
184 choice=prompt(message,True,('s','how'))
188 elif choice is False:
191 print 'About to run:',command
193 question=message+" - want to run " + command
194 if prompt(question,True):
198 def init_homedir (options):
199 topdir=options.workdir
200 if options.verbose and options.mode not in Main.silent_modes:
201 print 'Checking for',topdir
202 storage="%s/%s"%(topdir,Module.config_storage)
203 # sanity check. Either the topdir exists AND we have a config/storage
204 # or topdir does not exist and we create it
205 # to avoid people use their own daily svn repo
206 if os.path.isdir(topdir) and not os.path.isfile(storage):
207 print """The directory %s exists and has no CONFIG file
208 If this is your regular working directory, please provide another one as the
209 module-* commands need a fresh working dir. Make sure that you do not use
210 that for other purposes than tagging"""%topdir
212 if not os.path.isdir (topdir):
213 print "Cannot find",topdir,"let's create it"
214 Module.prompt_config()
215 print "Checking ...",
216 Command("svn co -N %s %s"%(Module.config['svnpath'],topdir),options).run_fatal()
217 Command("svn co -N %s/%s %s/%s"%(Module.config['svnpath'],
218 Module.config['build'],
220 Module.config['build']),options).run_fatal()
225 for (key,message,default) in Module.configKeys:
226 f.write("%s=%s\n"%(key,Module.config[key]))
229 print 'Stored',storage
230 Command("cat %s"%storage,options).run()
234 for line in f.readlines():
235 (key,value)=re.compile("^(.+)=(.+)$").match(line).groups()
236 Module.config[key]=value
238 if options.verbose and options.mode not in Main.silent_modes:
239 print '******** Using config'
240 for (key,message,default) in Module.configKeys:
241 print '\t',key,'=',Module.config[key]
243 def init_moddir (self):
244 if self.options.verbose:
245 print 'Checking for',self.moddir
246 if not os.path.isdir (self.moddir):
247 self.run_fatal("svn up -N %s"%self.moddir)
248 if not os.path.isdir (self.moddir):
249 raise Exception, 'Cannot find %s - check module name'%self.moddir
251 def init_subdir (self,fullpath):
252 if self.options.verbose:
253 print 'Checking for',fullpath
254 if not os.path.isdir (fullpath):
255 self.run_fatal("svn up -N %s"%fullpath)
257 def revert_subdir (self,fullpath):
258 if self.options.fast_checks:
259 if self.options.verbose: print 'Skipping revert of %s'%fullpath
261 if self.options.verbose:
262 print 'Checking whether',fullpath,'needs being reverted'
263 if Svnpath(fullpath,self.options).dir_needs_revert():
264 self.run_fatal("svn revert -R %s"%fullpath)
266 def update_subdir (self,fullpath):
267 if self.options.fast_checks:
268 if self.options.verbose: print 'Skipping update of %s'%fullpath
270 if self.options.verbose:
271 print 'Updating',fullpath
272 self.run_fatal("svn update -N %s"%fullpath)
274 def init_edge_dir (self):
275 # if branch, edge_dir is two steps down
277 self.init_subdir("%s/branches"%self.moddir)
278 self.init_subdir(self.edge_dir())
280 def revert_edge_dir (self):
281 self.revert_subdir(self.edge_dir())
283 def update_edge_dir (self):
284 self.update_subdir(self.edge_dir())
286 def main_specname (self):
287 attempt="%s/%s.spec"%(self.edge_dir(),self.name)
288 if os.path.isfile (attempt):
292 return glob("%s/*.spec"%self.edge_dir())[0]
294 raise Exception, 'Cannot guess specfile for module %s'%self.name
296 def all_specnames (self):
297 return glob("%s/*.spec"%self.edge_dir())
299 def parse_spec (self, specfile, varnames):
300 if self.options.verbose:
301 print 'Parsing',specfile,
307 for line in f.readlines():
308 attempt=Module.matcher_rpm_define.match(line)
310 (define,var,value)=attempt.groups()
314 if self.options.debug:
315 print 'found',len(result),'keys'
316 for (k,v) in result.iteritems():
320 # stores in self.module_name_varname the rpm variable to be used for the module's name
321 # and the list of these names in self.varnames
322 def spec_dict (self):
323 specfile=self.main_specname()
324 redirector_keys = [ varname for (varname,default) in Module.redirectors]
325 redirect_dict = self.parse_spec(specfile,redirector_keys)
326 if self.options.debug:
327 print '1st pass parsing done, redirect_dict=',redirect_dict
329 for (varname,default) in Module.redirectors:
330 if redirect_dict.has_key(varname):
331 setattr(self,varname,redirect_dict[varname])
332 varnames += [redirect_dict[varname]]
334 setattr(self,varname,default)
335 varnames += [ default ]
336 self.varnames = varnames
337 result = self.parse_spec (specfile,self.varnames)
338 if self.options.debug:
339 print '2st pass parsing done, varnames=',varnames,'result=',result
342 def patch_spec_var (self, patch_dict,define_missing=False):
343 for specfile in self.all_specnames():
344 # record the keys that were changed
345 changed = dict ( [ (x,False) for x in patch_dict.keys() ] )
346 newspecfile=specfile+".new"
347 if self.options.verbose:
348 print 'Patching',specfile,'for',patch_dict.keys()
350 new=open(newspecfile,"w")
352 for line in spec.readlines():
353 attempt=Module.matcher_rpm_define.match(line)
355 (define,var,value)=attempt.groups()
356 if var in patch_dict.keys():
357 if self.options.debug:
358 print 'rewriting %s as %s'%(var,patch_dict[var])
359 new.write('%%%s %s %s\n'%(define,var,patch_dict[var]))
364 for (key,was_changed) in changed.iteritems():
366 if self.options.debug:
367 print 'rewriting missed %s as %s'%(key,patch_dict[key])
368 new.write('%%define %s %s\n'%(key,patch_dict[key]))
371 os.rename(newspecfile,specfile)
373 def unignored_lines (self, logfile):
375 exclude="Tagging module %s"%self.name
376 for logline in file(logfile).readlines():
377 if logline.strip() == Module.svn_magic_line:
379 if logline.find(exclude) < 0:
380 result += [ logline ]
383 def insert_changelog (self, logfile, oldtag, newtag):
384 for specfile in self.all_specnames():
385 newspecfile=specfile+".new"
386 if self.options.verbose:
387 print 'Inserting changelog from %s into %s'%(logfile,specfile)
389 new=open(newspecfile,"w")
390 for line in spec.readlines():
392 if re.compile('%changelog').match(line):
393 dateformat="* %a %b %d %Y"
394 datepart=time.strftime(dateformat)
395 logpart="%s <%s> - %s %s"%(Module.config['username'],
396 Module.config['email'],
398 new.write(datepart+" "+logpart+"\n")
399 for logline in self.unignored_lines(logfile):
400 new.write("- " + logline)
404 os.rename(newspecfile,specfile)
406 def show_dict (self, spec_dict):
407 if self.options.verbose:
408 for (k,v) in spec_dict.iteritems():
412 return "%s/%s"%(Module.config['svnpath'],self.name)
416 return "%s/trunk"%(self.mod_url())
418 return "%s/branches/%s"%(self.mod_url(),self.branch)
420 def tag_name (self, spec_dict):
422 return "%s-%s-%s"%(#spec_dict[self.module_name_varname],
424 spec_dict[self.module_version_varname],
425 spec_dict[self.module_taglevel_varname])
427 raise Exception, 'Something is wrong with module %s, cannot determine %s - exiting'%(self.name,err)
429 def tag_url (self, spec_dict):
430 return "%s/tags/%s"%(self.mod_url(),self.tag_name(spec_dict))
432 def check_svnpath_exists (self, url, message):
433 if self.options.fast_checks:
435 if self.options.verbose:
436 print 'Checking url (%s) %s'%(url,message),
437 ok=Svnpath(url,self.options).url_exists()
439 if self.options.verbose: print 'exists - OK'
441 if self.options.verbose: print 'KO'
442 raise Exception, 'Could not find %s URL %s'%(message,url)
444 def check_svnpath_not_exists (self, url, message):
445 if self.options.fast_checks:
447 if self.options.verbose:
448 print 'Checking url (%s) %s'%(url,message),
449 ok=not Svnpath(url,self.options).url_exists()
451 if self.options.verbose: print 'does not exist - OK'
453 if self.options.verbose: print 'KO'
454 raise Exception, '%s URL %s already exists - exiting'%(message,url)
456 # locate specfile, parse it, check it and show values
458 ##############################
459 def do_version (self):
462 self.revert_edge_dir()
463 self.update_edge_dir()
464 spec_dict = self.spec_dict()
465 for varname in self.varnames:
466 if not spec_dict.has_key(varname):
467 print 'Could not find %%define for %s'%varname
470 print "%-16s %s"%(varname,spec_dict[varname])
471 if self.options.show_urls:
472 print "%-16s %s"%('edge url',self.edge_url())
473 print "%-16s %s"%('latest tag url',self.tag_url(spec_dict))
474 if self.options.verbose:
475 print "%-16s %s"%('main specfile:',self.main_specname())
476 print "%-16s %s"%('specfiles:',self.all_specnames())
478 ##############################
480 # print 'verbose',self.options.verbose
481 # print 'list_tags',self.options.list_tags
482 # print 'list_branches',self.options.list_branches
483 # print 'all_modules',self.options.all_modules
485 (verbose,branches,pattern,exact) = (self.options.verbose,self.options.list_branches,
486 self.options.list_pattern,self.options.list_exact)
494 if verbose: grep="%s/$"%exact
495 else: grep="^%s$"%exact
498 extra_command=" | grep %s"%grep
499 extra_message=" matching %s"%grep
502 message="==================== tags for %s"%self.friendly_name()
504 if verbose: command+="--verbose "
505 command += "%s/tags"%self.mod_url()
506 command += extra_command
507 message += extra_message
508 if verbose: print message
512 message="==================== branches for %s"%self.friendly_name()
514 if verbose: command+="--verbose "
515 command += "%s/branches"%self.mod_url()
516 command += extra_command
517 message += extra_message
518 if verbose: print message
521 ##############################
522 sync_warning="""*** WARNING
523 The module-init function has the following limitations
524 * it does not handle changelogs
525 * it does not scan the -tags*.mk files to adopt the new tags"""
528 if self.options.verbose:
529 print Module.sync_warning
530 if not prompt('Want to proceed anyway'):
535 self.revert_edge_dir()
536 self.update_edge_dir()
537 spec_dict = self.spec_dict()
539 edge_url=self.edge_url()
540 tag_name=self.tag_name(spec_dict)
541 tag_url=self.tag_url(spec_dict)
542 # check the tag does not exist yet
543 self.check_svnpath_not_exists(tag_url,"new tag")
545 if self.options.message:
546 svnopt='--message "%s"'%self.options.message
548 svnopt='--editor-cmd=%s'%self.options.editor
549 self.run_prompt("Create initial tag",
550 "svn copy %s %s %s"%(svnopt,edge_url,tag_url))
552 ##############################
553 def do_diff (self,compute_only=False):
556 self.revert_edge_dir()
557 self.update_edge_dir()
558 spec_dict = self.spec_dict()
559 self.show_dict(spec_dict)
561 edge_url=self.edge_url()
562 tag_url=self.tag_url(spec_dict)
563 self.check_svnpath_exists(edge_url,"edge track")
564 self.check_svnpath_exists(tag_url,"latest tag")
565 command="svn diff %s %s"%(tag_url,edge_url)
567 if self.options.verbose:
568 print 'Getting diff with %s'%command
569 diff_output = Command(command,self.options).output_of()
570 # if used as a utility
572 return (spec_dict,edge_url,tag_url,diff_output)
573 # otherwise print the result
574 if self.options.list:
578 if not self.options.only or diff_output:
579 print 'x'*30,'module',self.friendly_name()
580 print 'x'*20,'<',tag_url
581 print 'x'*20,'>',edge_url
584 ##############################
585 # using fine_grain means replacing only those instances that currently refer to this tag
586 # otherwise, <module>-SVNPATH is replaced unconditionnally
587 def patch_tags_file (self, tagsfile, oldname, newname,fine_grain=True):
588 newtagsfile=tagsfile+".new"
590 new=open(newtagsfile,"w")
593 # fine-grain : replace those lines that refer to oldname
595 if self.options.verbose:
596 print 'Replacing %s into %s\n\tin %s .. '%(oldname,newname,tagsfile),
597 matcher=re.compile("^(.*)%s(.*)"%oldname)
598 for line in tags.readlines():
599 if not matcher.match(line):
602 (begin,end)=matcher.match(line).groups()
603 new.write(begin+newname+end+"\n")
605 # brute-force : change uncommented lines that define <module>-SVNPATH
607 if self.options.verbose:
608 print 'Setting %s-SVNPATH for using %s\n\tin %s .. '%(self.name,newname,tagsfile),
609 pattern="\A\s*%s-SVNPATH\s*(=|:=)\s*(?P<url_main>[^\s]+)/%s/[^\s]+"\
610 %(self.name,self.name)
611 matcher_module=re.compile(pattern)
612 for line in tags.readlines():
613 attempt=matcher_module.match(line)
615 svnpath="%s-SVNPATH"%self.name
616 replacement = "%-32s:= %s/%s/tags/%s\n"%(svnpath,attempt.group('url_main'),self.name,newname)
617 new.write(replacement)
623 os.rename(newtagsfile,tagsfile)
624 if self.options.verbose: print "%d changes"%matches
630 self.revert_edge_dir()
631 self.update_edge_dir()
633 spec_dict = self.spec_dict()
634 self.show_dict(spec_dict)
637 edge_url=self.edge_url()
638 old_tag_name = self.tag_name(spec_dict)
639 old_tag_url=self.tag_url(spec_dict)
640 if (self.options.new_version):
641 # new version set on command line
642 spec_dict[self.module_version_varname] = self.options.new_version
643 spec_dict[self.module_taglevel_varname] = 0
646 new_taglevel = str ( int (spec_dict[self.module_taglevel_varname]) + 1)
647 spec_dict[self.module_taglevel_varname] = new_taglevel
650 new_tag_name = self.tag_name(spec_dict)
651 new_tag_url=self.tag_url(spec_dict)
652 self.check_svnpath_exists (edge_url,"edge track")
653 self.check_svnpath_exists (old_tag_url,"previous tag")
654 self.check_svnpath_not_exists (new_tag_url,"new tag")
657 diff_output=Command("svn diff %s %s"%(old_tag_url,edge_url),
658 self.options).output_of()
659 if len(diff_output) == 0:
660 if not prompt ("No difference in trunk for module %s, want to tag anyway"%self.name,False):
663 # side effect in trunk's specfile
664 self.patch_spec_var(spec_dict)
666 # prepare changelog file
667 # we use the standard subversion magic string (see svn_magic_line)
668 # so we can provide useful information, such as version numbers and diff
670 changelog="/tmp/%s-%d.txt"%(self.name,os.getpid())
671 file(changelog,"w").write("""Tagging module %s - %s
674 Please write a changelog for this new tag in the section above
675 """%(self.name,new_tag_name,Module.svn_magic_line))
677 if not self.options.verbose or prompt('Want to see diffs while writing changelog',True):
678 file(changelog,"a").write('DIFF=========\n' + diff_output)
680 if self.options.debug:
684 self.run("%s %s"%(self.options.editor,changelog))
685 # insert changelog in spec
686 if self.options.changelog:
687 self.insert_changelog (changelog,old_tag_name,new_tag_name)
691 buildname=Module.config['build']
694 build = Module(buildname,self.options)
696 build.init_edge_dir()
697 build.revert_edge_dir()
698 build.update_edge_dir()
700 tagsfiles=glob(build.edge_dir()+"/*-tags*.mk")
701 tagsdict=dict( [ (x,'todo') for x in tagsfiles ] )
704 for (tagsfile,status) in tagsdict.iteritems():
705 basename=os.path.basename(tagsfile)
706 print ".................... Dealing with %s"%basename
707 while tagsdict[tagsfile] == 'todo' :
708 choice = prompt ("insert %s in %s "%(new_tag_name,basename),default_answer,
709 [ ('y','es'), ('n', 'ext'), ('f','orce'),
710 ('d','iff'), ('r','evert'), ('h','elp') ] ,
713 self.patch_tags_file(tagsfile,old_tag_name,new_tag_name,fine_grain=True)
715 print 'Done with %s'%os.path.basename(tagsfile)
716 tagsdict[tagsfile]='done'
718 self.patch_tags_file(tagsfile,old_tag_name,new_tag_name,fine_grain=False)
720 self.run("svn diff %s"%tagsfile)
722 self.run("svn revert %s"%tagsfile)
725 print """y: change %(name)s-SVNPATH only if it currently refers to %(old_tag_name)s
726 f: unconditionnally change any line setting %(name)s-SVNPATH to using %(new_tag_name)s
727 d: show current diff for this tag file
728 r: revert that tag file
729 n: move to next file"""%locals()
731 if prompt("Want to review changes on tags files",False):
732 tagsdict = dict ( [ (x, 'todo') for tagsfile in tagsfiles ] )
738 paths += self.edge_dir() + " "
739 paths += build.edge_dir() + " "
740 self.run_prompt("Review trunk and build","svn diff " + paths)
741 self.run_prompt("Commit trunk and build","svn commit --file %s %s"%(changelog,paths))
742 self.run_prompt("Create tag","svn copy --file %s %s %s"%(changelog,edge_url,new_tag_url))
744 if self.options.debug:
745 print 'Preserving',changelog
749 ##############################
750 def do_branch (self):
752 # save self.branch if any, as a hint for the new branch
753 # do this before anything else and restore .branch to None,
754 # as this is part of the class's logic
757 new_trunk_name=self.branch
760 # compute diff - a way to initialize the whole stuff
761 # do_diff already does edge_dir initialization
762 # and it checks that edge_url and tag_url exist as well
763 (spec_dict,edge_url,tag_url,diff_listing) = self.do_diff(compute_only=True)
765 # the version name in the trunk becomes the new branch name
766 branch_name = spec_dict[self.module_version_varname]
768 # figure new branch name (the one for the trunk) if not provided on the command line
769 if not new_trunk_name:
770 # heuristic is to assume 'version' is a dot-separated name
771 # we isolate the rightmost part and try incrementing it by 1
772 version=spec_dict[self.module_version_varname]
774 m=re.compile("\A(?P<leftpart>.+)\.(?P<rightmost>[^\.]+)\Z")
775 (leftpart,rightmost)=m.match(version).groups()
776 incremented = int(rightmost)+1
777 new_trunk_name="%s.%d"%(leftpart,incremented)
779 raise Exception, 'Cannot figure next branch name from %s - exiting'%version
781 # record starting point tagname
782 latest_tag_name = self.tag_name(spec_dict)
785 print "Using starting point %s (%s)"%(tag_url,latest_tag_name)
786 print "Creating branch %s & moving trunk to %s"%(branch_name,new_trunk_name)
789 # print warning if pending diffs
791 print """*** WARNING : Module %s has pending diffs on its trunk
792 It is safe to proceed, but please note that branch %s
793 will be based on latest tag %s and *not* on the current trunk"""%(self.name,branch_name,latest_tag_name)
795 answer = prompt ('Are you sure you want to proceed with branching',True,('d','iff'))
798 elif answer is False:
799 raise Exception,"User quit"
801 print '<<<< %s'%tag_url
802 print '>>>> %s'%edge_url
805 branch_url = "%s/%s/branches/%s"%(Module.config['svnpath'],self.name,branch_name)
806 self.check_svnpath_not_exists (branch_url,"new branch")
809 spec_dict[self.module_version_varname]=new_trunk_name
810 spec_dict[self.module_taglevel_varname]='0'
811 # remember this in the trunk for easy location of the current branch
812 spec_dict['module_current_branch']=branch_name
813 self.patch_spec_var(spec_dict,True)
815 # create commit log file
816 tmp="/tmp/branching-%d"%os.getpid()
818 f.write("Branch %s for module %s created from tag %s\n"%(new_trunk_name,self.name,latest_tag_name))
821 # we're done, let's commit the stuff
822 command="svn diff %s"%self.edge_dir()
823 self.run_prompt("Review changes in trunk",command)
824 command="svn copy --file %s %s %s"%(tmp,self.edge_url(),branch_url)
825 self.run_prompt("Create branch",command)
826 command="svn commit --file %s %s"%(tmp,self.edge_dir())
827 self.run_prompt("Commit trunk",command)
828 new_tag_url=self.tag_url(spec_dict)
829 command="svn copy --file %s %s %s"%(tmp,self.edge_url(),new_tag_url)
830 self.run_prompt("Create initial tag in trunk",command)
833 ##############################
836 usage="""Usage: %prog options module_desc [ .. module_desc ]
838 manage subversion tags and specfile
839 requires the specfile to define *version* and *taglevel*
841 redirection variables module_version_varname / module_taglevel_varname
843 by default, the trunk of modules is taken into account
844 in this case, just mention the module name as <module_desc>
846 if you wish to work on a branch rather than on the trunk,
847 you can use something like e.g. Mom:2.1 as <module_desc>
849 see http://svn.planet-lab.org/wiki/ModuleTools
853 'list' : "displays a list of available tags or branches",
854 'version' : "check latest specfile and print out details",
855 'diff' : "show difference between trunk and latest tag",
856 'tag' : """increment taglevel in specfile, insert changelog in specfile,
857 create new tag and and monitor its adoption in build/*-tags*.mk""",
858 'branch' : """create a branch for this module, from the latest tag on the trunk,
859 and change trunk's version number to reflect the new branch name;
860 you can specify the new branch name by using module:branch""",
861 'sync' : """create a tag from the trunk
862 this is a last resort option, mostly for repairs""",
865 silent_modes = ['list']
870 for function in Main.modes.keys():
871 if sys.argv[0].find(function) >= 0:
875 print "Unsupported command",sys.argv[0]
878 Main.usage += "\nmodule-%s : %s"%(mode,Main.modes[mode])
879 all_modules=os.path.dirname(sys.argv[0])+"/modules.list"
881 parser=OptionParser(usage=Main.usage,version=subversion_id)
884 parser.add_option("-b","--branches",action="store_true",dest="list_branches",default=False,
885 help="list branches")
886 parser.add_option("-t","--tags",action="store_false",dest="list_branches",
888 parser.add_option("-m","--match",action="store",dest="list_pattern",default=None,
889 help="grep pattern for filtering output")
890 parser.add_option("-x","--exact-match",action="store",dest="list_exact",default=None,
891 help="exact grep pattern for filtering output")
892 if mode == "tag" or mode == 'branch':
893 parser.add_option("-s","--set-version",action="store",dest="new_version",default=None,
894 help="set new version and reset taglevel to 0")
896 parser.add_option("-c","--no-changelog", action="store_false", dest="changelog", default=True,
897 help="do not update changelog section in specfile when tagging")
898 if mode == "tag" or mode == "sync" :
899 parser.add_option("-e","--editor", action="store", dest="editor", default="emacs",
900 help="specify editor")
902 parser.add_option("-m","--message", action="store", dest="message", default=None,
903 help="specify log message")
905 parser.add_option("-o","--only", action="store_true", dest="only", default=False,
906 help="report diff only for modules that exhibit differences")
908 parser.add_option("-l","--list", action="store_true", dest="list", default=False,
909 help="just list modules that exhibit differences")
911 if mode == 'version':
912 parser.add_option("-u","--url", action="store_true", dest="show_urls", default=False,
915 # default verbosity depending on function - temp
916 parser.add_option("-a","--all",action="store_true",dest="all_modules",default=False,
917 help="run on all modules as found in %s"%all_modules)
918 verbose_default=False
919 if mode in ['tag','sync'] : verbose_default = True
920 parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=verbose_default,
921 help="run in verbose mode")
922 if mode not in ['version','list']:
923 parser.add_option("-q","--quiet", action="store_false", dest="verbose",
924 help="run in quiet (non-verbose) mode")
925 parser.add_option("-w","--workdir", action="store", dest="workdir",
926 default="%s/%s"%(os.getenv("HOME"),"modules"),
927 help="""name for dedicated working dir - defaults to ~/modules
928 ** THIS MUST NOT ** be your usual working directory""")
929 parser.add_option("-f","--fast-checks",action="store_true",dest="fast_checks",default=False,
930 help="skip safety checks, such as svn updates -- use with care")
931 parser.add_option("-d","--debug", action="store_true", dest="debug", default=False,
932 help="debug mode - mostly more verbose")
933 (options, args) = parser.parse_args()
937 if options.all_modules:
938 args=Command("grep -v '#' %s"%all_modules,options).output_of().split()
942 Module.init_homedir(options)
944 module=Module(modname,options)
945 if len(args)>1 and mode not in Main.silent_modes:
946 print '========================================',module.friendly_name()
947 # call the method called do_<mode>
948 method=Module.__dict__["do_%s"%mode]
952 print 'Skipping failed %s - %r'%(modname,e)
954 if __name__ == "__main__" :
957 except KeyboardInterrupt: