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


Python dirutil.touch函数代码示例

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


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

示例1: installer

    def installer(req):
      # Attempt to obtain the egg from the local cache.  If it's an exact match, we can use it.
      # If it's not an exact match, then if it's been resolved sufficiently recently, we still
      # use it.
      dist = egg_obtainer.obtain(req)
      if dist and (requirement_is_exact(req) or now - os.path.getmtime(dist.location) < ttl):
        return dist

      # Failed, so follow through to "remote" resolution
      source_translator = SourceTranslator(
           interpreter=interpreter,
           use_2to3=getattr(req, 'use_2to3', False),
           **shared_options)
      translator = ChainedTranslator(egg_translator, source_translator)
      obtainer = Obtainer(
          crawler,
          [Fetcher([req.repository])] if getattr(req, 'repository', None) else fetchers,
          translator)
      dist = obtainer.obtain(req)
      if dist:
        try:
          touch(dist.location)
        except OSError:
          pass
      return dist
开发者ID:intchar90,项目名称:commons,代码行数:25,代码来源:resolver.py

示例2: workspace

 def workspace(self, *buildfiles):
   with temporary_dir() as root_dir:
     with BuildRoot().temporary(root_dir):
       with pushd(root_dir):
         for buildfile in buildfiles:
           touch(os.path.join(root_dir, buildfile))
         yield os.path.realpath(root_dir)
开发者ID:Docworld,项目名称:pants,代码行数:7,代码来源:test_address.py

示例3: setUpClass

  def setUpClass(cls):
    cls.origin = safe_mkdtemp()
    with pushd(cls.origin):
      subprocess.check_call(['git', 'init', '--bare'])

    cls.gitdir = safe_mkdtemp()
    cls.worktree = safe_mkdtemp()

    cls.readme_file = os.path.join(cls.worktree, 'README')

    with environment_as(GIT_DIR=cls.gitdir, GIT_WORK_TREE=cls.worktree):
      cls.init_repo('depot', cls.origin)

      touch(cls.readme_file)
      subprocess.check_call(['git', 'add', 'README'])
      subprocess.check_call(['git', 'commit', '-am', 'initial commit with decode -> \x81b'])
      subprocess.check_call(['git', 'tag', 'first'])
      subprocess.check_call(['git', 'push', '--tags', 'depot', 'master'])
      subprocess.check_call(['git', 'branch', '--set-upstream', 'master', 'depot/master'])

      with safe_open(cls.readme_file, 'w') as readme:
        readme.write('Hello World.')
      subprocess.check_call(['git', 'commit', '-am', 'Update README.'])

    cls.clone2 = safe_mkdtemp()
    with pushd(cls.clone2):
      cls.init_repo('origin', cls.origin)
      subprocess.check_call(['git', 'pull', '--tags', 'origin', 'master:master'])

      with safe_open(os.path.realpath('README'), 'a') as readme:
        readme.write('--')
      subprocess.check_call(['git', 'commit', '-am', 'Update README 2.'])
      subprocess.check_call(['git', 'push', '--tags', 'origin', 'master'])

    cls.git = Git(gitdir=cls.gitdir, worktree=cls.worktree)
开发者ID:aoen,项目名称:pants,代码行数:35,代码来源:test_git.py

示例4: test_fnmatch

def test_fnmatch():
    with Fileset.over([".txt"]):
        assert leq(Fileset.zglobs("*.txt"))
        assert leq(Fileset.zglobs("?.txt"))
        assert leq(Fileset.zglobs("[].txt"))
        assert leq(Fileset.zglobs(".*"), ".txt")
        assert leq(Fileset.zglobs("*.py", ".*"), ".txt")
        assert leq(Fileset.rglobs(""))
        assert leq(Fileset.rglobs("*.txt"))
        assert leq(Fileset.rglobs("?.txt"))
        assert leq(Fileset.rglobs("[].txt"))
        assert leq(Fileset.rglobs(".*"), ".txt")
        assert leq(Fileset.rglobs("*.py", ".*"), ".txt")
        assert leq(Fileset.rglobs(".*", ".*"), ".txt")

    with Fileset.over(["a.txt"]):
        for operation in (Fileset.rglobs, Fileset.zglobs):
            assert leq(operation("*.txt"), "a.txt")
            assert leq(operation("?.txt"), "a.txt")
            assert leq(operation("[abcd].txt"), "a.txt")

    with temporary_dir() as tempdir:
        touch(os.path.join(tempdir, ".txt"))
        assert leq(Fileset.globs(".txt", root=tempdir), ".txt")
        assert leq(Fileset.globs("*.txt", root=tempdir))
        assert leq(Fileset.globs("", root=tempdir))
开发者ID:EricCen,项目名称:commons,代码行数:26,代码来源:fileset_test.py

示例5: distribution

 def distribution(self, files=None, executables=None):
   with temporary_dir() as jdk:
     for f in maybe_list(files or ()):
       touch(os.path.join(jdk, f))
     for exe in maybe_list(executables or (), expected_type=self.EXE):
       path = os.path.join(jdk, exe.name)
       with safe_open(path, 'w') as fp:
         fp.write(exe.contents or '')
       chmod_plus_x(path)
     yield jdk
开发者ID:CodeWarltz,项目名称:commons,代码行数:10,代码来源:test_distribution.py

示例6: fill

 def fill(self, slice_):
   log.debug('Disk filling %s' % slice_)
   if slice_.length == 0:
     return False
   touch(slice_.filename)
   with open(slice_.filename, 'r+b') as fp:
     if os.path.getsize(slice_.filename) < slice_.stop:
       fp.seek(slice_.stop - 1, 0)
       # write a sentinel byte which will fill the file at least up to stop.
       fp.write(b'\x00')
       return True
   return False
开发者ID:pombredanne,项目名称:rainman,代码行数:12,代码来源:fs.py

示例7: test_via_pantsini

  def test_via_pantsini(self):
    with temporary_dir() as root:
      root = os.path.realpath(root)
      touch(os.path.join(root, 'pants.ini'))
      with pushd(root):
        self.assertEqual(root, BuildRoot().path)

      BuildRoot().reset()
      child = os.path.join(root, 'one', 'two')
      safe_mkdir(child)
      with pushd(child):
        self.assertEqual(root, BuildRoot().path)
开发者ID:FernandoG26,项目名称:commons,代码行数:12,代码来源:test_build_root.py

示例8: test_round_trip

 def test_round_trip(prefix=None):
   with temporary_dir() as fromdir:
     safe_mkdir(os.path.join(fromdir, 'a/b/c'))
     touch(os.path.join(fromdir, 'a/b/d/e.txt'))
     with temporary_dir() as archivedir:
       archive = archiver.create(fromdir, archivedir, 'archive', prefix=prefix)
       with temporary_dir() as todir:
         archiver.extract(archive, todir)
         fromlisting = listtree(fromdir)
         if prefix:
           fromlisting = set(os.path.join(prefix, x) for x in fromlisting)
           if empty_dirs:
             fromlisting.add(prefix)
         self.assertEqual(fromlisting, listtree(todir))
开发者ID:govindkabra,项目名称:pants,代码行数:14,代码来源:test_archive.py

示例9: profile_classpath

def profile_classpath(profile, java_runner=None, config=None, ivy_jar=None, ivy_settings=None, workunit_factory=None):
    # TODO(John Sirois): consider rework when ant backend is gone and there is no more need to share
    # path structure

    java_runner = java_runner or runjava_indivisible

    config = config or Config.load()

    profile_dir = config.get("ivy-profiles", "workdir")
    profile_libdir = os.path.join(profile_dir, "%s.libs" % profile)
    profile_check = "%s.checked" % profile_libdir
    if not os.path.exists(profile_check):
        # TODO(John Sirois): refactor IvyResolve to share ivy invocation command line bits
        ivy_classpath = [ivy_jar] if ivy_jar else config.getlist("ivy", "classpath")

        safe_mkdir(profile_libdir)
        ivy_settings = ivy_settings or config.get("ivy", "ivy_settings")
        ivy_xml = os.path.join(profile_dir, "%s.ivy.xml" % profile)
        ivy_opts = [
            "-settings",
            ivy_settings,
            "-ivy",
            ivy_xml,
            # TODO(John Sirois): this pattern omits an [organisation]- prefix to satisfy IDEA jar naming
            # needs for scala - isolate this hack to idea.py where it belongs
            "-retrieve",
            "%s/[artifact]-[revision](-[classifier]).[ext]" % profile_libdir,
            "-sync",
            "-symlink",
            "-types",
            "jar",
            "bundle",
            "-confs",
            "default",
        ]
        result = java_runner(
            classpath=ivy_classpath,
            main="org.apache.ivy.Main",
            workunit_factory=workunit_factory,
            workunit_name="%s:bootstrap" % profile,
            opts=ivy_opts,
        )
        if result != 0:
            raise TaskError("Failed to load profile %s, ivy exit code %s" % (profile, str(result)))
        touch(profile_check)

    return [os.path.join(profile_libdir, jar) for jar in os.listdir(profile_libdir)]
开发者ID:dynamicguy,项目名称:commons,代码行数:47,代码来源:binary_util.py

示例10: execute_single_compilation

  def execute_single_compilation(self, versioned_targets, cp):
    compilation_id = Target.maybe_readable_identify(versioned_targets.targets)

    # TODO: Use the artifact cache. In flat mode we may want to look for the artifact for all targets,
    # not just the invalid ones, as it might be more likely to be present. Or we could look for both.

    if self._flatten:
      # If compiling in flat mode, we let all dependencies aggregate into a single well-known depfile. This
      # allows us to build different targets in different invocations without losing dependency information
      # from any of them.
      depfile = os.path.join(self._depfile_dir, 'dependencies.flat')
    else:
      # If not in flat mode, we let each compilation have its own depfile, to avoid quadratic behavior (each
      # compilation will read in the entire depfile, add its stuff to it and write it out again).
      depfile = os.path.join(self._depfile_dir, compilation_id) + '.dependencies'

    if not versioned_targets.valid:
      self.context.log.info('Compiling targets %s' % str(versioned_targets.targets))
      sources_by_target, processors, fingerprint = self.calculate_sources(versioned_targets.targets)
      if sources_by_target:
        sources = reduce(lambda all, sources: all.union(sources), sources_by_target.values())
        if not sources:
          touch(depfile)  # Create an empty depfile, since downstream code may assume that one exists.
          self.context.log.warn('Skipping java compile for targets with no sources:\n  %s' %
                                '\n  '.join(str(t) for t in sources_by_target.keys()))
        else:
          classpath = [jar for conf, jar in cp if conf in self._confs]
          result = self.compile(classpath, sources, fingerprint, depfile)
          if result != 0:
            default_message = 'Unexpected error - %s returned %d' % (_JMAKE_MAIN, result)
            raise TaskError(_JMAKE_ERROR_CODES.get(result, default_message))

        if processors:
          # Produce a monolithic apt processor service info file for further compilation rounds
          # and the unit test classpath.
          processor_info_file = os.path.join(self._classes_dir, _PROCESSOR_INFO_FILE)
          if os.path.exists(processor_info_file):
            with safe_open(processor_info_file, 'r') as f:
              for processor in f:
                processors.add(processor.strip())
          self.write_processor_info(processor_info_file, processors)

    # Read in the deps created either just now or by a previous compiler run on these targets.
    deps = Dependencies(self._classes_dir)
    deps.load(depfile)
    self._deps.merge(deps)
开发者ID:kevints,项目名称:commons,代码行数:46,代码来源:java_compile.py

示例11: do_mount

    def do_mount(source, destination):
      log.info('Mounting %s into task filesystem at %s.' % (source, destination))

      # If we're mounting a file into the task filesystem, the mount call will fail if the mount
      # point doesn't exist. In that case we'll create an empty file to mount over.
      if os.path.isfile(source) and not os.path.exists(destination):
        safe_mkdir(os.path.dirname(destination))
        touch(destination)
      else:
        safe_mkdir(destination)

      # This mount call is meant to mimic what mesos does when mounting into the container. C.f.
      # https://github.com/apache/mesos/blob/c3228f3c3d1a1b2c145d1377185cfe22da6079eb/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp#L521-L528
      subprocess.check_call([
          'mount',
          '-n',
          '--rbind',
          source,
          destination])
开发者ID:pgaref,项目名称:aurora,代码行数:19,代码来源:sandbox.py

示例12: setUpClass

    def setUpClass(cls):
        BuildFileTest.base_dir = tempfile.mkdtemp()

        # Seed a BUILD outside the build root that should not be detected
        touch(os.path.join(BuildFileTest.base_dir, "BUILD"))

        BuildFileTest.root_dir = os.path.join(BuildFileTest.base_dir, "root")

        BuildFileTest.touch("grandparent/parent/BUILD")
        BuildFileTest.touch("grandparent/parent/BUILD.twitter")
        BuildFileTest.makedirs("grandparent/parent/BUILD.dir")
        BuildFileTest.makedirs("grandparent/BUILD")
        BuildFileTest.touch("BUILD")
        BuildFileTest.touch("BUILD.twitter")
        BuildFileTest.touch("grandparent/parent/child1/BUILD")
        BuildFileTest.touch("grandparent/parent/child1/BUILD.twitter")
        BuildFileTest.touch("grandparent/parent/child2/child3/BUILD")
        BuildFileTest.makedirs("grandparent/parent/child2/BUILD")
        BuildFileTest.makedirs("grandparent/parent/child4")
开发者ID:foursquare,项目名称:twitter-commons,代码行数:19,代码来源:test_build_file.py

示例13: setUpClass

  def setUpClass(cls):
    BuildFileTest.base_dir = tempfile.mkdtemp()

    # Seed a BUILD outside the build root that should not be detected
    touch(os.path.join(BuildFileTest.base_dir, 'BUILD'))

    BuildFileTest.root_dir = os.path.join(BuildFileTest.base_dir, 'root')

    BuildFileTest.touch('grandparent/parent/BUILD')
    BuildFileTest.touch('grandparent/parent/BUILD.twitter')
    # Tricky!  This is a directory
    BuildFileTest.makedirs('grandparent/parent/BUILD.dir')
    BuildFileTest.makedirs('grandparent/BUILD')
    BuildFileTest.touch('BUILD')
    BuildFileTest.touch('BUILD.twitter')
    BuildFileTest.touch('grandparent/parent/child1/BUILD')
    BuildFileTest.touch('grandparent/parent/child1/BUILD.twitter')
    BuildFileTest.touch('grandparent/parent/child2/child3/BUILD')
    BuildFileTest.makedirs('grandparent/parent/child2/BUILD')
    BuildFileTest.makedirs('grandparent/parent/child4')
开发者ID:Docworld,项目名称:pants,代码行数:20,代码来源:test_build_file.py

示例14: setUp

  def setUp(self):
    self.base_dir = tempfile.mkdtemp()

    def generate_path(name):
      return os.path.join(self.base_dir, name)

    test_class_path = generate_path('com/twitter/Test.class')
    duplicate_class_path = generate_path('com/twitter/commons/Duplicate.class')
    unique_class_path = generate_path('org/apache/Unique.class')

    touch(test_class_path)
    touch(duplicate_class_path)
    touch(unique_class_path)

    def generate_jar(path, *class_name):
      with closing(ZipFile(generate_path(path), 'w')) as zipfile:
        for clazz in class_name:
          zipfile.write(clazz)
        return zipfile.filename

    @contextmanager
    def jars():
      test_jar = generate_jar('test.jar', test_class_path, duplicate_class_path)
      jar_with_duplicates = generate_jar('dups.jar', duplicate_class_path, unique_class_path)
      jar_without_duplicates = generate_jar('no_dups.jar', unique_class_path)

      jars = []
      jars.append(test_jar)
      jars.append(jar_with_duplicates)
      jars.append(jar_without_duplicates)
      yield jars

    with jars() as jars:
      self.path_with_duplicates = [jars[0], jars[1]]
      self.path_without_duplicates = [jars[0], jars[2]]
开发者ID:FernandoG26,项目名称:commons,代码行数:35,代码来源:test_detect_duplicates.py

示例15: profile_classpath

def profile_classpath(profile, java_runner=None, config=None, ivy_jar=None, ivy_settings=None,
                      workunit_factory=None):
  # TODO(John Sirois): consider rework when ant backend is gone and there is no more need to share
  # path structure

  java_runner = java_runner or runjava_indivisible

  config = config or Config.load()

  profile_dir = config.get('ivy-profiles', 'workdir')
  profile_libdir = os.path.join(profile_dir, '%s.libs' % profile)
  profile_check = '%s.checked' % profile_libdir
  if not os.path.exists(profile_check):
    # TODO(John Sirois): refactor IvyResolve to share ivy invocation command line bits
    ivy_classpath = [ivy_jar] if ivy_jar else config.getlist('ivy', 'classpath')

    safe_mkdir(profile_libdir)
    ivy_settings = ivy_settings or config.get('ivy', 'ivy_settings')
    ivy_xml = os.path.join(profile_dir, '%s.ivy.xml' % profile)
    ivy_opts = [
      '-settings', ivy_settings,
      '-ivy', ivy_xml,

      # TODO(John Sirois): this pattern omits an [organisation]- prefix to satisfy IDEA jar naming
      # needs for scala - isolate this hack to idea.py where it belongs
      '-retrieve', '%s/[artifact]-[revision](-[classifier]).[ext]' % profile_libdir,

      '-sync',
      '-symlink',
      '-types', 'jar', 'bundle',
      '-confs', 'default'
    ]
    result = java_runner(classpath=ivy_classpath, main='org.apache.ivy.Main',
                         workunit_factory=workunit_factory,
                         workunit_name='%s:bootstrap' % profile, opts=ivy_opts)
    if result != 0:
      raise TaskError('Failed to load profile %s, ivy exit code %s' % (profile, str(result)))
    touch(profile_check)

  return [os.path.join(profile_libdir, jar) for jar in os.listdir(profile_libdir)]
开发者ID:UrbanCompass,项目名称:commons,代码行数:40,代码来源:binary_util.py


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