コード例 #1
0
def _ReZipSite(update_site_dir):
    """Rezip the update site.

  Args:
    update_site_dir: the root direcory of the update site
  """
    log.debug('ReZipSite(' + update_site_dir + ')')
    format_dir = 'D: {0:<120} N: {1}'
    format_file = 'F: {0:<120} N: {1}'
    format_zip = '{0:<70} {1:>9} {2:>9}'
    try:
        files = os.listdir(update_site_dir)
    except OSError as e:
        log.error('could not read files in ' + update_site_dir)
        raise e
    version_re = re.compile('.+Eclipse([0-9]\.[0-9]).+')

    for f in files:
        if f.endswith('.zip'):
            zip_file = os.path.join(update_site_dir, f)
            log.info('processing ' + zip_file)
            res = version_re.search(f)
            util.DisplayMatch(res)
            version = res.group(1)
            site_dir = os.path.join(update_site_dir, version)

            log.debug('removing ' + zip_file)
            os.remove(zip_file)
            log.debug('creating zip file ' + zip_file)
            os.chdir(site_dir)
            log.debug('creating zip in ' + os.getcwd())
            command = ['zip', zip_file]

            for root, dirs, files_to_zip in os.walk(site_dir,
                                                    followlinks=False):
                for name in files_to_zip:
                    file_to_zip = os.path.join(root, name)
                    zip_file_name = file_to_zip[len(site_dir) + 1:]
                    log.debug(format_file.format(file_to_zip, zip_file_name))
                    if not zip_file_name.endswith('pack.gz'):
                        command.append(zip_file_name)

            if log.debug:
                data = 'Command: '
                for cmd in command:
                    data = data + cmd + ' '
                log.debug(data)

            subprocess.check_call(command)
        log.debug('out rezipSite')
コード例 #2
0
def _UnzipSites(ziped_update_sites_dir):
  log.debug('unzipSites(' + ziped_update_sites_dir + ')')
  try:
    files = os.listdir(ziped_update_sites_dir)
  except OSError as e:
    log.error('could not read files in ' + ziped_update_sites_dir)
    raise e
  version_re = re.compile('.+Eclipse([0-9]\.[0-9]).+')

  for f in files:
    log.debug('processing {0}/{1}'.format(ziped_update_sites_dir, f))
    if f.endswith('.zip'):
      res = version_re.search(f)
      log.debug(util.DisplayMatch(res))
      version = res.group(1)
      unarchive_dest = os.path.join(ziped_update_sites_dir, version)
      if not os.path.exists(unarchive_dest):
        os.mkdir(unarchive_dest)

      util.Unarchive(os.path.join(ziped_update_sites_dir, f), unarchive_dest)
コード例 #3
0
def _FindEclipseArchive(eclipse_version):
  global eclipse_archive_file
  log.debug('findEclipseArchive(' + eclipse_version + ')')
  log.info('searching for Eclipse in ' + eclipse_archive_dir)
  if eclipse_archive_file is None:
    try:
      files = os.listdir(eclipse_archive_dir)
    except OSError as e:
      log.error('could not read files in ' + eclipse_archive_dir)
      raise e

    found_eclipse_dirs = []
    for f in files:
      if f.startswith('R-') or f.startswith('S-'):
        log.debug('found: ' + f)
        found_eclipse_dirs.append(f)
    if not found_eclipse_dirs:
      msg = ('could not find any Eclipse directories'
             ' starting with R or S in {0}').format(eclipse_archive_dir)
      log.error(msg)
      raise OSError(msg)

    saved_ts = datetime.datetime(1970, 1, 1)
    search_dir = None
    search_term = '[RS]-([0-9]\.[0-9](\.[0-9]|M[0-9]|RC[0-9])?)-(.+)(.*)'
    search = re.compile(search_term)
    for d in found_eclipse_dirs:
      results = search.search(d)
      util.DisplayMatch(results)
      version = results.group(1)
      timestamp = results.group(3)
      if version.find(eclipse_version) >= 0:
        eclipse_ts = datetime.datetime.strptime(timestamp, '%Y%m%d%H%M')
        if eclipse_ts > saved_ts:
          saved_ts = eclipse_ts
          search_dir = os.path.join(eclipse_archive_dir, d)

    log.debug('search_dir = ' + search_dir)
    if search_dir is None:
      msg = 'could not find any Eclipse directories with ' + eclipse_version
      log.error(msg)
      raise OSError(msg)

    try:
      files = os.listdir(search_dir)
    except OSError as e:
      log.error('could not read files in ' + search_dir)
      raise e

    eclipse_archive_file = None
    search_term = eclipse_version + '(M[0-9]|RC[0-9]|\.[0-3])?-linux-gtk.tar.gz'
    search = re.compile(search_term)

    log.debug('search_term = ' + search_term)
    for f in files:
      if search.search(f) is not None:
        eclipse_archive_file = os.path.join(search_dir, f)
        break

    if eclipse_archive_file is None:
      msg = ('could not find any Eclipse archives'
             ' with {0} in {1}').format(search_term, search_dir)
      log.error(msg)
      raise OSError(msg)

  log.info('found Eclipse archive ' + eclipse_archive_file)
  return eclipse_archive_file