Back to index

plone3  3.1.7
Classes | Functions | Variables
fillmsgstr Namespace Reference

Classes

class  Usage

Functions

def dump
def main

Variables

string help_message

Function Documentation

def fillmsgstr.dump (   s)

Definition at line 87 of file fillmsgstr.py.

00087 
00088 def dump(s):
00089     print '>>> %s' % s

Here is the caller graph for this function:

def fillmsgstr.main (   argv = None)

Definition at line 90 of file fillmsgstr.py.

00090 
00091 def main(argv=None):
00092     if argv is None:
00093         argv = sys.argv
00094     try:
00095         try:
00096             opts, args = getopt.getopt(argv[1:], "hro:v", 
00097                                        ["help", "output="])
00098         except getopt.error, msg:
00099              raise Usage(msg)
00100     
00101         # option processing
00102         verbose, output, infile, infilepath, reverse = \
00103           False, None, None, None, False
00104         for option, value in opts:
00105             if option == "-v":
00106                 verbose = True
00107             if option in ("-h", "--help"):
00108                 raise Usage(help_message)
00109             if option in ("-o", "--output"):
00110                 output = value
00111             if option in ("-r"):
00112                 reverse = True
00113         if len(args) < 1:
00114             print >> sys.stderr, "You forgot your input file..."
00115             raise Usage(help_message)
00116 
00117         if len(args) > 1 and output:
00118             print >> sys.stderr, "If you specify an output file, then you may only provide a single input file..."
00119             raise Usage(help_message)
00120                         
00121          
00122         for infilepath in args:
00123             if os.path.isfile(infilepath):
00124                 infile=fileinput.input(infilepath)
00125             else:
00126                 print >> sys.stderr, "Check your input file. %s Is it a text file?" % infilepath
00127                 raise Usage(help_message)
00128 
00129     except Usage, err:
00130         print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
00131         print >> sys.stderr, "\t for help use --help"
00132         return 2
00133     
00134     for infilepath in args:
00135         infile=fileinput.input(infilepath)        
00136 
00137         if output:
00138             outfilepath=output
00139         else:
00140             if reverse:
00141                 outfilepath=infilepath + '.unfilled'
00142             else:
00143                 outfilepath=infilepath + '.filled'
00144     
00145         outfile=open(outfilepath, 'w')
00146     
00147         defMark='#. Default:'
00148         msgidMark='msgid '
00149         msgstrMark='msgstr '
00150         savedMark='#saved'
00151         buff = None
00152         if reverse:
00153             for line in infile:
00154                 # convert the #savedmsgid lines back to msgid lines
00155                 # and swallow the next msgid, i.e. the fake one we created earlier
00156                 if line.startswith(savedMark):
00157                     buff=1          
00158                     # save this line, less the savedMark, until we see the msgstr line
00159                     delayedLine=line[len(savedMark):]
00160                     continue
00161                 if not buff:
00162                     outfile.write(line)
00163                     continue
00164                 # ok, so we're buffering, which means...
00165                 #   Delete next msgid, by omission, and drop the delayedLine in its place.
00166                 #   This ensures it appears after any comments that it may been 
00167                 #   moved ahead of by some translation memory tools.
00168                 if line.startswith(msgidMark): 
00169                     buff=None
00170                     outfile.write(delayedLine)
00171                     continue
00172                 # but meanwhile other lines remain unchanged
00173                 outfile.write(line)
00174         else:
00175             for line in infile:
00176                 if line.startswith(defMark):
00177                     buff=line[len(defMark):]
00178                     outfile.write(line)
00179                     continue
00180                 if not buff:
00181                     outfile.write(line)
00182                     continue
00183                 # ok, so we're buffering, which means...
00184         
00185                 # we rename msgid to savedmsgid
00186                 # and if the msgid is cryptic (different from buff) write buff 
00187                 # as msgid, else write line
00188                 if line.startswith(msgidMark):
00189                     outfile.write('#saved%s' % line)
00190                     if line[len(msgidMark):] <> buff:
00191                         oline='msgid%s' % buff
00192                     else:
00193                         oline=line
00194                     outfile.write(oline)
00195                     buff=None
00196                     if verbose:
00197                         dump(oline)            
00198                     continue
00199                 outfile.write(line)
00200         
00201         outfile.close()
00202         infile.close()
00203     

Here is the call graph for this function:


Variable Documentation

Definition at line 21 of file fillmsgstr.py.