当前位置: 首页>>代码示例>>Python>>正文


Python Preprocessor.clone方法代码示例

本文整理汇总了Python中Preprocessor.Preprocessor.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Preprocessor.clone方法的具体用法?Python Preprocessor.clone怎么用?Python Preprocessor.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Preprocessor.Preprocessor的用法示例。


在下文中一共展示了Preprocessor.clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: JarMaker

# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import clone [as 别名]

#.........这里部分代码省略.........
      manifestExists = os.path.isfile(manifestPath)
      mode = (manifestExists and 'r+b') or 'wb'
      mf = open(manifestPath, mode)
      if manifestExists:
        # import previous content into hash, ignoring empty ones and comments
        imf = re.compile('(#.*)?$')
        for l in re.split('[\r\n]+', mf.read()):
          if imf.match(l):
            continue
          myregister[l] = None
        mf.seek(0)
      for k in myregister.iterkeys():
        mf.write(k + os.linesep)
      mf.close()
    finally:
      lock = None

  def makeJar(self, infile, jardir):
    '''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.
    '''
    # making paths absolute, guess srcdir if file and add to sourcedirs
    _normpath = lambda p: os.path.normpath(os.path.abspath(p))
    self.topsourcedir = _normpath(self.topsourcedir)
    self.sourcedirs = [_normpath(p) for p in self.sourcedirs]
    if self.localedirs:
      self.localedirs = [_normpath(p) for p in self.localedirs]
    elif self.relativesrcdir:
      self.localedirs = self.generateLocaleDirs(self.relativesrcdir)
    if isinstance(infile, basestring):
      logging.info("processing " + infile)
      self.sourcedirs.append(_normpath(os.path.dirname(infile)))
    pp = self.pp.clone()
    pp.out = StringIO()
    pp.do_include(infile)
    lines = pushback_iter(pp.out.getvalue().splitlines())
    try:
      while True:
        l = lines.next()
        m = self.jarline.match(l)
        if not m:
          raise RuntimeError(l)
        if m.group('jarfile') is None:
          # comment
          continue
        self.processJarSection(m.group('jarfile'), lines, jardir)
    except StopIteration:
      # we read the file
      pass
    return

  def generateLocaleDirs(self, relativesrcdir):
    if os.path.basename(relativesrcdir) == 'locales':
      # strip locales
      l10nrelsrcdir = os.path.dirname(relativesrcdir)
    else:
      l10nrelsrcdir = relativesrcdir
    locdirs = []
    # generate locales dirs, merge, l10nbase, en-US
    if self.l10nmerge:
      locdirs.append(os.path.join(self.l10nmerge, l10nrelsrcdir))
    if self.l10nbase:
      locdirs.append(os.path.join(self.l10nbase, l10nrelsrcdir))
    if self.l10nmerge or not self.l10nbase:
      # add en-US if we merge, or if it's not l10n
      locdirs.append(os.path.join(self.topsourcedir, relativesrcdir, 'en-US'))
    return locdirs

  def processJarSection(self, jarfile, lines, jardir):
    '''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.
    '''

    # chromebasepath is used for chrome registration manifests
    # %s is getting replaced with chrome/ for chrome.manifest, and with
    # an empty string for jarfile.manifest
    chromebasepath = '%s' + os.path.basename(jarfile)
    if self.outputFormat == 'jar':
      chromebasepath = 'jar:' + chromebasepath + '.jar!'
    chromebasepath += '/'

    jarfile = os.path.join(jardir, jarfile)
    jf = None
    if self.outputFormat == 'jar':
      #jar
      jarfilepath = jarfile + '.jar'
      try:
        os.makedirs(os.path.dirname(jarfilepath))
      except OSError, error:
        if error.errno != errno.EEXIST:
          raise
      jf = ZipFile(jarfilepath, 'a', lock = True)
      outHelper = self.OutputHelper_jar(jf)
    else:
开发者ID:KenChang,项目名称:releases-mozilla-central,代码行数:104,代码来源:JarMaker.py

示例2: JarMaker

# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import clone [as 别名]

