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


Python file_path.rmtree函数代码示例

本文整理汇总了Python中utils.file_path.rmtree函数的典型用法代码示例。如果您正苦于以下问题:Python rmtree函数的具体用法?Python rmtree怎么用?Python rmtree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: tearDown

 def tearDown(self):
   try:
     self.server.close_start()
     file_path.rmtree(self.tempdir)
     self.server.close_end()
   finally:
     super(IsolateServerStorageSmokeTest, self).tearDown()
开发者ID:eakuefner,项目名称:luci-py,代码行数:7,代码来源:isolateserver_test.py

示例2: archive

def archive(isolate_server, script):
  """Archives the tool and return the sha-1."""
  base_script = os.path.basename(script)
  isolate = {
    'variables': {
      'command': ['python', base_script],
      'files': [base_script],
    },
  }
  tempdir = tempfile.mkdtemp(prefix=u'run_on_bots')
  try:
    isolate_file = os.path.join(tempdir, 'tool.isolate')
    isolated_file = os.path.join(tempdir, 'tool.isolated')
    with open(isolate_file, 'wb') as f:
      f.write(str(isolate))
    shutil.copyfile(script, os.path.join(tempdir, base_script))
    cmd = [
      sys.executable, 'isolate.py', 'archive',
      '--isolate-server', isolate_server,
      '-i', isolate_file,
      '-s', isolated_file,
    ]
    return subprocess.check_output(cmd, cwd=ROOT_DIR).split()[0]
  finally:
    file_path.rmtree(tempdir)
开发者ID:Crawping,项目名称:chromium_extract,代码行数:25,代码来源:run_on_bots.py

示例3: tearDown

 def tearDown(self):
   try:
     self.server.close_start()
     file_path.rmtree(self.tempdir)
     self.server.close_end()
   finally:
     super(RunIsolatedTest, self).tearDown()
开发者ID:endlessm,项目名称:chromium-browser,代码行数:7,代码来源:run_isolated_smoke_test.py

示例4: task_collect

 def task_collect(self, task_id):
   """Collects the results for a task."""
   h, tmp = tempfile.mkstemp(prefix='swarming_smoke_test', suffix='.json')
   os.close(h)
   try:
     tmpdir = tempfile.mkdtemp(prefix='swarming_smoke_test')
     try:
       # swarming.py collect will return the exit code of the task.
       args = [
         '--task-summary-json', tmp, task_id, '--task-output-dir', tmpdir,
         '--timeout', '20', '--perf',
       ]
       self._run('collect', args)
       with open(tmp, 'rb') as f:
         content = f.read()
       try:
         summary = json.loads(content)
       except ValueError:
         print >> sys.stderr, 'Bad json:\n%s' % content
         raise
       outputs = {}
       for root, _, files in os.walk(tmpdir):
         for i in files:
           p = os.path.join(root, i)
           name = p[len(tmpdir)+1:]
           with open(p, 'rb') as f:
             outputs[name] = f.read()
       return summary, outputs
     finally:
       file_path.rmtree(tmpdir)
   finally:
     os.remove(tmp)
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:32,代码来源:local_smoke_test.py

示例5: test_get_swarming_bot_zip

  def test_get_swarming_bot_zip(self):
    zipped_code = bot_code.get_swarming_bot_zip('http://localhost')
    # Ensure the zip is valid and all the expected files are present.
    with zipfile.ZipFile(StringIO.StringIO(zipped_code), 'r') as zip_file:
      for i in bot_archive.FILES:
        with zip_file.open(i) as f:
          content = f.read()
          if os.path.basename(i) != '__init__.py':
            self.assertTrue(content, i)

    temp_dir = tempfile.mkdtemp(prefix='swarming')
    try:
      # Try running the bot and ensure it can import the required files. (It
      # would crash if it failed to import them).
      bot_path = os.path.join(temp_dir, 'swarming_bot.zip')
      with open(bot_path, 'wb') as f:
        f.write(zipped_code)
      proc = subprocess.Popen(
          [sys.executable, bot_path, 'start_bot', '-h'],
          cwd=temp_dir,
          stdout=subprocess.PIPE,
          stderr=subprocess.STDOUT)
      out = proc.communicate()[0]
      self.assertEqual(0, proc.returncode, out)
    finally:
      file_path.rmtree(temp_dir)
