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=[]):
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: the_prompt.append('[y]')
20 else : the_prompt.append('y')
22 if default is False: the_prompt.append('[n]')
23 else : the_prompt.append('n')
25 for (char,choice) in other_choices:
27 the_prompt.append("["+char+"]"+choice)
29 the_prompt.append("<"+char+">"+choice)
31 answer=raw_input(question + " " + "/".join(the_prompt) + " ? ")
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:
45 return prompt(question,default,other_choices)
50 def __init__ (self,command,options):
53 self.tmp="/tmp/command-%d"%os.getpid()
56 if self.options.verbose:
57 print '+',self.command
59 return os.system(self.command)
61 def run_silent (self):
62 if self.options.verbose:
63 print '+',self.command,' .. ',
65 retcod=os.system(self.command + " &> " + self.tmp)
67 print "FAILED ! -- output quoted below "
68 os.system("cat " + self.tmp)
69 print "FAILED ! -- end of quoted output"
70 elif self.options.verbose:
76 if self.run_silent() !=0:
77 raise Exception,"Command %s failed"%self.command
79 # returns stdout, like bash's $(mycommand)
80 def output_of (self,with_stderr=False):
81 tmp="/tmp/status-%d"%os.getpid()
82 if self.options.debug:
83 print '+',self.command,' .. ',
92 result=file(tmp).read()
94 if self.options.debug:
99 def __init__(self,path,options):
103 def url_exists (self):
104 return os.system("svn list %s &> /dev/null"%self.path) == 0
106 def dir_needs_revert (self):
107 command="svn status %s"%self.path
108 return len(Command(command,self.options).output_of(True)) != 0
109 # turns out it's the same implem.
110 def file_needs_commit (self):
111 command="svn status %s"%self.path
112 return len(Command(command,self.options).output_of(True)) != 0
116 svn_magic_line="--This line, and those below, will be ignored--"
118 redirectors=[ # ('module_name_varname','name'),
119 ('module_version_varname','version'),
120 ('module_taglevel_varname','taglevel'), ]
122 # where to store user's config
123 config_storage="CONFIG"
128 configKeys=[ ('svnpath',"Enter your toplevel svnpath",
129 "svn+ssh://%s@svn.planet-lab.org/svn/"%commands.getoutput("id -un")),
130 ("build", "Enter the name of your build module","build"),
131 ('username',"Enter your firstname and lastname for changelogs",""),
132 ("email","Enter your email address for changelogs",""),
136 def prompt_config ():
137 for (key,message,default) in Module.configKeys:
138 Module.config[key]=""
139 while not Module.config[key]:
140 Module.config[key]=raw_input("%s [%s] : "%(message,default)).strip() or default
143 # for parsing module spec name:branch
144 matcher_branch_spec=re.compile("\A(?P<name>[\w-]+):(?P<branch>[\w\.]+)\Z")
145 matcher_rpm_define=re.compile("%(define|global)\s+(\S+)\s+(\S*)\s*")
147 def __init__ (self,module_spec,options):
149 attempt=Module.matcher_branch_spec.match(module_spec)
151 self.name=attempt.group('name')
152 self.branch=attempt.group('branch')
154 self.name=module_spec
158 self.moddir="%s/%s"%(options.workdir,self.name)
160 def friendly_name (self):
164 return "%s:%s"%(self.name,self.branch)
168 return "%s/trunk"%(self.moddir)
170 return "%s/branches/%s"%(self.moddir,self.branch)
173 return "%s/tags"%(self.moddir)
175 def run (self,command):
176 return Command(command,self.options).run()
177 def run_fatal (self,command):
178 return Command(command,self.options).run_fatal()
179 def run_prompt (self,message,command):
180 if not self.options.verbose:
183 question=message+" - want to run " + command
184 if prompt(question,True):
188 def init_homedir (options):
189 topdir=options.workdir
191 print 'Checking for',topdir
192 storage="%s/%s"%(topdir,Module.config_storage)
193 # sanity check. Either the topdir exists AND we have a config/storage
194 # or topdir does not exist and we create it
195 # to avoid people use their own daily svn repo
196 if os.path.isdir(topdir) and not os.path.isfile(storage):
197 print """The directory %s exists and has no CONFIG file
198 If this is your regular working directory, please provide another one as the
199 module-* commands need a fresh working dir. Make sure that you do not use
200 that for other purposes than tagging"""%topdir
202 if not os.path.isdir (topdir):
203 print "Cannot find",topdir,"let's create it"
204 Module.prompt_config()
205 print "Checking ...",
206 Command("svn co -N %s %s"%(Module.config['svnpath'],topdir),options).run_fatal()
207 Command("svn co -N %s/%s %s/%s"%(Module.config['svnpath'],
208 Module.config['build'],
210 Module.config['build']),options).run_fatal()
215 for (key,message,default) in Module.configKeys:
216 f.write("%s=%s\n"%(key,Module.config[key]))
219 print 'Stored',storage
220 Command("cat %s"%storage,options).run()
224 for line in f.readlines():
225 (key,value)=re.compile("^(.+)=(.+)$").match(line).groups()
226 Module.config[key]=value
229 print '******** Using config'
230 for (key,message,default) in Module.configKeys:
231 print '\t',key,'=',Module.config[key]
233 def init_moddir (self):
234 if self.options.verbose:
235 print 'Checking for',self.moddir
236 if not os.path.isdir (self.moddir):
237 self.run_fatal("svn up -N %s"%self.moddir)
238 if not os.path.isdir (self.moddir):
239 print 'Cannot find %s - check module name'%self.moddir
242 def init_subdir (self,fullpath):
243 if self.options.verbose:
244 print 'Checking for',fullpath
245 if not os.path.isdir (fullpath):
246 self.run_fatal("svn up -N %s"%fullpath)
248 def revert_subdir (self,fullpath):
249 if self.options.fast_checks:
250 if self.options.verbose: print 'Skipping revert of %s'%fullpath
252 if self.options.verbose:
253 print 'Checking whether',fullpath,'needs being reverted'
254 if Svnpath(fullpath,self.options).dir_needs_revert():
255 self.run_fatal("svn revert -R %s"%fullpath)
257 def update_subdir (self,fullpath):
258 if self.options.fast_checks:
259 if self.options.verbose: print 'Skipping update of %s'%fullpath
261 if self.options.verbose:
262 print 'Updating',fullpath
263 self.run_fatal("svn update -N %s"%fullpath)
265 def init_edge_dir (self):
266 # if branch, edge_dir is two steps down
268 self.init_subdir("%s/branches"%self.moddir)
269 self.init_subdir(self.edge_dir())
271 def revert_edge_dir (self):
272 self.revert_subdir(self.edge_dir())
274 def update_edge_dir (self):
275 self.update_subdir(self.edge_dir())
277 def main_specname (self):
278 attempt="%s/%s.spec"%(self.edge_dir(),self.name)
279 if os.path.isfile (attempt):
283 return glob("%s/*.spec"%self.edge_dir())[0]
285 print 'Cannot guess specfile for module %s'%self.name
288 def all_specnames (self):
289 return glob("%s/*.spec"%self.edge_dir())
291 def parse_spec (self, specfile, varnames):
292 if self.options.verbose:
293 print 'Parsing',specfile,
299 for line in f.readlines():
300 attempt=Module.matcher_rpm_define.match(line)
302 (define,var,value)=attempt.groups()
306 if self.options.debug:
307 print 'found',len(result),'keys'
308 for (k,v) in result.iteritems():
312 # stores in self.module_name_varname the rpm variable to be used for the module's name
313 # and the list of these names in self.varnames
314 def spec_dict (self):
315 specfile=self.main_specname()
316 redirector_keys = [ varname for (varname,default) in Module.redirectors]
317 redirect_dict = self.parse_spec(specfile,redirector_keys)
318 if self.options.debug:
319 print '1st pass parsing done, redirect_dict=',redirect_dict
321 for (varname,default) in Module.redirectors:
322 if redirect_dict.has_key(varname):
323 setattr(self,varname,redirect_dict[varname])
324 varnames += [redirect_dict[varname]]
326 setattr(self,varname,default)
327 varnames += [ default ]
328 self.varnames = varnames
329 result = self.parse_spec (specfile,self.varnames)
330 if self.options.debug:
331 print '2st pass parsing done, varnames=',varnames,'result=',result
334 def patch_spec_var (self, patch_dict,define_missing=False):
335 for specfile in self.all_specnames():
336 # record the keys that were changed
337 changed = dict ( [ (x,False) for x in patch_dict.keys() ] )
338 newspecfile=specfile+".new"
339 if self.options.verbose:
340 print 'Patching',specfile,'for',patch_dict.keys()
342 new=open(newspecfile,"w")
344 for line in spec.readlines():
345 attempt=Module.matcher_rpm_define.match(line)
347 (define,var,value)=attempt.groups()
348 if var in patch_dict.keys():
349 if self.options.debug:
350 print 'rewriting %s as %s'%(var,patch_dict[var])
351 new.write('%%%s %s %s\n'%(define,var,patch_dict[var]))
356 for (key,was_changed) in changed.iteritems():
358 if self.options.debug:
359 print 'rewriting missed %s as %s'%(key,patch_dict[key])
360 new.write('%%define %s %s\n'%(key,patch_dict[key]))
363 os.rename(newspecfile,specfile)
365 def unignored_lines (self, logfile):
367 exclude="Tagging module %s"%self.name
368 for logline in file(logfile).readlines():
369 if logline.strip() == Module.svn_magic_line:
371 if logline.find(exclude) < 0:
372 result += [ logline ]
375 def insert_changelog (self, logfile, oldtag, newtag):
376 for specfile in self.all_specnames():
377 newspecfile=specfile+".new"
378 if self.options.verbose:
379 print 'Inserting changelog from %s into %s'%(logfile,specfile)
381 new=open(newspecfile,"w")
382 for line in spec.readlines():
384 if re.compile('%changelog').match(line):
385 dateformat="* %a %b %d %Y"
386 datepart=time.strftime(dateformat)
387 logpart="%s <%s> - %s %s"%(Module.config['username'],
388 Module.config['email'],
390 new.write(datepart+" "+logpart+"\n")
391 for logline in self.unignored_lines(logfile):
392 new.write("- " + logline)
396 os.rename(newspecfile,specfile)
398 def show_dict (self, spec_dict):
399 if self.options.verbose:
400 for (k,v) in spec_dict.iteritems():
404 return "%s/%s"%(Module.config['svnpath'],self.name)
408 return "%s/trunk"%(self.mod_url())
410 return "%s/branches/%s"%(self.mod_url(),self.branch)
412 def tag_name (self, spec_dict):
414 return "%s-%s-%s"%(#spec_dict[self.module_name_varname],
416 spec_dict[self.module_version_varname],
417 spec_dict[self.module_taglevel_varname])
419 print 'Something is wrong with module %s, cannot determine %s - exiting'%(self.name,err)
422 def tag_url (self, spec_dict):
423 return "%s/tags/%s"%(self.mod_url(),self.tag_name(spec_dict))
425 def check_svnpath_exists (self, url, message):
426 if self.options.fast_checks:
428 if self.options.verbose:
429 print 'Checking url (%s) %s'%(url,message),
430 ok=Svnpath(url,self.options).url_exists()
432 if self.options.verbose: print 'exists - OK'
434 if self.options.verbose: print 'KO'
435 print 'Could not find %s URL %s'%(message,url)
437 def check_svnpath_not_exists (self, url, message):
438 if self.options.fast_checks:
440 if self.options.verbose:
441 print 'Checking url (%s) %s'%(url,message),
442 ok=not Svnpath(url,self.options).url_exists()
444 if self.options.verbose: print 'does not exist - OK'
446 if self.options.verbose: print 'KO'
447 print '%s URL %s already exists - exiting'%(message,url)
450 # locate specfile, parse it, check it and show values
451 ##############################
452 def do_version (self):
455 self.revert_edge_dir()
456 self.update_edge_dir()
457 spec_dict = self.spec_dict()
458 for varname in self.varnames:
459 if not spec_dict.has_key(varname):
460 print 'Could not find %%define for %s'%varname
463 print varname+":",spec_dict[varname]
464 print 'edge url',self.edge_url()
465 print 'latest tag url',self.tag_url(spec_dict)
466 if self.options.verbose:
467 print 'main specfile:',self.main_specname()
468 print 'specfiles:',self.all_specnames()
470 init_warning="""*** WARNING
471 The module-init function has the following limitations
472 * it does not handle changelogs
473 * it does not scan the -tags*.mk files to adopt the new tags"""
474 ##############################
476 if self.options.verbose:
477 print Module.init_warning
478 if not prompt('Want to proceed anyway'):
483 self.revert_edge_dir()
484 self.update_edge_dir()
485 spec_dict = self.spec_dict()
487 edge_url=self.edge_url()
488 tag_name=self.tag_name(spec_dict)
489 tag_url=self.tag_url(spec_dict)
490 # check the tag does not exist yet
491 self.check_svnpath_not_exists(tag_url,"new tag")
493 if self.options.message:
494 svnopt='--message "%s"'%self.options.message
496 svnopt='--editor-cmd=%s'%self.options.editor
497 self.run_prompt("Create initial tag",
498 "svn copy %s %s %s"%(svnopt,edge_url,tag_url))
500 ##############################
501 def do_diff (self,compute_only=False):
504 self.revert_edge_dir()
505 self.update_edge_dir()
506 spec_dict = self.spec_dict()
507 self.show_dict(spec_dict)
509 edge_url=self.edge_url()
510 tag_url=self.tag_url(spec_dict)
511 self.check_svnpath_exists(edge_url,"edge track")
512 self.check_svnpath_exists(tag_url,"latest tag")
513 command="svn diff %s %s"%(tag_url,edge_url)
515 print 'Getting diff with %s'%command
516 diff_output = Command(command,self.options).output_of()
517 # if used as a utility
519 return (spec_dict,edge_url,tag_url,diff_output)
520 # otherwise print the result
521 if self.options.list:
525 if not self.options.only or diff_output:
526 print 'x'*30,'module',self.friendly_name()
527 print 'x'*20,'<',tag_url
528 print 'x'*20,'>',edge_url
531 ##############################
532 # using fine_grain means replacing only those instances that currently refer to this tag
533 # otherwise, <module>-SVNPATH is replaced unconditionnally
534 def patch_tags_file (self, tagsfile, oldname, newname,fine_grain=True):
535 newtagsfile=tagsfile+".new"
537 new=open(newtagsfile,"w")
540 # fine-grain : replace those lines that refer to oldname
542 if self.options.verbose:
543 print 'Replacing %s into %s\n\tin %s .. '%(oldname,newname,tagsfile),
544 matcher=re.compile("^(.*)%s(.*)"%oldname)
545 for line in tags.readlines():
546 if not matcher.match(line):
549 (begin,end)=matcher.match(line).groups()
550 new.write(begin+newname+end+"\n")
552 # brute-force : change uncommented lines that define <module>-SVNPATH
554 if self.options.verbose:
555 print 'Setting %s-SVNPATH for using %s\n\tin %s .. '%(self.name,newname,tagsfile),
556 pattern="\A\s*%s-SVNPATH\s*(=|:=)\s*(?P<url_main>[^\s]+)/%s/[^\s]+"\
557 %(self.name,self.name)
558 matcher_module=re.compile(pattern)
559 for line in tags.readlines():
560 attempt=matcher_module.match(line)
562 svnpath="%s-SVNPATH"%self.name
563 replacement = "%-32s:= %s/%s/tags/%s\n"%(svnpath,attempt.group('url_main'),self.name,newname)
564 new.write(replacement)
570 os.rename(newtagsfile,tagsfile)
571 if self.options.verbose: print "%d changes"%matches
577 self.revert_edge_dir()
578 self.update_edge_dir()
580 spec_dict = self.spec_dict()
581 self.show_dict(spec_dict)
584 edge_url=self.edge_url()
585 old_tag_name = self.tag_name(spec_dict)
586 old_tag_url=self.tag_url(spec_dict)
587 if (self.options.new_version):
588 # new version set on command line
589 spec_dict[self.module_version_varname] = self.options.new_version
590 spec_dict[self.module_taglevel_varname] = 0
593 new_taglevel = str ( int (spec_dict[self.module_taglevel_varname]) + 1)
594 spec_dict[self.module_taglevel_varname] = new_taglevel
597 new_tag_name = self.tag_name(spec_dict)
598 new_tag_url=self.tag_url(spec_dict)
599 self.check_svnpath_exists (edge_url,"edge track")
600 self.check_svnpath_exists (old_tag_url,"previous tag")
601 self.check_svnpath_not_exists (new_tag_url,"new tag")
604 diff_output=Command("svn diff %s %s"%(old_tag_url,edge_url),
605 self.options).output_of()
606 if len(diff_output) == 0:
607 if not prompt ("No difference in trunk for module %s, want to tag anyway"%self.name,False):
610 # side effect in trunk's specfile
611 self.patch_spec_var(spec_dict)
613 # prepare changelog file
614 # we use the standard subversion magic string (see svn_magic_line)
615 # so we can provide useful information, such as version numbers and diff
617 changelog="/tmp/%s-%d.txt"%(self.name,os.getpid())
618 file(changelog,"w").write("""Tagging module %s - %s
621 Please write a changelog for this new tag in the section above
622 """%(self.name,new_tag_name,Module.svn_magic_line))
624 if not self.options.verbose or prompt('Want to see diffs while writing changelog',True):
625 file(changelog,"a").write('DIFF=========\n' + diff_output)
627 if self.options.debug:
631 self.run("%s %s"%(self.options.editor,changelog))
632 # insert changelog in spec
633 if self.options.changelog:
634 self.insert_changelog (changelog,old_tag_name,new_tag_name)
638 buildname=Module.config['build']
641 build = Module(buildname,self.options)
643 build.init_edge_dir()
644 build.revert_edge_dir()
645 build.update_edge_dir()
647 tagsfiles=glob(build.edge_dir()+"/*-tags*.mk")
648 tagsdict=dict( [ (x,'todo') for x in tagsfiles ] )
650 for (tagsfile,status) in tagsdict.iteritems():
651 while tagsdict[tagsfile] == 'todo' :
652 choice = prompt ("Want to adopt %s in %s "%(new_tag_name,os.path.basename(tagsfile)),'a',
653 [ ('n', 'ext'), ('a','uto'), ('d','iff'), ('r','evert'), ('h','elp') ] )
655 self.patch_tags_file(tagsfile,old_tag_name,new_tag_name,fine_grain=False)
657 print 'Done with %s'%os.path.basename(tagsfile)
658 tagsdict[tagsfile]='done'
660 self.patch_tags_file(tagsfile,old_tag_name,new_tag_name,fine_grain=True)
662 self.run("svn diff %s"%tagsfile)
664 self.run("svn revert %s"%tagsfile)
667 print """y: unconditionnally changes any line setting %(name)s-SVNPATH to using %(new_tag_name)s
668 a: changes the definition of %(name)s only if it currently refers to %(old_tag_name)s
669 d: shows current diff for this tag file
670 r: reverts that tag file
671 n: move to next file"""%locals()
674 if prompt("Want to review changes on tags files",False):
675 tagsdict = dict ( [ (x, 'todo') for tagsfile in tagsfiles ] )
680 paths += self.edge_dir() + " "
681 paths += build.edge_dir() + " "
682 self.run_prompt("Check","svn diff " + paths)
683 self.run_prompt("Commit","svn commit --file %s %s"%(changelog,paths))
684 self.run_prompt("Create tag","svn copy --file %s %s %s"%(changelog,edge_url,new_tag_url))
686 if self.options.debug:
687 print 'Preserving',changelog
691 ##############################
692 def do_branch (self):
694 # save self.branch if any, as a hint for the new branch
695 # do this before anything else and restore .branch to None,
696 # as this is part of the class's logic
699 new_branch_name=self.branch
702 # check module-diff is empty
703 # used in do_diff, and should be options for diff only
704 (spec_dict,edge_url,tag_url,diff_listing) = self.do_diff(compute_only=True)
706 print '*** WARNING : Module %s has pending diffs on its trunk'%self.name
708 answer = prompt ('Are you sure you want to proceed with branching',False,('d','iff'))
711 elif answer is False:
714 print '<<<< %s'%tag_url
715 print '>>>> %s'%edge_url
718 # do_diff already does edge_dir initialization
719 # and it checks that edge_url and tag_url exist as well
721 # figure new branch name
722 old_branch_name = spec_dict[self.module_version_varname]
723 if not new_branch_name:
724 # heuristic is to assume 'version' is a dot-separated name
725 # we isolate the rightmost part and try incrementing it by 1
726 version=spec_dict[self.module_version_varname]
728 m=re.compile("\A(?P<leftpart>.+)\.(?P<rightmost>[^\.]+)\Z")
729 (leftpart,rightmost)=m.match(version).groups()
730 incremented = int(rightmost)+1
731 new_branch_name="%s.%d"%(leftpart,incremented)
733 print 'Cannot figure next branch name from %s - exiting'%version
737 print "Using starting point %s"%tag_url
738 print "Using branch name %s"%old_branch_name
739 print "Moving trunk to %s"%new_branch_name
742 branch_url = "%s/%s/branches/%s"%(Module.config['svnpath'],self.name,old_branch_name)
743 self.check_svnpath_not_exists (branch_url,"new branch")
745 # record starting point tagname
746 old_tag_name = self.tag_name(spec_dict)
749 spec_dict[self.module_version_varname]=new_branch_name
750 spec_dict[self.module_taglevel_varname]='0'
751 # remember this in the trunk for easy location of the current branch
752 spec_dict['module_current_branch']=old_branch_name
753 self.patch_spec_var(spec_dict,True)
755 # create commit log file
756 tmp="/tmp/branching-%d"%os.getpid()
758 f.write("Branch %s for module %s created from tag %s\n"%(new_branch_name,self.name,old_tag_name))
761 # we're done, let's commit the stuff
762 command="svn diff %s"%self.edge_dir()
763 self.run_prompt("Changes in trunk",command)
764 command="svn copy --file %s %s %s"%(tmp,self.edge_url(),branch_url)
765 self.run_prompt("Create branch",command)
766 command="svn commit --file %s %s"%(tmp,self.edge_dir())
767 self.run_prompt("Commit trunk",command)
768 new_tag_url=self.tag_url(spec_dict)
769 command="svn copy --file %s %s %s"%(tmp,self.edge_url(),new_tag_url)
770 self.run_prompt("Create initial tag in trunk",command)
773 ##############################
774 usage="""Usage: %prog options module_desc [ .. module_desc ]
776 manage subversion tags and specfile
777 requires the specfile to define *version* and *taglevel*
779 redirection variables module_version_varname / module_taglevel_varname
781 by default, the trunk of modules is taken into account
782 in this case, just mention the module name as <module_desc>
784 if you wish to work on a branch rather than on the trunk,
785 you can use something like e.g. Mom:2.1 as <module_desc>
787 see http://svn.planet-lab.org/wiki/ModuleTools
791 'version' : "only check specfile and print out details",
792 'diff' : "show difference between trunk and latest tag",
793 'tag' : """increment taglevel in specfile, insert changelog in specfile,
794 create new tag and and monitor its adoption in build/*-tags*.mk""",
795 'branch' : """create a branch for this module, from the latest tag on the trunk,
796 and change trunk's version number to reflect the new branch name;
797 you can specify the new branch name by using module:branch""",
798 'sync' : """create a tag from the trunk
799 this is a last resort option, mostly for repairs""",
805 for function in functions.keys():
806 if sys.argv[0].find(function) >= 0:
810 print "Unsupported command",sys.argv[0]
814 usage += "\nmodule-%s : %s"%(mode,functions[mode])
815 all_modules=os.path.dirname(sys.argv[0])+"/modules.list"
817 parser=OptionParser(usage=usage,version=subversion_id)
818 parser.add_option("-a","--all",action="store_true",dest="all_modules",default=False,
819 help="run on all modules as found in %s"%all_modules)
820 parser.add_option("-f","--fast-checks",action="store_true",dest="fast_checks",default=False,
821 help="skip safety checks, such as svn updates -- use with care")
822 if mode == "tag" or mode == 'branch':
823 parser.add_option("-s","--set-version",action="store",dest="new_version",default=None,
824 help="set new version and reset taglevel to 0")
826 parser.add_option("-c","--no-changelog", action="store_false", dest="changelog", default=True,
827 help="do not update changelog section in specfile when tagging")
828 if mode == "tag" or mode == "sync" :
829 parser.add_option("-e","--editor", action="store", dest="editor", default="emacs",
830 help="specify editor")
832 parser.add_option("-m","--message", action="store", dest="message", default=None,
833 help="specify log message")
835 parser.add_option("-o","--only", action="store_true", dest="only", default=False,
836 help="report diff only for modules that exhibit differences")
838 parser.add_option("-l","--list", action="store_true", dest="list", default=False,
839 help="just list modules that exhibit differences")
840 parser.add_option("-w","--workdir", action="store", dest="workdir",
841 default="%s/%s"%(os.getenv("HOME"),"modules"),
842 help="""name for dedicated working dir - defaults to ~/modules
843 ** THIS MUST NOT ** be your usual working directory""")
844 parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=True,
845 help="run in verbose mode")
846 parser.add_option("-q","--quiet", action="store_false", dest="verbose",
847 help="run in quiet (non-verbose) mode")
848 parser.add_option("-d","--debug", action="store_true", dest="debug", default=False,
849 help="debug mode - mostly more verbose")
850 (options, args) = parser.parse_args()
853 if options.all_modules:
854 args=Command("grep -v '#' %s"%all_modules,options).output_of().split()
858 Module.init_homedir(options)
860 module=Module(modname,options)
861 print '========================================',module.friendly_name()
862 # call the method called do_<mode>
863 method=Module.__dict__["do_%s"%mode]
866 # basically, we exit if anything goes wrong
867 if __name__ == "__main__" :
870 except KeyboardInterrupt: