Back to index

enigmail  1.4.3
Classes | Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
JarMaker.JarMaker Class Reference

List of all members.

Classes

class  OutputHelper_flat
class  OutputHelper_jar
class  OutputHelper_symlink

Public Member Functions

def __init__
def getCommandLineParser
def processIncludes
def finalizeJar
def updateManifest
def makeJar
def makeJars
def processJarSection

Public Attributes

 outputFormat
 useJarfileManifest
 useChromeManifest
 pp

Static Public Attributes

tuple ignore = re.compile('\s*(\#.*)?$')
tuple jarline = re.compile('(?:(?P<jarfile>[\w\d.\-\_\\\/]+).jar\:)|(?:\s*(\#.*)?)\s*$')
tuple regline = re.compile('\%\s+(.*)$')
string entryre = '(?P<optPreprocess>\*)?(?P<optOverwrite>\+?)\s+'
tuple entryline = re.compile(entryre + '(?P<output>[\w\d.\-\_\\\/\+]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/]+)\))?\s*$')

Private Member Functions

def _processEntryLine

Detailed Description

JarMaker reads jar.mn files and process those into jar files or
flat directories, along with chrome.manifest files.

Definition at line 93 of file JarMaker.py.


Constructor & Destructor Documentation

def JarMaker.JarMaker.__init__ (   self,
  outputFormat = 'flat',
  useJarfileManifest = True,
  useChromeManifest = False 
)

Definition at line 105 of file JarMaker.py.

00105 
00106                useChromeManifest = False):
00107     self.outputFormat = outputFormat
00108     self.useJarfileManifest = useJarfileManifest
00109     self.useChromeManifest = useChromeManifest
00110     self.pp = Preprocessor()


Member Function Documentation

def JarMaker.JarMaker._processEntryLine (   self,
  m,
  sourcedirs,
  topsourcedir,
  localedirs,
  outHelper,
  jf 
) [private]

Definition at line 372 of file JarMaker.py.

00372 
00373                         outHelper, jf):
00374       out = m.group('output')
00375       src = m.group('source') or os.path.basename(out)
00376       # pick the right sourcedir -- l10n, topsrc or src
00377       if m.group('locale'):
00378         src_base = localedirs
00379       elif src.startswith('/'):
00380         # path/in/jar/file_name.xul     (/path/in/sourcetree/file_name.xul)
00381         # refers to a path relative to topsourcedir, use that as base
00382         # and strip the leading '/'
00383         src_base = [topsourcedir]
00384         src = src[1:]
00385       else:
00386         # use srcdirs and the objdir (current working dir) for relative paths
00387         src_base = sourcedirs + [os.getcwd()]
00388       # check if the source file exists
00389       realsrc = None
00390       for _srcdir in src_base:
00391         if os.path.isfile(os.path.join(_srcdir, src)):
00392           realsrc = os.path.join(_srcdir, src)
00393           break
00394       if realsrc is None:
00395         if jf is not None:
00396           jf.close()
00397         raise RuntimeError('File "%s" not found in %s' % (src, ', '.join(src_base)))
00398       if m.group('optPreprocess'):
00399         outf = outHelper.getOutput(out)
00400         inf = open(realsrc)
00401         pp = self.pp.clone()
00402         if src[-4:] == '.css':
00403           pp.setMarker('%')
00404         pp.out = outf
00405         pp.do_include(inf)
00406         outf.close()
00407         inf.close()
00408         return
00409       # copy or symlink if newer or overwrite
00410       if (m.group('optOverwrite')
00411           or (getModTime(realsrc) >
00412               outHelper.getDestModTime(m.group('output')))):
00413         if self.outputFormat == 'symlink':
00414           outHelper.symlink(realsrc, out)
00415           return
00416         outf = outHelper.getOutput(out)
00417         # open in binary mode, this can be images etc
00418         inf = open(realsrc, 'rb')
00419         outf.write(inf.read())
00420         outf.close()
00421         inf.close()
00422     

Here is the call graph for this function:

Here is the caller graph for this function:

def JarMaker.JarMaker.finalizeJar (   self,
  jarPath,
  chromebasepath,
  register,
  doZip = True 
)
Helper method to write out the chrome registration entries to
jarfile.manifest or chrome.manifest, or both.

The actual file processing is done in updateManifest.

Definition at line 172 of file JarMaker.py.