开发者ID:rmistry,项目名称:luci-py,代码行数:26,代码来源:bot_code_test.py

示例6: test_rmtree_unicode

 def test_rmtree_unicode(self):
     subdir = os.path.join(self.tempdir, "hi")
     fs.mkdir(subdir)
     filepath = os.path.join(subdir, u"\u0627\u0644\u0635\u064A\u0646\u064A\u0629")
     with fs.open(filepath, "wb") as f:
         f.write("hi")
     # In particular, it fails when the input argument is a str.
     file_path.rmtree(str(subdir))
开发者ID:rmistry,项目名称:luci-py,代码行数:8,代码来源:file_path_test.py

示例7: tearDown

 def tearDown(self):
   for dirpath, dirnames, filenames in os.walk(self.tempdir, topdown=True):
     for filename in filenames:
       file_path.set_read_only(os.path.join(dirpath, filename), False)
     for dirname in dirnames:
       file_path.set_read_only(os.path.join(dirpath, dirname), False)
   file_path.rmtree(self.tempdir)
   super(RunIsolatedTestBase, self).tearDown()
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:8,代码来源:run_isolated_test.py

示例8: tearDown

 def tearDown(self):
     try:
         if self._tempdir:
             file_path.rmtree(self._tempdir)
         if not self.has_failed():
             self._check_output("", "")
     finally:
         super(NetTestCase, self).tearDown()
开发者ID:qlb7707,项目名称:webrtc_src,代码行数:8,代码来源:swarming_test.py

示例9: tearDown

 def tearDown(self):
   os.chdir(test_env_bot_code.BOT_DIR)
   try:
     file_path.rmtree(self.root_dir)
   except OSError:
     print >> sys.stderr, 'Failed to delete %s' % self.root_dir
   finally:
     super(TestTaskRunnerBase, self).tearDown()
开发者ID:eakuefner,项目名称:luci-py,代码行数:8,代码来源:task_runner_test.py

示例10: test_rmtree_unicode

 def test_rmtree_unicode(self):
   subdir = os.path.join(self.tempdir, 'hi')
   os.mkdir(subdir)
   filepath = os.path.join(
       subdir, u'\u0627\u0644\u0635\u064A\u0646\u064A\u0629')
   with open(filepath, 'wb') as f:
     f.write('hi')
   # In particular, it fails when the input argument is a str.
   file_path.rmtree(str(subdir))
开发者ID:nodirt,项目名称:luci-py,代码行数:9,代码来源:file_path_test.py

示例11: test_undeleteable_chmod

 def test_undeleteable_chmod(self):
   # Create a file and a directory with an empty ACL. Then try to delete it.
   dirpath = os.path.join(self.tempdir, 'd')
   filepath = os.path.join(dirpath, 'f')
   os.mkdir(dirpath)
   with open(filepath, 'w') as f:
     f.write('hi')
   os.chmod(filepath, 0)
   os.chmod(dirpath, 0)
   file_path.rmtree(dirpath)
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:10,代码来源:file_path_test.py

示例12: tearDown

 def tearDown(self):
     try:
         if self._tempdir:
             for dirpath, dirnames, filenames in fs.walk(self._tempdir, topdown=True):
                 for filename in filenames:
                     file_path.set_read_only(os.path.join(dirpath, filename), False)
                 for dirname in dirnames:
                     file_path.set_read_only(os.path.join(dirpath, dirname), False)
             file_path.rmtree(self._tempdir)
     finally:
         super(FilePathTest, self).tearDown()
开发者ID:rmistry,项目名称:luci-py,代码行数:11,代码来源:file_path_test.py

示例13: main