#.........这里部分代码省略.........
      mode = (manifestExists and 'r+b') or 'wb'
      mf = open(manifestPath, mode)
      if manifestExists:
        # import previous content into hash, ignoring empty ones and comments
        imf = re.compile('(#.*)?$')
        for l in re.split('[\r\n]+', mf.read()):
          if imf.match(l):
            continue
          myregister[l] = None
        mf.seek(0)
      for k in myregister.iterkeys():
        mf.write(k + os.linesep)
      mf.close()
    finally:
      lock = None

  def makeJar(self, infile, jardir):
    '''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.
    '''
    # making paths absolute, guess srcdir if file and add to sourcedirs
    _normpath = lambda p: os.path.normpath(os.path.abspath(p))
    self.topsourcedir = _normpath(self.topsourcedir)
    self.sourcedirs = [_normpath(p) for p in self.sourcedirs]
    if self.localedirs:
      self.localedirs = [_normpath(p) for p in self.localedirs]
    elif self.relativesrcdir:
      self.localedirs = self.generateLocaleDirs(self.relativesrcdir)
    if isinstance(infile, basestring):
      logging.info("processing " + infile)
      self.sourcedirs.append(_normpath(os.path.dirname(infile)))
    pp = self.pp.clone()
    pp.out = StringIO()
    pp.do_include(infile)
    lines = pushback_iter(pp.out.getvalue().splitlines())
    try:
      while True:
        l = lines.next()
        m = self.jarline.match(l)
        if not m:
          raise RuntimeError(l)
        if m.group('jarfile') is None:
          # comment
          continue
        self.processJarSection(m.group('jarfile'), lines, jardir)
    except StopIteration:
      # we read the file
      pass
    return

  def generateLocaleDirs(self, relativesrcdir):
    if os.path.basename(relativesrcdir) == 'locales':
      # strip locales
      l10nrelsrcdir = os.path.dirname(relativesrcdir)
    else:
      l10nrelsrcdir = relativesrcdir
    locdirs = []
    # generate locales dirs, merge, l10nbase, en-US
    if self.l10nmerge:
      locdirs.append(os.path.join(self.l10nmerge, l10nrelsrcdir))
    if self.l10nbase:
      locdirs.append(os.path.join(self.l10nbase, l10nrelsrcdir))
    if self.l10nmerge or not self.l10nbase:
      # add en-US if we merge, or if it's not l10n
开发者ID:BitVapor,项目名称:Pale-Moon,代码行数:70,代码来源:JarMaker.py

示例3: JarMaker

# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import clone [as 别名]

#.........这里部分代码省略.........
        '''updateManifest replaces the % in the chrome registration entries
    with the given chrome base path, and updates the given manifest file.
    '''
        myregister = dict.fromkeys(
            map(lambda s: s.replace('%', chromebasepath), register.iterkeys()))
        manifestExists = os.path.isfile(manifestPath)
        mode = (manifestExists and 'r+b') or 'wb'
        mf = open(manifestPath, mode)
        if manifestExists:
            # import previous content into hash, ignoring empty ones and comments
            imf = re.compile('(#.*)?$')
            for l in re.split('[\r\n]+', mf.read()):
                if imf.match(l):
                    continue
                myregister[l] = None
            mf.seek(0)
        for k in myregister.iterkeys():
            mf.write(k + os.linesep)
        mf.close()

    def 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.
    '''
        if isinstance(infile, basestring):
            logging.info("processing " + infile)
        pp = self.pp.clone()
        pp.out = StringIO()
        pp.do_include(infile)
        lines = pushback_iter(pp.out.getvalue().splitlines())
        try:
            while True:
                l = lines.next()
                m = self.jarline.match(l)
                if not m:
                    raise RuntimeError(l)
                if m.group('jarfile') is None:
                    # comment
                    continue
                self.processJarSection(
                    m.group('jarfile'), lines, jardir, sourcedirs,
                    topsourcedir, localedirs)
        except StopIteration:
            # we read the file
            pass
        return

    def 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.
开发者ID:yooyoo123,项目名称:firefox,代码行数:70,代码来源:JarMaker.py

示例4: JarMaker

# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import clone [as 别名]

#.........这里部分代码省略.........
    with the given chrome base path, and updates the given manifest file.
    '''
    lock = lockFile(manifestPath + '.lck')
    try:
      myregister = dict.fromkeys(map(lambda s: s.replace('%', chromebasepath),
                                     register.iterkeys()))
      manifestExists = os.path.isfile(manifestPath)
      mode = (manifestExists and 'r+b') or 'wb'
      mf = open(manifestPath, mode)
      if manifestExists:
        # import previous content into hash, ignoring empty ones and comments
        imf = re.compile('(#.*)?$')
        for l in re.split('[\r\n]+', mf.read()):
          if imf.match(l):
            continue
          myregister[l] = None
        mf.seek(0)
      for k in myregister.iterkeys():
        mf.write(k + os.linesep)
      mf.close()
    finally:
      lock = None
  
  def 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.
    '''
    if isinstance(infile, basestring):
      logging.info("processing " + infile)
    pp = self.pp.clone()
    pp.out = StringIO()
    pp.do_include(infile)
    lines = pushback_iter(pp.out.getvalue().splitlines())
    try:
      while True:
        l = lines.next()
        m = self.jarline.match(l)
        if not m:
          raise RuntimeError(l)
        if m.group('jarfile') is None:
          # comment
          continue
        self.processJarSection(m.group('jarfile'), lines,
                               jardir, sourcedirs, topsourcedir,
                               localedirs)
    except StopIteration:
      # we read the file
      pass
    return

  def 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.
开发者ID:Ajunboys,项目名称:mozilla-os2,代码行数:69,代码来源:JarMaker.py


注:本文中的Preprocessor.Preprocessor.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。