00172 
00173                   doZip=True):
00174     '''Helper method to write out the chrome registration entries to
00175     jarfile.manifest or chrome.manifest, or both.
00176 
00177     The actual file processing is done in updateManifest.
00178     '''
00179     # rewrite the manifest, if entries given
00180     if not register:
00181       return
00182 
00183     chromeManifest = os.path.join(os.path.dirname(jarPath),
00184                                   '..', 'chrome.manifest')
00185 
00186     if self.useJarfileManifest:
00187       self.updateManifest(jarPath + '.manifest', chromebasepath % '',
00188                           register)
00189       addEntriesToListFile(chromeManifest, ['manifest chrome/%s.manifest' % (os.path.basename(jarPath),)])
00190     if self.useChromeManifest:
00191       self.updateManifest(chromeManifest, chromebasepath % 'chrome/',
00192                           register)

Here is the call graph for this function:

Here is the caller graph for this function:

Get a optparse.OptionParser for jarmaker.

This OptionParser has the options for jarmaker as well as
the options for the inner PreProcessor.

Definition at line 111 of file JarMaker.py.

00111 
00112   def getCommandLineParser(self):
00113     '''Get a optparse.OptionParser for jarmaker.
00114 
00115     This OptionParser has the options for jarmaker as well as
00116     the options for the inner PreProcessor.
00117     '''
00118     # HACK, we need to unescape the string variables we get,
00119     # the perl versions didn't grok strings right
00120     p = self.pp.getCommandLineParser(unescapeDefines = True)
00121     p.add_option('-f', type="choice", default="jar",
00122                  choices=('jar', 'flat', 'symlink'),
00123                  help="fileformat used for output", metavar="[jar, flat, symlink]")
00124     p.add_option('-v', action="store_true", dest="verbose",
00125                  help="verbose output")
00126     p.add_option('-q', action="store_false", dest="verbose",
00127                  help="verbose output")
00128     p.add_option('-e', action="store_true",
00129                  help="create chrome.manifest instead of jarfile.manifest")
00130     p.add_option('--both-manifests', action="store_true",
00131                  dest="bothManifests",
00132                  help="create chrome.manifest and jarfile.manifest")
00133     p.add_option('-s', type="string", action="append", default=[],
00134                  help="source directory")
00135     p.add_option('-t', type="string",
00136                  help="top source directory")
00137     p.add_option('-c', '--l10n-src', type="string", action="append",
00138                  help="localization directory")
00139     p.add_option('--l10n-base', type="string", action="append", default=[],
00140                  help="base directory to be used for localization (multiple)")
00141     p.add_option('-j', type="string",
00142                  help="jarfile directory")
00143     # backwards compat, not needed
00144     p.add_option('-a', action="store_false", default=True,
00145                  help="NOT SUPPORTED, turn auto-registration of chrome off (installed-chrome.txt)")
00146     p.add_option('-d', type="string",
00147                  help="UNUSED, chrome directory")
00148     p.add_option('-o', help="cross compile for auto-registration, ignored")
00149     p.add_option('-l', action="store_true",
00150                  help="ignored (used to switch off locks)")
00151     p.add_option('-x', action="store_true",
00152                  help="force Unix")
00153     p.add_option('-z', help="backwards compat, ignored")
00154     p.add_option('-p', help="backwards compat, ignored")
00155     return p

Here is the caller graph for this function:

def JarMaker.JarMaker.makeJar (   self,
  infile = None,
  jardir = '',
  sourcedirs = [],
  topsourcedir = '',
  localedirs = None 
)
makeJar is the main entry point to JarMaker.

It takes the input file, the output directory, the source dirs and the
top source dir as argument, and optionally the l10n dirs.

Definition at line 220 of file JarMaker.py.

00220 
00221                sourcedirs=[], topsourcedir='', localedirs=None):
00222     '''makeJar is the main entry point to JarMaker.
00223 
00224     It takes the input file, the output directory, the source dirs and the
00225     top source dir as argument, and optionally the l10n dirs.
00226     '''
00227     if isinstance(infile, basestring):
00228       logging.info("processing " + infile)
00229     pp = self.pp.clone()
00230     pp.out = StringIO()
00231     pp.do_include(infile)
00232     lines = pushback_iter(pp.out.getvalue().splitlines())
00233     try:
00234       while True:
00235         l = lines.next()
00236         m = self.jarline.match(l)
00237         if not m:
00238           raise RuntimeError(l)
00239         if m.group('jarfile') is None:
00240           # comment
00241           continue
00242         self.processJarSection(m.group('jarfile'), lines,
00243                                jardir, sourcedirs, topsourcedir,
00244                                localedirs)
00245     except StopIteration:
00246       # we read the file
00247       pass
00248     return

Here is the call graph for this function:

Here is the caller graph for this function:

def JarMaker.JarMaker.makeJars (   self,
  infiles,
  l10nbases,
  jardir = '',
  sourcedirs = [],
  topsourcedir = '',
  localedirs = None 
)
makeJars is the second main entry point to JarMaker.

