我们从Python开源项目中,提取了以下47个代码示例,用于说明如何使用distutils.dir_util.mkpath()。
def run_cmake(): """ Runs CMake to determine configuration for this build. """ if _spawn.find_executable('cmake') is None: print("CMake is required to build this package.") print("Please install/load CMake and re-run setup.") sys.exit(-1) _build_dir = os.path.join(os.path.split(__file__)[0], 'build') _dir_util.mkpath(_build_dir) os.chdir(_build_dir) try: _spawn.spawn(['cmake', '-DCMAKE_BUILD_TYPE=release', '-DENABLE_OPENMP=True', '..']) except _spawn.DistutilsExecError: print("Error while running CMake") sys.exit(-1)
def run_cmake(arg=""): """ Forcing to run cmake """ if ds.find_executable('cmake') is None: print "CMake is required to build zql" print "Please install cmake version >= 2.8 and re-run setup" sys.exit(-1) print "Configuring zql build with CMake.... " cmake_args = arg try: build_dir = op.join(op.split(__file__)[0], 'build') dd.mkpath(build_dir) os.chdir("build") ds.spawn(['cmake', '..'] + cmake_args.split()) ds.spawn(['make', 'clean']) ds.spawn(['make']) os.chdir("..") except ds.DistutilsExecError: print "Error while running cmake" print "run 'setup.py build --help' for build options" print "You may also try editing the settings in CMakeLists.txt file and re-running setup" sys.exit(-1)
def copy_files_from_src(self): if self.bundle_files: target = os.path.join(self.role_path, 'files') if not os.path.exists(target): dir_util.mkpath(target) else: target = self.base_path if self.force: files = os.listdir(self.import_from) logger.debug('Files to import: %s' % files) for f in files: path = os.path.join(target, f) if os.path.exists(path): if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path) self.copytree(self.import_from, target, ignore=lambda dir, files: ['Dockerfile'] if dir == self.import_from else [])
def mkpath(self, name, mode=0777): mkpath(name, mode, dry_run=self.dry_run) # class CCompiler # Map a sys.platform/os.name ('posix', 'nt') to the default compiler # type for that platform. Keys are interpreted as re match # patterns. Order is important; platform mappings are preferred over # OS names.
def mkpath(self, name, mode=0777): dir_util.mkpath(name, mode, dry_run=self.dry_run)
def _copy_files(self, filelist): self.outfiles = [] if not filelist: return self.mkpath(self.install_dir) for f in filelist: self.copy_file(f, self.install_dir) self.outfiles.append(os.path.join(self.install_dir, f))
def create_dir(path): if not op.isdir(path): du.mkpath(path)
def create_role_from_templates(role_name=None, role_path=None, project_name=None, description=None): """ Create a new role with initial files from templates. :param role_name: Name of the role :param role_path: Full path to the role :param project_name: Name of the project, or the base path name. :param description: One line description of the role. :return: None """ context = locals() templates_path = os.path.join(conductor_dir, 'templates', 'role') timestamp = datetime.now().strftime('%Y%m%d%H%M%s') logger.debug('Role template location', path=templates_path) for rel_path, templates in [(os.path.relpath(path, templates_path), files) for (path, _, files) in os.walk(templates_path)]: target_dir = os.path.join(role_path, rel_path) dir_util.mkpath(target_dir) for template in templates: template_rel_path = os.path.join(rel_path, template) target_name = template.replace('.j2', '') target_path = os.path.join(target_dir, target_name) if os.path.exists(target_path): backup_path = u'%s_%s' % (target_path, timestamp) logger.debug(u'Found existing file. Backing target to backup', target=target_path, backup=backup_path) os.rename(target_path, backup_path) logger.debug("Rendering template for %s/%s" % (target_dir, template)) jinja_render_to_temp(templates_path, template_rel_path, target_dir, target_name, **context) new_file_name = "main_{}.yml".format(datetime.today().strftime('%y%m%d%H%M%S')) new_tasks_file = os.path.join(role_path, 'tasks', new_file_name) tasks_file = os.path.join(role_path, 'tasks', 'main.yml') if os.path.exists(tasks_file): os.rename(tasks_file, new_tasks_file)
def mkpath (self, name, mode=0o777): mkpath(name, mode, dry_run=self.dry_run) # Map a sys.platform/os.name ('posix', 'nt') to the default compiler # type for that platform. Keys are interpreted as re match # patterns. Order is important; platform mappings are preferred over # OS names.
def mkpath(self, name, mode=0o777): dir_util.mkpath(name, mode, dry_run=self.dry_run)
def run(self): self.mkpath(self.install_dir) for f in self.data_files: dir, files = f dir = util.convert_path(dir) if not os.path.isabs(dir): dir = os.path.join(self.install_dir, dir) elif self.root: dir = change_root(self.root, dir) self.mkpath(dir) if not files: self.outfiles.append(dir) else: for file in files: if isinstance(file, six.string_types): infile = file outfile = os.path.join(dir, os.path.basename(file)) else: infile, outfile = file infile = util.convert_path(infile) outfile = util.convert_path(outfile) if os.path.sep not in outfile: outfile = os.path.join(dir, outfile) self.copy_file(infile, outfile) self.outfiles.append(outfile)
def _setup_compile(self, outdir, macros, incdirs, sources, depends, extra): """Process arguments and decide which source files to compile.""" if outdir is None: outdir = self.output_dir elif not isinstance(outdir, str): raise TypeError, "'output_dir' must be a string or None" if macros is None: macros = self.macros elif isinstance(macros, list): macros = macros + (self.macros or []) else: raise TypeError, "'macros' (if supplied) must be a list of tuples" if incdirs is None: incdirs = self.include_dirs elif isinstance(incdirs, (list, tuple)): incdirs = list(incdirs) + (self.include_dirs or []) else: raise TypeError, \ "'include_dirs' (if supplied) must be a list of strings" if extra is None: extra = [] # Get the list of expected output (object) files objects = self.object_filenames(sources, strip_dir=0, output_dir=outdir) assert len(objects) == len(sources) pp_opts = gen_preprocess_options(macros, incdirs) build = {} for i in range(len(sources)): src = sources[i] obj = objects[i] ext = os.path.splitext(src)[1] self.mkpath(os.path.dirname(obj)) build[obj] = (src, ext) return macros, objects, extra, pp_opts, build
def _setup_compile(self, outdir, macros, incdirs, sources, depends, extra): """Process arguments and decide which source files to compile.""" if outdir is None: outdir = self.output_dir elif not isinstance(outdir, str): raise TypeError("'output_dir' must be a string or None") if macros is None: macros = self.macros elif isinstance(macros, list): macros = macros + (self.macros or []) else: raise TypeError("'macros' (if supplied) must be a list of tuples") if incdirs is None: incdirs = self.include_dirs elif isinstance(incdirs, (list, tuple)): incdirs = list(incdirs) + (self.include_dirs or []) else: raise TypeError( "'include_dirs' (if supplied) must be a list of strings") if extra is None: extra = [] # Get the list of expected output (object) files objects = self.object_filenames(sources, strip_dir=0, output_dir=outdir) assert len(objects) == len(sources) pp_opts = gen_preprocess_options(macros, incdirs) build = {} for i in range(len(sources)): src = sources[i] obj = objects[i] ext = os.path.splitext(src)[1] self.mkpath(os.path.dirname(obj)) build[obj] = (src, ext) return macros, objects, extra, pp_opts, build
def run(self): """At the end of the install function, we need to rename some files because distutils provides no way to rename files as they are placed in their install locations. """ _install.run(self) for o_src, o_dest in hardlink_modules: for e in [".py", ".pyc"]: src = util.change_root(self.root_dir, o_src + e) dest = util.change_root( self.root_dir, o_dest + e) if ostype == "posix": if os.path.exists(dest) and \ os.stat(src)[stat.ST_INO] != \ os.stat(dest)[stat.ST_INO]: os.remove(dest) file_util.copy_file(src, dest, link="hard", update=1) else: file_util.copy_file(src, dest, update=1) # XXX Uncomment it when we need to deliver python 3.4 version # of modules. # Don't install the scripts for python 3.4. if py_version == '3.4': return for d, files in six.iteritems(scripts[osname]): for (srcname, dstname) in files: dst_dir = util.change_root(self.root_dir, d) dst_path = util.change_root(self.root_dir, os.path.join(d, dstname)) dir_util.mkpath(dst_dir, verbose=True) file_util.copy_file(srcname, dst_path, update=True) # make scripts executable os.chmod(dst_path, os.stat(dst_path).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) for target, o_dest in symlink_modules: dest = util.change_root(self.root_dir, o_dest) dir_util.mkpath(os.path.dirname(dest), verbose=True) try: os.unlink(dest) except Exception: pass os.symlink(target, dest)