コード例 #1
0
ファイル: JarMaker.py プロジェクト: oss-qm/enigmail
 def 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.
 '''
     lock = lockFile(manifestPath + '.lck')
     try:
         myregister = dict.fromkeys([
             s.replace('%', chromebasepath) for s in iter(register.keys())
         ])
         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.keys():
             mf.write(k + os.linesep)
         mf.close()
     finally:
         lock = None
コード例 #2
0
  def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED,
               lock = False):
    if lock:
      assert isinstance(file, basestring)
      self.lockfile = lockFile(file + '.lck')
    else:
      self.lockfile = None

    if mode == 'a' and lock:
      # appending to a file which doesn't exist fails, but we can't check
      # existence util we hold the lock
      if (not os.path.isfile(file)) or os.path.getsize(file) == 0:
        mode = 'w'

    zipfile.ZipFile.__init__(self, file, mode, compression)
    self._remove = []
    self.end = self.fp.tell()
    self.debug = 0
コード例 #3
0
def addEntriesToListFile(listFile, entries):
    """Given a file |listFile| containing one entry per line,
  add each entry in |entries| to the file, unless it is already
  present."""
    lock = lockFile(listFile + ".lck")
    try:
        if os.path.exists(listFile):
            f = open(listFile)
            existing = set(x.strip() for x in f.readlines())
            f.close()
        else:
            existing = set()
        f = open(listFile, 'a')
        for e in entries:
            if e not in existing:
                f.write("{0}\n".format(e))
                existing.add(e)
        f.close()
    finally:
        lock = None
コード例 #4
0
ファイル: buildlist.py プロジェクト: lafisrap/enigmail
def addEntriesToListFile(listFile, entries):
    """Given a file |listFile| containing one entry per line,
  add each entry in |entries| to the file, unless it is already
  present."""
    lock = lockFile(listFile + ".lck")
    try:
        if os.path.exists(listFile):
            f = open(listFile)
            existing = set(x.strip() for x in f.readlines())
            f.close()
        else:
            existing = set()
        f = open(listFile, "a")
        for e in entries:
            if e not in existing:
                f.write("{0}\n".format(e))
                existing.add(e)
        f.close()
    finally:
        lock = None
コード例 #5
0
    def __init__(self,
                 file,
                 mode="r",
                 compression=zipfile.ZIP_STORED,
                 lock=False):
        if lock:
            assert isinstance(file, basestring)
            self.lockfile = lockFile(file + '.lck')
        else:
            self.lockfile = None

        if mode == 'a' and lock:
            # appending to a file which doesn't exist fails, but we can't check
            # existence util we hold the lock
            if (not os.path.isfile(file)) or os.path.getsize(file) == 0:
                mode = 'w'

        zipfile.ZipFile.__init__(self, file, mode, compression)
        self._remove = []
        self.end = self.fp.tell()
        self.debug = 0
コード例 #6
0
 def 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.
   '''
   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