LT 91: The "disregard exit status by default" strategy is rotten!

Index: ChangeLog from Akim Demaille <akim@epita.fr> The "disregard exit status by default" strategy is rotten! * prcs2svn/prcs2svn.py (error): Expect an exit status. (warn, fatal): New. (xsystem, xtee): By default, do not disregard the exit status. And these new functions to output better messages and exit when appropriate. Adjust all callers. Flag those where ignoring error is truly OK. (repositoryCmp.cmp_trunk): Complete PRCS' message with the missing eol. Index: prcs2svn/prcs2svn.py --- prcs2svn/prcs2svn.py (revision 88) +++ prcs2svn/prcs2svn.py (working copy) @@ -79,25 +79,30 @@ print msg sys.stdout.flush() -def error(msg): - sys.stderr.write(msg + "\n") +def error(status, msg): + print "prcs2svn: ***" + msg >>sys.stderr sys.stderr.flush() + if status: + sys.exit (status) + +def warn(msg): + error (0, "Warning: " + msg) + +def fatal(msg): + error (1, "Error: " + msg) ## ------------------------------------- ## Misc. ## Print cmd on debug stream and execute it through os.system. -def xsystem(cmd, ignErr=True): +def xsystem(cmd, ignErr=False): debug("os.system(\"" + cmd + "\")") - if 2 > infos.trace_level: + if infos.trace_level < 2: cmd += "> /dev/null 2> /dev/null" - if ignErr: - if os.system(cmd) != 0: - # Errors may be ignored if the repositories are the same. - error("** Warning: '" + cmd + "' returned an error.") - else: - assert(os.system(cmd) == 0) + status = os.system(cmd) + if status: + error (int (ignErr), cmd + ": returned an error (" + status + ")") ## Add quote for filename, directory's name, ... def quote(path): @@ -117,12 +122,10 @@ for line in pipe: res += len(line) sys.__stdout__.write(line) - if not ignErr: - if pipe.close() != None: - # Errors may be ignored if the repositories are the same. - error("** Warning: '" + cmd + "' returned an error.") - else: - pipe.close() + # What is this supposed to return? There is nothing in the doc! --akim + status = pipe.close () + if status: + error (int (ignErr), cmd + ": returned an error (" + status + ")") return res ## Print copy on debug stream and copy a file. @@ -361,6 +364,9 @@ os.mkdir(self.prcs_project + "_prcs") os.chdir(self.prcs_project + "_prcs") xsystem("prcs checkout -f " + prcs_revision + self.prjname ()) + # PRCS sometimes lacks a \n after the messages emitted by checkout -f. + if 2 <= infos.trace_level: + print svn_repo = os.path.join(self.svn_project, os.path.join(infos.subdir, "trunk")) if len(infos.prcs_projects) > 1: svn_repo = os.path.join(svn_repo, self.prcs_project) @@ -456,7 +462,7 @@ self.topdir = topdir self.workdir = os.path.join(self.topdir, infos.subdir) info("> Checkout subversion repository") - xsystem("svn checkout " + self.repository + " " + quote(self.topdir), False) + xsystem("svn checkout " + self.repository + " " + quote(self.topdir)) info("> Create subversion repository tree") if len(infos.subdir) > 0: xsystem("svn mkdir " + infos.subdir, False) @@ -541,7 +547,7 @@ "--username " + checkin_login + " --file " + log_path) if r > 0: self.revision += 1 - # Refresh local copy (should be useness, may be a bug of svn). + # Refresh local copy (should be useless, may be a bug of svn). if update: xsystem("svn update") os.remove(log_path) @@ -946,12 +952,14 @@ if svn_branch_start < self.svn.branches[self.svn.branch][0] and \ self.svn.branches[self.svn.branch][0] < svn_merge_parent[1]: svn_branch_start = self.svn.branches[self.svn.branch][0] - # Do merge. + + # Do merge. Ignore errors, since anyway we will solve all the + # conflicts and make a fresh and clean tree. xsystem("svn --force merge " + \ "-r " + str(svn_branch_start) + \ ":" + str(svn_merge_parent[1]) + \ " " + urlparse.urljoin(self.svn.repository + "/", - svn_merge_parent[0])) + svn_merge_parent[0]), True) # The conflicts will be resolved later, tell it now to Subversion. xsystem("svn resolved --recursive .") self.svn.changes_commit("prcs2svn", "Only merge branches, "+\
participants (1)
-
Akim Demaille