def main():
  tools.disable_buffering()
  parser = optparse.OptionParser()
  parser.add_option('-s', '--isolated', help='.isolated file to profile with.')
  parser.add_option('--largest_files', type='int',
                    help='If this is set, instead of compressing all the '
                    'files, only the large n files will be compressed')
  options, args = parser.parse_args()

  if args:
    parser.error('Unknown args passed in; %s' % args)
  if not options.isolated:
    parser.error('The .isolated file must be given.')

  temp_dir = None
  try:
    temp_dir = tempfile.mkdtemp(prefix=u'zip_profiler')

    # Create a directory of the required files
    subprocess.check_call([os.path.join(ROOT_DIR, 'isolate.py'),
                           'remap',
                           '-s', options.isolated,
                           '--outdir', temp_dir])

    file_set = tree_files(temp_dir)

    if options.largest_files:
      sorted_by_size = sorted(file_set.iteritems(),  key=lambda x: x[1],
                              reverse=True)
      files_to_compress = sorted_by_size[:options.largest_files]

      for filename, size in files_to_compress:
        print('Compressing %s, uncompressed size %d' % (filename, size))

        profile_compress('zlib', zlib.compressobj, range(10), zip_file,
                         filename)
        profile_compress('bz2', bz2.BZ2Compressor, range(1, 10), zip_file,
                         filename)
    else:
      print('Number of files: %s' % len(file_set))
      print('Total size: %s' % sum(file_set.itervalues()))

      # Profile!
      profile_compress('zlib', zlib.compressobj, range(10), zip_directory,
                       temp_dir)
      profile_compress('bz2', bz2.BZ2Compressor, range(1, 10), zip_directory,
                       temp_dir)
  finally:
    file_path.rmtree(temp_dir)
开发者ID:Crawping,项目名称:chromium_extract,代码行数:49,代码来源:zip_profiler.py

示例14: CMDrun

def CMDrun(parser, args):
    """Runs the test executable in an isolated (temporary) directory.

  All the dependencies are mapped into the temporary directory and the
  directory is cleaned up after the target exits.

  Argument processing stops at -- and these arguments are appended to the
  command line of the target to run. For example, use:
    isolate.py run --isolated foo.isolated -- --gtest_filter=Foo.Bar
  """
    add_isolate_options(parser)
    add_skip_refresh_option(parser)
    options, args = parser.parse_args(args)
    process_isolate_options(parser, options, require_isolated=False)
    complete_state = load_complete_state(options, os.getcwd(), None, options.skip_refresh)
    cmd = complete_state.saved_state.command + args
    if not cmd:
        raise ExecutionError("No command to run.")
    cmd = tools.fix_python_path(cmd)

    outdir = run_isolated.make_temp_dir(u"isolate-%s" % datetime.date.today(), os.path.dirname(complete_state.root_dir))
    try:
        # TODO(maruel): Use run_isolated.run_tha_test().
        cwd = create_isolate_tree(
            outdir,
            complete_state.root_dir,
            complete_state.saved_state.files,
            complete_state.saved_state.relative_cwd,
            complete_state.saved_state.read_only,
        )
        file_path.ensure_command_has_abs_path(cmd, cwd)
        logging.info("Running %s, cwd=%s" % (cmd, cwd))
        try:
            result = subprocess.call(cmd, cwd=cwd)
        except OSError:
            sys.stderr.write(
                "Failed to executed the command; executable is missing, maybe you\n"
                "forgot to map it in the .isolate file?\n  %s\n  in %s\n" % (" ".join(cmd), cwd)
            )
            result = 1
    finally:
        file_path.rmtree(outdir)

    if complete_state.isolated_filepath:
        complete_state.save_files()
    return result
开发者ID:qlb7707,项目名称:webrtc_src,代码行数:46,代码来源:isolate.py

示例15: _run_isolated

 def _run_isolated(self, hello_world, name, args, expected_summary,
     expected_files):
   # Shared code for all test_isolated_* test cases.
   tmpdir = tempfile.mkdtemp(prefix='swarming_smoke')
   try:
     isolate_path = os.path.join(tmpdir, 'i.isolate')
     isolated_path = os.path.join(tmpdir, 'i.isolated')
     with open(isolate_path, 'wb') as f:
       json.dump(ISOLATE_HELLO_WORLD, f)
     with open(os.path.join(tmpdir, 'hello_world.py'), 'wb') as f:
       f.write(hello_world)
     isolated_hash = self.client.isolate(isolate_path, isolated_path)
     task_id = self.client.task_trigger_isolated(
         name, isolated_hash, extra=args)
     actual_summary, actual_files = self.client.task_collect(task_id)
     self.assertResults(expected_summary, actual_summary)
     actual_files.pop('summary.json')
     self.assertEqual(expected_files, actual_files)
   finally:
     file_path.rmtree(tmpdir)
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:20,代码来源:local_smoke_test.py


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