It takes an iterable sequence of input file names, the l10nbases,
the output directory, the source dirs and the
top source dir as argument, and optionally the l10n dirs.

It iterates over all inputs, guesses srcdir and l10ndir from the
path and topsourcedir and calls into makeJar.

The l10ndirs are created by guessing the relativesrcdir, and resolving
that against the l10nbases. l10nbases can either be path strings, or 
callables. In the latter case, that will be called with the 
relativesrcdir as argument, and is expected to return a path string.
This logic is disabled if the jar.mn path is not inside the topsrcdir.

Definition at line 251 of file JarMaker.py.

00251 
00252                sourcedirs=[], topsourcedir='', localedirs=None):
00253     '''makeJars is the second main entry point to JarMaker.
00254 
00255     It takes an iterable sequence of input file names, the l10nbases,
00256     the output directory, the source dirs and the
00257     top source dir as argument, and optionally the l10n dirs.
00258 
00259     It iterates over all inputs, guesses srcdir and l10ndir from the
00260     path and topsourcedir and calls into makeJar.
00261 
00262     The l10ndirs are created by guessing the relativesrcdir, and resolving
00263     that against the l10nbases. l10nbases can either be path strings, or 
00264     callables. In the latter case, that will be called with the 
00265     relativesrcdir as argument, and is expected to return a path string.
00266     This logic is disabled if the jar.mn path is not inside the topsrcdir.
00267     '''
00268     topsourcedir = os.path.normpath(os.path.abspath(topsourcedir))
00269     def resolveL10nBase(relpath):
00270       def _resolve(base):
00271         if isinstance(base, basestring):
00272           return os.path.join(base, relpath)
00273         if callable(base):
00274           return base(relpath)
00275         return base
00276       return _resolve
00277     for infile in infiles:
00278       srcdir = os.path.normpath(os.path.abspath(os.path.dirname(infile)))
00279       l10ndir = srcdir
00280       if os.path.basename(srcdir) == 'locales':
00281         l10ndir = os.path.dirname(l10ndir)
00282 
00283       l10ndirs = None
00284       # srcdir may not be a child of topsourcedir, in which case
00285       # we assume that the caller passed in suitable sourcedirs,
00286       # and just skip passing in localedirs
00287       if srcdir.startswith(topsourcedir):
00288         rell10ndir = l10ndir[len(topsourcedir):].lstrip(os.sep)
00289 
00290         l10ndirs = map(resolveL10nBase(rell10ndir), l10nbases)
00291         if localedirs is not None:
00292           l10ndirs += [os.path.normpath(os.path.abspath(s))
00293                        for s in localedirs]
00294       srcdirs = [os.path.normpath(os.path.abspath(s))
00295                  for s in sourcedirs] + [srcdir]
00296       self.makeJar(infile=infile,
00297                    sourcedirs=srcdirs, topsourcedir=topsourcedir,
00298                    localedirs=l10ndirs,
00299                    jardir=jardir)
00300 

Here is the call graph for this function:

Here is the caller graph for this function:

def JarMaker.JarMaker.processIncludes (   self,
  includes 
)
Process given includes with the inner PreProcessor.

Only use this for #defines, the includes shouldn't generate
content.

Definition at line 156 of file JarMaker.py.

00156 
00157   def processIncludes(self, includes):
00158     '''Process given includes with the inner PreProcessor.
00159 
00160     Only use this for #defines, the includes shouldn't generate
00161     content.
00162     '''
00163     self.pp.out = StringIO()
00164     for inc in includes:
00165       self.pp.do_include(inc)
00166     includesvalue = self.pp.out.getvalue()
00167     if includesvalue:
00168       logging.info("WARNING: Includes produce non-empty output")
00169     self.pp.out = None
00170     pass

Here is the call graph for this function:

def JarMaker.JarMaker.processJarSection (   self,
  jarfile,
  lines,
  jardir,
  sourcedirs,
  topsourcedir,
  localedirs 
)
Internal method called by makeJar to actually process a section
of a jar.mn file.

jarfile is the basename of the jarfile or the directory name for 
flat output, lines is a pushback_iterator of the lines of jar.mn,
the remaining options are carried over from makeJar.

Definition at line 302 of file JarMaker.py.

