Exemple #1
0
    def _MakeDummyArchive(self,
                          bundle_name,
                          tarname=None,
                          filename='dummy.txt'):
        tarname = (tarname or bundle_name) + '.tar.bz2'
        temp_dir = tempfile.mkdtemp(prefix='archive')
        try:
            dummy_path = os.path.join(temp_dir, filename)
            with open(dummy_path, 'w') as stream:
                stream.write('Dummy stuff for %s' % bundle_name)

            # Build the tarfile directly into the server's directory.
            tar_path = os.path.join(self.basedir, tarname)
            tarstream = tarfile.open(tar_path, 'w:bz2')
            try:
                tarstream.add(dummy_path, os.path.join(bundle_name, filename))
            finally:
                tarstream.close()

            with open(tar_path, 'rb') as archive_stream:
                sha1, size = manifest_util.DownloadAndComputeHash(
                    archive_stream)

            archive = manifest_util.Archive(manifest_util.GetHostOS())
            archive.url = self.server.GetURL(os.path.basename(tar_path))
            archive.size = size
            archive.checksum = sha1
            return archive
        finally:
            oshelpers.Remove(['-rf', temp_dir])
Exemple #2
0
def RemoveDir(dst):
    """Remove the provided path."""
    print 'rm -fr ' + dst
    oshelpers.Remove(['-fr', dst])
Exemple #3
0
def RemoveFile(dst):
    """Remove the provided file."""
    print 'rm ' + dst
    oshelpers.Remove(['-f', dst])
Exemple #4
0
def RemoveFile(dst):
    """Remove the provided file."""
    Trace('rm ' + ShortFilename(dst))
    oshelpers.Remove(['-f', dst])
Exemple #5
0
def RemoveDir(dst):
    """Remove the provided path."""
    Trace('rm -fr ' + ShortFilename(dst))
    oshelpers.Remove(['-fr', dst])
def Main(args):
  parser = optparse.OptionParser()
  # Modes
  parser.add_option('-s', '--sdk', help='SDK directory.',
      dest='sdk')
  parser.add_option('-t', '--tool', help='Which toolchain.',
      dest='tool')
  parser.add_option('-o', '--os', help='Untar for which OS.',
      dest='os')
  parser.add_option('-T', '--tmp', help='Temp directory.',
      dest='tmp')
  parser.add_option('-f', '--fin', help='Final output directory.',
      dest='fin')
  parser.add_option('-v', '--verbose', dest='verbose', default=False,
      help='Enable verbosity', action='store_true')

  options, args = parser.parse_args(args[1:])
  if not options.sdk:
    parser.error('Expecting SDK directory.')
  if not options.os:
    parser.error('Expecting OS to be specified.')
  if not options.tool:
    parser.error('Expecting which tool to untar.')
  if not options.fin:
    parser.error('Expecting final output directory.')
  if len(args) < 1:
    parser.error('Expecting path(s) to tarball(s).')

  untar_path = os.path.join(options.tmp, options.tool)
  if options.tool == 'x86_newlib':
    tool_path = os.path.join(untar_path, 'sdk', 'nacl-sdk')
  elif options.tool == 'x86_glibc':
    tool_path = os.path.join(untar_path, 'toolchain', options.os + '_x86')
  elif options.tool in ('pnacl', 'arm_newlib'):
    tool_path = untar_path
  else:
    parser.error('Unknown tool type: ' + options.tool)

  final_path = os.path.abspath(options.fin)
  stamp_path = os.path.join(final_path, 'stamp.untar')

  final_path = os.path.abspath(final_path)
  untar_path = os.path.abspath(untar_path)
  stamp_path = os.path.abspath(stamp_path)
  tool_path = os.path.abspath(tool_path)

  if options.verbose:
   print 'Delete: ' + untar_path
  oshelpers.Remove(['-fr', untar_path])

  if options.verbose:
    print 'Mkdir: ' + untar_path
  oshelpers.Mkdir(['-p', untar_path])

  if options.verbose:
    print 'Delete: ' + final_path
  oshelpers.Remove(['-fr', final_path])

  if options.verbose:
    print 'Mkdir: ' + os.path.join(options.sdk, 'toolchain')
  oshelpers.Mkdir(['-p', os.path.join(options.sdk, 'toolchain')])

  args = [os.path.abspath(a) for a in args]

  old_path = os.getcwd()
  os.chdir(untar_path)

  for arg in args:
    if options.verbose:
      print 'Open: ' + arg
    tar = cygtar.CygTar(arg, 'r', verbose=options.verbose)

    if options.verbose:
      print 'Extract'
    tar.Extract()

  os.chdir(old_path)
  if options.verbose:
    print 'Move: %s to %s' % (tool_path, final_path)
  oshelpers.Move([tool_path, final_path])

  if options.verbose:
    print 'Stamp: ' + stamp_path
  fh = open(stamp_path, 'w')
  fh.write(args[0] + '\n')
  fh.close()
  if options.verbose:
    print 'Done.'
  return 0
Exemple #7
0
def RemoveDir(dst):
    """Remove the provided path."""
    Trace('rm -fr ' + dst)
    oshelpers.Remove(['-fr', dst])
Exemple #8
0
 def tearDown(self):
   if self.server:
     self.server.Shutdown()
   oshelpers.Remove(['-rf', self.basedir])