Exemplo n.º 1
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.
        '''

        ensureParentDir(manifestPath)
        lock = lock_file(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 sorted(myregister.iterkeys()):
                mf.write(k + os.linesep)
            mf.close()
        finally:
            lock = None
Exemplo n.º 2
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 = lock_file(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 sorted(myregister.iterkeys()):
                mf.write(k + os.linesep)
            mf.close()
        finally:
            lock = None
Exemplo n.º 3
0
def gradle_lock(topobjdir, max_wait_seconds=600):
    # Building the same Gradle root project with multiple concurrent processes
    # is not well supported, so we use a simple lock file to serialize build
    # steps.
    lock_path = '{}/gradle/mach_android.lockfile'.format(topobjdir)
    ensureParentDir(lock_path)
    lock_instance = lock_file(lock_path, max_wait=max_wait_seconds)

    try:
        yield
    finally:
        del lock_instance
Exemplo n.º 4
0
    def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED,
                 lock=False):
        if lock:
            assert isinstance(file, basestring)
            self.lockfile = lock_file(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
Exemplo n.º 5
0
  def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED,
               lock = False):
    if lock:
      assert isinstance(file, basestring)
      self.lockfile = lock_file(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
Exemplo n.º 6
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 = lock_file(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()
    for e in entries:
      if e not in existing:
        existing.add(e)
    with open(listFile, 'w') as f:
      f.write("\n".join(sorted(existing))+"\n")
  finally:
    lock = None
def android(verb, *args):
    # Building the same Gradle root project with multiple concurrent processes
    # is not well supported, so we use a simple lock file to serialize build
    # steps.
    lock_path = '{}/gradle/mach_android.lockfile'.format(buildconfig.topobjdir)
    ensureParentDir(lock_path)
    lock_instance = lock_file(lock_path)
    try:
        cmd = [
            mozpath.join(buildconfig.topsrcdir, 'mach'),
            'android',
            verb,
        ]
        cmd.extend(args)
        subprocess.check_call(cmd)

        return 0
    finally:
        del lock_instance
Exemplo n.º 8
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 = lock_file(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()
        for e in entries:
            if e not in existing:
                existing.add(e)
        with open(listFile, 'w') as f:
            f.write("\n".join(sorted(existing)) + "\n")
    finally:
        lock = None
Exemplo n.º 9
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."""
    ensureParentDir(listFile)
    lock = lock_file(listFile + '.lck')
    try:
        if os.path.exists(listFile):
            f = io.open(listFile)
            existing = set(x.strip() for x in f.readlines())
            f.close()
        else:
            existing = set()
        for e in entries:
            if e not in existing:
                existing.add(e)
        with io.open(listFile, 'w', newline='\n') as f:
            f.write('\n'.join(sorted(existing)) + '\n')
    finally:
        del lock  # Explicitly release the lock_file to free it
Exemplo n.º 10
0
def android(verb, *args):
    # Building the same Gradle root project with multiple concurrent processes
    # is not well supported, so we use a simple lock file to serialize build
    # steps.
    lock_path = '{}/gradle/mach_android.lockfile'.format(buildconfig.topobjdir)
    ensureParentDir(lock_path)
    lock_instance = lock_file(lock_path)
    try:
        cmd = [
            sys.executable,
            mozpath.join(buildconfig.topsrcdir, 'mach'),
            'android',
            verb,
        ]
        cmd.extend(args)
        env = dict(os.environ)
        # Confusingly, `MACH` is set only within `mach build`.
        if env.get('MACH'):
            env['GRADLE_INVOKED_WITHIN_MACH_BUILD'] = '1'
        subprocess.check_call(cmd, env=env)

        return 0
    finally:
        del lock_instance
Exemplo n.º 11
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 = lock_file(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 sorted(myregister.iterkeys()):
                mf.write(k + os.linesep)
            mf.close()
        finally:
            lock = None