00302 
00303                         jardir, sourcedirs, topsourcedir, localedirs):
00304     '''Internal method called by makeJar to actually process a section
00305     of a jar.mn file.
00306 
00307     jarfile is the basename of the jarfile or the directory name for 
00308     flat output, lines is a pushback_iterator of the lines of jar.mn,
00309     the remaining options are carried over from makeJar.
00310     '''
00311 
00312     # chromebasepath is used for chrome registration manifests
00313     # %s is getting replaced with chrome/ for chrome.manifest, and with
00314     # an empty string for jarfile.manifest
00315     chromebasepath = '%s' + jarfile
00316     if self.outputFormat == 'jar':
00317       chromebasepath = 'jar:' + chromebasepath + '.jar!'
00318     chromebasepath += '/'
00319 
00320     jarfile = os.path.join(jardir, jarfile)
00321     jf = None
00322     if self.outputFormat == 'jar':
00323       #jar
00324       jarfilepath = jarfile + '.jar'
00325       try:
00326         os.makedirs(os.path.dirname(jarfilepath))
00327       except OSError:
00328         pass
00329       jf = ZipFile(jarfilepath, 'a', lock = True)
00330       outHelper = self.OutputHelper_jar(jf)
00331     else:
00332       outHelper = getattr(self, 'OutputHelper_' + self.outputFormat)(jarfile)
00333     register = {}
00334     # This loop exits on either
00335     # - the end of the jar.mn file
00336     # - an line in the jar.mn file that's not part of a jar section
00337     # - on an exception raised, close the jf in that case in a finally
00338     try:
00339       while True:
00340         try:
00341           l = lines.next()
00342         except StopIteration:
00343           # we're done with this jar.mn, and this jar section
00344           self.finalizeJar(jarfile, chromebasepath, register)
00345           if jf is not None:
00346             jf.close()
00347           # reraise the StopIteration for makeJar
00348           raise
00349         if self.ignore.match(l):
00350           continue
00351         m = self.regline.match(l)
00352         if  m:
00353           rline = m.group(1)
00354           register[rline] = 1
00355           continue
00356         m = self.entryline.match(l)
00357         if not m:
00358           # neither an entry line nor chrome reg, this jar section is done
00359           self.finalizeJar(jarfile, chromebasepath, register)
00360           if jf is not None:
00361             jf.close()
00362           lines.pushback(l)
00363           return
00364         self._processEntryLine(m, sourcedirs, topsourcedir, localedirs,
00365                               outHelper, jf)
00366     finally:
00367       if jf is not None:
00368         jf.close()
00369     return

Here is the call graph for this function:

Here is the caller graph for this function:

def JarMaker.JarMaker.updateManifest (   self,
  manifestPath,
  chromebasepath,
  register 
)
updateManifest replaces the % in the chrome registration entries
with the given chrome base path, and updates the given manifest file.

Definition at line 193 of file JarMaker.py.

00193 
00194   def updateManifest(self, manifestPath, chromebasepath, register):
00195     '''updateManifest replaces the % in the chrome registration entries
00196     with the given chrome base path, and updates the given manifest file.
00197     '''
00198     lock = lockFile(manifestPath + '.lck')
00199     try:
00200       myregister = dict.fromkeys(map(lambda s: s.replace('%', chromebasepath),
00201                                      register.iterkeys()))
00202       manifestExists = os.path.isfile(manifestPath)
00203       mode = (manifestExists and 'r+b') or 'wb'
00204       mf = open(manifestPath, mode)
00205       if manifestExists:
00206         # import previous content into hash, ignoring empty ones and comments
00207         imf = re.compile('(#.*)?$')
00208         for l in re.split('[\r\n]+', mf.read()):
00209           if imf.match(l):
00210             continue
00211           myregister[l] = None
00212         mf.seek(0)
00213       for k in myregister.iterkeys():
00214         mf.write(k + os.linesep)
00215       mf.close()
00216     finally:
00217       lock = None
  

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tuple JarMaker.JarMaker.entryline = re.compile(entryre + '(?P<output>[\w\d.\-\_\\\/\+]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/]+)\))?\s*$') [static]

Definition at line 102 of file JarMaker.py.

string JarMaker.JarMaker.entryre = '(?P<optPreprocess>\*)?(?P<optOverwrite>\+?)\s+' [static]

Definition at line 101 of file JarMaker.py.

tuple JarMaker.JarMaker.ignore = re.compile('\s*(\#.*)?$') [static]

Definition at line 98 of file JarMaker.py.

tuple JarMaker.JarMaker.jarline = re.compile('(?:(?P<jarfile>[\w\d.\-\_\\\/]+).jar\:)|(?:\s*(\#.*)?)\s*$') [static]

Definition at line 99 of file JarMaker.py.

Definition at line 106 of file JarMaker.py.

Definition at line 109 of file JarMaker.py.

tuple JarMaker.JarMaker.regline = re.compile('\%\s+(.*)$') [static]

Definition at line 100 of file JarMaker.py.

Definition at line 108 of file JarMaker.py.

Definition at line 107 of file JarMaker.py.


The documentation for this class was generated from the following file: