def make_release_tree(self, base_dir, files): """Create the directory tree that will become the dist archive. """ self.mkpath(base_dir) dir_util.create_tree(base_dir, files, dry_run=self.dry_run) # Original hard link logic from distutils # However, /most/ files will not be linked, just compiled over if hasattr(os, 'link'): # can make hard links on this system link = 'hard' log.info('making hard links in {}...'.format(base_dir)) else: link = None log.info('copying files to {}...'.format(base_dir)) compiled_files = self.python_sources.values() if not self.dry_run: compile_multiple(self.python_sources.keys(), self.compilation_options) for c_file in compiled_files: dest = os.path.join(base_dir, c_file) self.move_file(c_file, dest) for filename in files: if filename not in compiled_files: if not os.path.isfile(filename): log.warn( '"{}" not a regular file -- skipping'.format(filename)) else: dest = os.path.join(base_dir, filename) self.copy_file(filename, dest, link=link) self.distribution.metadata.write_pkg_info(base_dir)
def copy_gstreamer_dlls(self, dest_path): """Copy gstreamer DLLs to a directory. This method does the work for setup_gstreamer_bin_dir(). It copies over DLLs from the gstreamer bin directory, unless they also exist in GTK_BIN_PATH. """ src_path = os.path.join(GSTREAMER_PATH, 'bin') files_to_copy = [] for name in os.listdir(src_path): if name == 'libgtkgl-2.0-1.dll': # This one isn't in the GTK bin directory, but we still want # to skiip it. It's definitely not needed, and might get in # the way. continue if os.path.exists(os.path.join(GTK_BIN_PATH, name)): # This file is also in the GTK runtime directory. We want to # use the GTK version, so don't copy the file continue files_to_copy.append(name) dir_util.create_tree(dest_path, files_to_copy) for name in files_to_copy: file_util.copy_file(os.path.join(src_path, name), dest_path, update=True)
def setup_python3(): # Taken from "distribute" setup.py from distutils.filelist import FileList from distutils import dir_util, file_util, util, log from os.path import join tmp_src = join("build", "src") log.set_verbosity(1) fl = FileList() for line in open("MANIFEST.in"): if not line.strip(): continue fl.process_template_line(line) dir_util.create_tree(tmp_src, fl.files) outfiles_2to3 = [] for f in fl.files: outf, copied = file_util.copy_file(f, join(tmp_src, f), update=1) if copied and outf.endswith(".py"): outfiles_2to3.append(outf) util.run_2to3(outfiles_2to3) # arrange setup to use the copy sys.path.insert(0, tmp_src) return tmp_src
def make_release_tree(self, base_dir, files): self.mkpath(base_dir) dir_util.create_tree(base_dir, files, verbose=self.verbose, dry_run=self.dry_run) if hasattr(os, 'link'): # can make hard links on this system link = 'hard' msg = "making hard links in %s..." % base_dir else: # nope, have to copy link = None msg = "copying files to %s..." % base_dir if not files: self.warn("no files to distribute -- empty manifest?") else: self.announce(msg) for file in files: if os.path.isfile(file): dest = os.path.join(base_dir, file) self.copy_file(file, dest, link=link) elif os.path.isdir(file): dir_util.mkpath(os.path.join(base_dir, file)) else: self.warn("'%s' not a regular file or directory -- skipping" % file)
def setup_python3(): # Taken from "distribute" setup.py from distutils.filelist import FileList from distutils import dir_util, file_util, util, log tmp_src = join("build", "src") log.set_verbosity(1) fl = FileList() for line in open("MANIFEST.in"): if not line.strip(): continue fl.process_template_line(line) dir_util.create_tree(tmp_src, fl.files) outfiles_2to3 = [] for f in fl.files: outf, copied = file_util.copy_file(f, join(tmp_src, f), update=1) if copied and outf.endswith(".py"): outfiles_2to3.append(outf) util.run_2to3(outfiles_2to3) # arrange setup to use the copy sys.path.insert(0, tmp_src) return tmp_src
def make_release_tree(self, base_dir, files): """Create the directory tree that will become the source distribution archive. All directories implied by the filenames in 'files' are created under 'base_dir', and then we hard link or copy (if hard linking is unavailable) those files into place. Essentially, this duplicates the developer's source tree, but in a directory named after the distribution, containing only the files to be distributed. """ # Create all the directories under 'base_dir' necessary to # put 'files' there. dir_util.create_tree(base_dir, files, verbose=self.verbose, dry_run=self.dry_run) # And walk over the list of files, either making a hard link (if # os.link exists) to each one that doesn't already exist in its # corresponding location under 'base_dir', or copying each file # that's out-of-date in 'base_dir'. (Usually, all files will be # out-of-date, because by default we blow away 'base_dir' when # we're done making the distribution archives.) if hasattr(os, 'link'): # can make hard links on this system link = 'hard' msg = "making hard links in %s..." % base_dir else: # nope, have to copy link = None msg = "copying files to %s..." % base_dir self.announce(msg) for file in files: dest = os.path.join(base_dir, file) self.copy_file(file, dest, link=link)
def fullCopy(srcdir, dstdir, item): """ Copy the item from srcdir to dstdir, creates missing directories if needed """ item = item.rstrip().lstrip().lstrip("./").rstrip("/") srcdir = srcdir.rstrip("/") dstdir = dstdir.rstrip("/") if not re.match(r"(.*)[a-zA-Z0-9]+(.*)", item): #we want to have explicit elements gLogger.error("You try to get all files, that cannot happen") return S_OK() src = os.path.join(srcdir, item) items = glob.glob(src) if not items: gLogger.error("No items found matching", src) return S_ERROR("No items found!") for item in items: item = item.replace(srcdir, "").lstrip("/") dst = os.path.join(dstdir, item) try: dir_util.create_tree(dstdir, [item]) except errors.DistutilsFileError, why: return S_ERROR(str(why)) if os.path.isfile(os.path.join(srcdir, item)): try: shutil.copy2(os.path.join(srcdir, item), dst) except EnvironmentError, why: return S_ERROR(str(why))
def make_release_tree (self, base_dir, files): """Create the directory tree that will become the source distribution archive. All directories implied by the filenames in 'files' are created under 'base_dir', and then we hard link or copy (if hard linking is unavailable) those files into place. Essentially, this duplicates the developer's source tree, but in a directory named after the distribution, containing only the files to be distributed. """ # Create all the directories under 'base_dir' necessary to # put 'files' there. dir_util.create_tree (base_dir, files, verbose=self.verbose, dry_run=self.dry_run) # And walk over the list of files, either making a hard link (if # os.link exists) to each one that doesn't already exist in its # corresponding location under 'base_dir', or copying each file # that's out-of-date in 'base_dir'. (Usually, all files will be # out-of-date, because by default we blow away 'base_dir' when # we're done making the distribution archives.) if hasattr (os, 'link'): # can make hard links on this system link = 'hard' msg = "making hard links in %s..." % base_dir else: # nope, have to copy link = None msg = "copying files to %s..." % base_dir self.announce (msg) for file in files: dest = os.path.join (base_dir, file) self.copy_file (file, dest, link=link)
def run(self, test): """Run the given test case or test suite.""" classname = test.__class__.__module__ + "." + test.__class__.__name__ if self._output_name is None: self._output_name = classname if self._stream == None: filename = "TEST-%s.xml" % self._output_name dir_util.create_tree(self._output_dir, [filename]) stream = file(os.path.join(self._output_dir, filename), "w") stream.write('<?xml version="1.0" encoding="utf-8"?>\n') else: stream = self._stream self.result.test_name = self._output_name start_time = time.time() with _fake_std_streams(): test(self.result) try: out_s = sys.stdout.getvalue() except AttributeError: out_s = "" try: err_s = sys.stderr.getvalue() except AttributeError: err_s = "" time_taken = time.time() - start_time self.result.print_report(stream, time_taken, out_s, err_s) if self._stream is None: stream.close() return self.result
def make_release_tree(self, base_dir, files): """Create the directory tree becoming the distribution archive This method differs from the original forcing making a copy of the files instead of hard linking. """ self.mkpath(base_dir) create_tree(base_dir, files, dry_run=self.dry_run) msg = "copying files to %s..." % base_dir log.info(msg) for afile in files: if not os.path.isfile(afile): log.warn("'%s' not a regular file -- skipping" % afile) else: dest = os.path.join(base_dir, afile) self.copy_file(afile, dest) # install extra files extra_files = [ ('version.py', os.path.join(base_dir, os.path.normpath('python2/mysql/connector/'))), ('version.py', os.path.join(base_dir, os.path.normpath('python3/mysql/connector/'))), ] for src, dest in extra_files: self.copy_file(src, dest)
def make_release_tree(self, base_dir, files): """Create the directory tree that will become the source distribution archive. All directories implied by the filenames in 'files' are created under 'base_dir', and then we hard link or copy (if hard linking is unavailable) those files into place. Essentially, this duplicates the developer's source tree, but in a directory named after the distribution, containing only the files to be distributed. """ self.mkpath(base_dir) dir_util.create_tree(base_dir, files, dry_run=self.dry_run) if hasattr(os, 'link'): link = 'hard' msg = 'making hard links in %s...' % base_dir else: link = None msg = 'copying files to %s...' % base_dir if not files: log.warn('no files to distribute -- empty manifest?') else: log.info(msg) for file in files: if not os.path.isfile(file): log.warn("'%s' not a regular file -- skipping" % file) else: dest = os.path.join(base_dir, file) self.copy_file(file, dest, link=link) self.distribution.metadata.write_pkg_info(base_dir) return
def fullCopy(srcdir, dstdir, item): """ Copy the item from srcdir to dstdir, creates missing directories if needed """ item = item.rstrip().lstrip().lstrip("./").rstrip("/") srcdir = srcdir.rstrip("/") dstdir = dstdir.rstrip("/") if not re.match(r"(.*)[a-zA-Z0-9]+(.*)", item):#we want to have explicit elements gLogger.error("You try to get all files, that cannot happen") return S_OK() src = os.path.join(srcdir, item) items = glob.glob(src) if not items: gLogger.error("No items found matching", src) return S_ERROR("No items found!") for item in items: item = item.replace(srcdir,"").lstrip("/") dst = os.path.join(dstdir, item) try: dir_util.create_tree(dstdir, [item]) except errors.DistutilsFileError, why: return S_ERROR(str(why)) if os.path.isfile(os.path.join(srcdir, item)): try: shutil.copy2(os.path.join(srcdir, item), dst) except EnvironmentError, why: return S_ERROR(str(why))
def setup_python3(): """Taken from "distribute" setup.py.""" from distutils.filelist import FileList from distutils import dir_util, file_util, util from os.path import join, exists tmp_src = join("build", "src") # Not covered by "setup.py clean --all", so explicit deletion required. if exists(tmp_src): dir_util.remove_tree(tmp_src) # log.set_verbosity(1) fl = FileList() for line in open("MANIFEST.in"): if not line.strip(): continue fl.process_template_line(line) dir_util.create_tree(tmp_src, fl.files) outfiles_2to3 = [] for f in fl.files: outf, copied = file_util.copy_file(f, join(tmp_src, f), update=1) if copied and outf.endswith(".py"): outfiles_2to3.append(outf) util.run_2to3(outfiles_2to3) # arrange setup to use the copy sys.path.insert(0, tmp_src) return tmp_src
def run(self): dist_py2exe_path = os.path.normpath( os.path.join(os.path.abspath(os.path.dirname(__file__)), "py2exe_builder/dist_py2exe")) # clean destination directory if os.path.isdir(dist_py2exe_path): dir_util.remove_tree(dist_py2exe_path) # build with py2exe py2exe.build_exe.py2exe.run(self) # copy data files src_base = os.path.dirname(__file__) for dst, src_files in py2exe_dataFiles: dst_abs = os.path.normpath(os.path.join(dist_py2exe_path, dst)) for src in src_files: try: src_abs = os.path.normpath(os.path.join(src_base, src)) dir_util.create_tree(dst_abs, src_abs) file_util.copy_file(src_abs, dst_abs, dry_run=self.dry_run) except Exception, e: sys.stderr.write("%s\n" % e)
def make_release_tree(self, psBaseDir, plFiles): """Override standard make_release_tree method in order to encrypt .py files found. This method is a rewrite of distutils.command.sdist make_release_tree method but don't create hard link because we don't want do modify source files. ditribute.command.sdist method is not called because it wrap distutils.command.sdist method in order to not create hard link on setup.cfg in order to keep the original unmofieid. Our re-write achieve the same goal. """ self.mkpath(psBaseDir) dir_util.create_tree(psBaseDir, plFiles, dry_run = self.dry_run) loRegex = re.compile(self.DISABLE_ENCRYPT_PATTERN) for lsFile in plFiles: if os.path.isfile(lsFile): lsDst = os.path.abspath(os.path.join(psBaseDir, lsFile)) self.copy_file(lsFile, lsDst) if os.path.splitext(lsFile)[1] in self.ENCRYPT_SUFFIXES: with open(lsFile, "r") as loFd: if loRegex.search(loFd.read()): continue liReturn = subprocess.call([self._getEncryptCommand(), lsDst]) if liReturn != 0: raise IOError("Can't encrypt %s." % lsDst) self.distribution.metadata.write_pkg_info(psBaseDir) self.get_finalized_command('egg_info')\ .save_version_info(os.path.join(psBaseDir, 'setup.cfg'))
def test_create_tree_verbosity(self): create_tree(self.root_target, ['one', 'two', 'three'], verbose=0) self.assertEqual(self._logs, []) remove_tree(self.root_target, verbose=0) wanted = ['creating %s' % self.root_target] create_tree(self.root_target, ['one', 'two', 'three'], verbose=1) self.assertEqual(self._logs, wanted) remove_tree(self.root_target, verbose=0)
def test_create_tree_verbosity(self): create_tree(self.root_target, ["one", "two", "three"], verbose=0) self.assertEquals(self._logs, []) remove_tree(self.root_target, verbose=0) wanted = ["creating %s" % self.root_target] create_tree(self.root_target, ["one", "two", "three"], verbose=1) self.assertEquals(self._logs, wanted) remove_tree(self.root_target, verbose=0)
def copy_new_img(path, new_path): u_path = os.path.join('users', new_path) i_path = os.path.join('images', path) try: remove_tree(u_path) except: pass finally: create_tree(u_path, os.listdir(i_path)) copy_tree(i_path, u_path) return u_path
def createProjectFolder(self): "Create folder structure for current project name and update paths" import distutils.dir_util as du if not self.__folderscreated: self.log.info("Creating project folder") self.__folderscreated = True du.create_tree(self.projName, [self.replPaths + os.sep], verbose=True) T.BROWSER.chdir(self.projName) self.projFilePath = self.projFileName self.write() self.updatePath()
def copy_files_helper(folder_name): src = os.path.join(CURRENT_DIR, os.path.pardir, folder_name) if os.path.exists(src): dst = os.path.join(CURRENT_DIR, 'compile', folder_name) if os.path.exists(dst): if os.path.isdir: # see https://github.com/pypa/distutils/pull/21 remove_tree(dst) else: os.remove(dst) create_tree(src, dst, verbose=0) copy_tree(src, dst, verbose=0) else: raise Exception('Cannot copy {0} folder'.format(src))
def copy_locale_files(): print "*** copying locale files ***" # handle locale files locale_files = [] for source in glob(os.path.join(resources_dir, "locale", "*.mo")): lang = os.path.basename(source)[:-3] dest = os.path.join(locale_temp_dir, lang, "LC_MESSAGES", "miro.mo") locale_files.append((source, dest)) dir_util.create_tree(os.path.dirname(__file__), [dst for src, dst in locale_files]) for source, dest in locale_files: file_util.copy_file(source, dest, update=True, verbose=True)
def run(self): data_dir = os.path.join(self.install_data,'share','amuse') # for the moment add to amuse.. data_dir = os.path.abspath(data_dir) # copy only: # '*.h', '*.a', '*.mod', '*.inc', '*.so', '*.dylib' files=[os.path.join(dp, f) for dp, dn, fn in os.walk(self.lib_dir) for f in fn] ext=['.h', '.a', '.mod', '.inc', '.so', '.dylib'] files=[f for f in files if (os.path.splitext(f)[1] in ext)] files=[os.path.relpath(f,self.lib_dir) for f in files] create_tree(os.path.join(data_dir,'lib'), files) for f in files: src=os.path.join(self.lib_dir,f) target=os.path.join(data_dir,'lib', f) self.copy_file(src,target)
def add(self): if not self.wit_exist: return if self.is_file: path = os.path.split(self.path)[0] else: path = self.path relative_path = os.path.relpath(path, self.wit_location) des = os.path.join(self.staging_area, relative_path) if not self.is_file: if os.path.exists(des): shutil.rmtree(des) copy_tree(path, des) else: create_tree(des, path) shutil.copy2(self.path, des) print("File(s) added successfully")
def make_release_tree(self, base_dir, files): """Create the directory tree that will become the source distribution archive. All directories implied by the filenames in 'files' are created under 'base_dir', and then we hard link or copy (if hard linking is unavailable) those files into place. Essentially, this duplicates the developer's source tree, but in a directory named after the distribution, containing only the files to be distributed. """ # Create all the directories under 'base_dir' necessary to # put 'files' there; the 'mkpath()' is just so we don't die # if the manifest happens to be empty. self.mkpath(base_dir) files_tree_fix = [ f.replace(str(MINIFIED_DIR) + '/', '') for f in files ] dir_util.create_tree(base_dir, files_tree_fix, dry_run=self.dry_run) # And walk over the list of files, either making a hard link (if # os.link exists) to each one that doesn't already exist in its # corresponding location under 'base_dir', or copying each file # that's out-of-date in 'base_dir'. (Usually, all files will be # out-of-date, because by default we blow away 'base_dir' when # we're done making the distribution archives.) if hasattr(os, 'link'): # can make hard links on this system link = 'hard' msg = "making hard links in %s..." % base_dir else: # nope, have to copy link = None msg = "copying files to %s..." % base_dir if not files: log.warn("no files to distribute -- empty manifest?") else: log.info(msg) for file in files: if not os.path.isfile(file): log.warn("'%s' not a regular file -- skipping" % file) else: file_fix = file.replace(str(MINIFIED_DIR) + '/', '') dest = os.path.join(base_dir, file_fix) self.copy_file(file, dest, link=link) self.distribution.metadata.write_pkg_info(base_dir)
def make_release_tree(self, base_dir, files): """Make the release tree.""" self.mkpath(base_dir) create_tree(base_dir, files, dry_run=self.dry_run) if not files: self.log.warning("no files to distribute -- empty manifest?") else: self.log.info("copying files to %s...", base_dir) for filename in files: if not os.path.isfile(filename): self.log.warning("'%s' not a regular file -- skipping", filename) else: dest = os.path.join(base_dir, filename) self.copy_file(filename, dest) self.distribution.metadata.write_pkg_info(base_dir)
def make_release_tree (self, base_dir, files): # Taken from 2.7 version -- but also removes source_dir from dests """Create the directory tree that will become the source distribution archive. All directories implied by the filenames in 'files' are created under 'base_dir', and then we hard link or copy (if hard linking is unavailable) those files into place. Essentially, this duplicates the developer's source tree, but in a directory named after the distribution, containing only the files to be distributed. """ self.run_command('gen_version') source_dir = self.distribution.source_dir # Create all the directories under 'base_dir' necessary to # put 'files' there; the 'mkpath()' is just so we don't die # if the manifest happens to be empty. self.mkpath(base_dir) dir_util.create_tree(base_dir, [relpath(f, source_dir) for f in files], dry_run=self.dry_run) # And walk over the list of files, either making a hard link (if # os.link exists) to each one that doesn't already exist in its # corresponding location under 'base_dir', or copying each file # that's out-of-date in 'base_dir'. (Usually, all files will be # out-of-date, because by default we blow away 'base_dir' when # we're done making the distribution archives.) link = None msg = "copying files to %s..." % base_dir if not files: log.warn("no files to distribute -- empty manifest?") else: log.info(msg) for file in files: if not os.path.isfile(file): log.warn("'%s' not a regular file -- skipping" % file) else: dest = destpath(file, [source_dir]) dest = os.path.join(base_dir, dest) self.copy_file(file, dest, link=link) self.distribution.metadata.write_pkg_info(base_dir)
def make_release_tree(self, base_dir, files): self.mkpath(base_dir) create_tree(base_dir, files, dry_run=self.dry_run) msg = "copying files to %s..." % base_dir if not files: log.warn("no files to distribute -- empty manifest?") else: log.info(msg) for file in files: if not os.path.isfile(file): log.warn("'%s' not a regular file -- skipping" % file) else: dest = os.path.join(base_dir, file) self.copy_file(file, dest) self.copy_extra_files(base_dir) self.distribution.metadata.write_pkg_info(base_dir)
def make_release_tree(self, base_dir, files): self.mkpath(base_dir) dir_util.create_tree(base_dir, files, dry_run=self.dry_run) if hasattr(os, 'link'): link = 'hard' msg = 'making hard links in %s...' % base_dir else: link = None msg = 'copying files to %s...' % base_dir if not files: log.warn('no files to distribute -- empty manifest?') else: log.info(msg) for file in files: if not os.path.isfile(file): log.warn("'%s' not a regular file -- skipping" % file) dest = os.path.join(base_dir, file) self.copy_file(file, dest, link=link) self.distribution.metadata.write_pkg_info(base_dir) return
def run(self): dist_py2exe_path = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "py2exe_builder/dist_py2exe")) # clean destination directory if os.path.isdir(dist_py2exe_path): dir_util.remove_tree(dist_py2exe_path) # build with py2exe py2exe.build_exe.py2exe.run(self) # copy data files src_base = os.path.dirname(__file__) for dst, src_files in py2exe_dataFiles: dst_abs = os.path.normpath(os.path.join(dist_py2exe_path, dst)) for src in src_files: try: src_abs = os.path.normpath(os.path.join(src_base, src)) dir_util.create_tree(dst_abs, src_abs) file_util.copy_file(src_abs, dst_abs, dry_run=self.dry_run) except Exception, e: sys.stderr.write("%s\n" % e)
def make_release_tree(self, base_dir, files): self.mkpath(base_dir) dir_util.create_tree(base_dir, files, verbose=self.verbose, dry_run=self.dry_run) if hasattr(os, "link"): # can make hard links on this system link = "hard" msg = "making hard links in %s..." % base_dir else: # nope, have to copy link = None msg = "copying files to %s..." % base_dir if not files: self.warn("no files to distribute -- empty manifest?") else: self.announce(msg) for file in files: if os.path.isfile(file): dest = os.path.join(base_dir, file) self.copy_file(file, dest, link=link) elif os.path.isdir(file): dir_util.mkpath(os.path.join(base_dir, file)) else: self.warn("'%s' not a regular file or directory -- skipping" % file)
def get_sources_onedal(): from distutils.dir_util import create_tree from distutils.file_util import copy_file cpp_files = glob.glob("onedal/**/**/*.cpp") pyx_files = glob.glob("onedal/**/*.pyx") pxi_files = glob.glob("onedal/**/*.pxi") create_tree('build', pyx_files) for f in pyx_files: copy_file(f, jp('build', f)) main_pyx = 'onedal/onedal.pyx' main_host_pyx = 'build/onedal/onedal_host.pyx' main_dpc_pyx = 'build/onedal/onedal_dpc.pyx' copy_file(main_pyx, main_host_pyx) copy_file(main_pyx, main_dpc_pyx) for f in pxi_files: copy_file(f, jp('build', f)) return cpp_files, main_host_pyx, main_dpc_pyx
def _download_asset(self, destination, asset): if not self.extensionId: log.warning( 'download_asset() cannot download update if the update definition has not been downloaded' ) return destination = os.path.join(destination, self.identity, self.version()) url = self._get_asset_source(asset) if not url: log.warning( 'download_asset() cannot download update as asset url is missing' ) return destfile = os.path.join(destination, f'{asset}') create_tree(os.path.abspath(os.sep), (destfile, )) if not os.path.exists(destfile): log.debug(f'Downloading {self.identity} {asset} to {destfile}') result = self.session.get(url, allow_redirects=True, timeout=vsc.TIMEOUT) with open(destfile, 'wb') as dest: dest.write(result.content)
import distutils.file_util as fu import Biskit as bi import numpy as npy # Check and parse arguments if len(sys.argv) < 5: sys.exit("USAGE: setdirectories.py topologyFile pdbFile mdPath dirName") topFile = os.path.abspath(sys.argv[1]) pdbFile = os.path.abspath(sys.argv[2]) trajPath = os.path.abspath(sys.argv[3]) dirName = sys.argv[4] rootPath = os.path.dirname(sys.argv[0]) + os.sep # Create directory tree and symbolik links du.create_tree(dirName, ['pdbs/', 'sasa/', 'pca/', 'mdpocket/', 'desc/', 'mdmix/']) os.chdir(dirName) os.symlink(trajPath, 'raw_traj') os.symlink(topFile, os.path.splitext(os.path.basename(topFile))[0] + '.top') os.symlink(pdbFile, os.path.basename(pdbFile)) ### Copy scripts of analysis ##fu.copy_file(rootPath+'scripts/runptraj.py','.') ##fu.copy_file(rootPath+'scripts/mdmix_ta.py','mdmix/') ##fu.copy_file(rootPath+'scripts/mdmix_gr.py','mdmix/') ##fu.copy_file(rootPath+'scripts/modules.py','mdmix/') ##fu.copy_file(rootPath+'scripts/mdmix_pscript.pml','mdmix/') ##fu.copy_file(rootPath+'scripts/mdmix_druggability.pl','mdmix/') ##fu.copy_file(rootPath+'scripts/mdmix_druggability_DGgrids.pl','mdmix/') ##fu.copy_file(rootPath+'scripts/PCA_md_trajectories.R','pca/') ##fu.copy_file(rootPath+'scripts/takeBB.py','pca/')
def run(self): name = self.distribution.metadata.name version = self.distribution.metadata.version fullname = "%s-%s" % (name, version) description = self.distribution.metadata.description self.run_command('build') install = self.reinitialize_command('install', reinit_subcommands=1) install.root = self.bdist_dir install.warn_dir = 0 log.info("installing to %s" % self.bdist_dir) self.run_command('install') bin = os.path.join(self.bdist_dir, "usr/bin") create_tree(bin, self.distribution.scripts) for script in self.distribution.scripts: copy_file(script, bin) if not os.path.exists(self.dist_dir): os.mkdir(self.dist_dir) pkg_dir = os.path.join(self.dist_dir, "pkg") if not os.path.exists(pkg_dir): os.mkdir(pkg_dir) pkg = os.path.join(pkg_dir, fullname + ".pkg") if os.path.exists(pkg): remove_tree(pkg) copy_file('README', 'gamera/mac/resources/ReadMe.txt') copy_file('LICENSE', 'gamera/mac/resources/License.txt') import buildpkg import __version__ log.info("Building %s.pkg..." % fullname) pm = buildpkg.PackageMaker(fullname, version, description) pm.build(self.bdist_dir, "gamera/mac/resources", DefaultLocation="/", Relocatable='NO', NeedsAuthorization='YES', UseUserMask='YES', OutputDir=pkg_dir) remove_tree(self.bdist_dir) removals = [os.path.join(self.dist_dir, fullname + ".dmg")] for removal in removals: if os.path.exists(removal): os.remove(removal) dmg_dir = join(self.dist_dir, 'pkg') dmg_dir_gamera = join(dmg_dir, 'Gamera') copy_tree('gamera/mac/gameraclick', join(dmg_dir, 'Gamera')) readmes = ['README', 'readme.txt', 'LICENSE', 'ACKNOWLEDGEMENTS'] for readme in readmes: if os.path.exists(readme): copy_file(readme, dmg_dir_gamera) # dmg background image copy_tree('gamera/mac/dmg_images', join(dmg_dir, '.images')) # wxPython link copy_file('gamera/mac/wxPython.html', join(dmg_dir, 'wxPython Build on Sourceforge.html')) imagename = "%s.osx.dmg" % fullname if self.nightly: d = datetime.date.today() monthstring = str(d.month) daystring = str(d.day) if d.month < 10: monthstring = '0' + monthstring if d.day < 10: daystring = '0' + daystring imagename = "gamera-2-nightly-%s%s%s.osx.dmg" % ( d.year, monthstring, daystring) log.info("Making %s..." % imagename) # Make a read/write DMG output = run_command_at(self.dist_dir, "hdiutil", "create", "-format", "UDRW", "-fs", "HFS+", "-volname", "Gamera", "-srcfolder", "pkg", "temp.dmg") # Mount it output = run_command_at(self.dist_dir, "hdiutil", "mount", "temp.dmg") # Change the DS Store so the background image and icon sizes will be fixed copy_file('gamera/mac/dmg_ds_store', join('/Volumes', 'Gamera', '.DS_Store')) # Unmount it output = run_command("hdiutil unmount /Volumes/Gamera") # Make it read only output = run_command_at(self.dist_dir, "hdiutil", "convert", "-format", "UDRO", "-o", imagename, "temp.dmg") # Internet Enable it (why I can do this read only, but I can't do the background, I dunno) output = run_command_at(self.dist_dir, "hdiutil internet-enable -no", imagename) # Delete the temporary image os.remove(join(self.dist_dir, "temp.dmg")) remove_tree(pkg_dir)
#!/usr/bin/env python """Distutils setup file, used to install or test 'setuptools'""" import sys import os src_root = None if sys.version_info >= (3, ): tmp_src = os.path.join("build", "src") from distutils.filelist import FileList from distutils import dir_util, file_util, util, log log.set_verbosity(1) fl = FileList() for line in open("MANIFEST.in"): fl.process_template_line(line) dir_util.create_tree(tmp_src, fl.files) outfiles_2to3 = [] dist_script = os.path.join("build", "src", "distribute_setup.py") for f in fl.files: outf, copied = file_util.copy_file(f, os.path.join(tmp_src, f), update=1) if copied and outf.endswith(".py") and outf != dist_script: outfiles_2to3.append(outf) if copied and outf.endswith('api_tests.txt'): # XXX support this in distutils as well from lib2to3.main import main main( 'lib2to3.fixes', ['-wd', os.path.join(tmp_src, 'tests', 'api_tests.txt')]) util.run_2to3(outfiles_2to3)
def createFolder(self, where=False, fixtop=True, **kwargs): """ Create directory tree for current replica. :attr:`path` should have been set with :meth:`setPath`. Copy inside the :attr:`top`, :attr:`crd` files if given or generate them from a object file :attr:`off`. Create also replica pickle file. :arg str where: Path where folder structure should be created. If **None**, use current folder. Path must exist. :arg bool fixtop: When saving amber parm7 topology file, remove SCEE and SCNB sections from it. When loading some solvent boxes that include tailored parameters in new Amber programs (> 9.0), they may make the program crash because no SCNB and SCEE scaling factors were specifically given. If the sections are removed, they all take default values. Tree structure :: replica.name/ replica.top # will be copied if existent or created from off if given replica.crd # will be copied if existent replica.pdb # will be copied if existent replica.name.mrepl replica.minfolder/ replica.eqfolder/ replica.mdfolder/ """ if not self.name: raise ReplicaError, "Unnamed replica folder can not be created." if self.system and self.eqfolder and self.mdfolder: import distutils.dir_util as du import shutil self.log.info("Creating folder structure for replica %s" % self.name) pwd = T.BROWSER.cwd if where and osp.exists(where): where = osp.abspath(where) else: where = T.BROWSER.getcwd() T.BROWSER.chdir(where) du.create_tree(self.name, [ self.minfolder + os.sep, self.eqfolder + os.sep, self.mdfolder + os.sep ], verbose=True) # Save top, crd and pdb files for system in current created folder basenames = '{0}_{1}'.format(self.system.name, self.name) topcrdok = self.system.saveTopCrd(osp.join(self.name, basenames)) pdbok = self.system.savePDB(osp.join(self.name, basenames + '.pdb')) if topcrdok and pdbok: self.top = basenames + '.prmtop' self.crd = basenames + '.prmcrd' self.pdb = basenames + '.pdb' else: raise ReplicaError, "Error saving system top, crd or pdb files" # update replica path and save replica file T.BROWSER.chdir(self.name) self.setPath(T.BROWSER.getcwd()) self.__folderscreated = True # If fixtop, will remove SCEE and SCNB entries from topology file # Needed for some boxes if fixtop: self.__fixTopology(self.top) # Save reference pdb from pdb refpdb = self.system.ref self.ref = basenames + '_ref.pdb' refpdb.writePdb(self.ref) self.log.debug("Created replica: %s" % str(self)) self.write() # write project file T.BROWSER.chdir(pwd) # self.log.info("Created folder structure for replica %s"%self.name) else: raise ReplicaError, "Folder names or replica name not set. Cannot create folders."
"""distutils.command.sdist
if sys.version_info >= (3, ): print( "Using 2to3 to translate Python2-only idioms into Python3 code. Please wait..." ) # Python 3 and we need to translate code package_prefix = os.path.join('build', 'python3_rpy') from distutils import filelist, dir_util, file_util, util #, log #log.set_verbosity(1) fl = filelist.FileList() tmp = open("MANIFEST.in") for line in tmp: line = line.rstrip() if line != '': fl.process_template_line(line) tmp.close() dir_util.create_tree(package_prefix, fl.files) outfiles_2to3 = [] #dist_script = os.path.join("build", "src", "distribute_setup.py") for f in fl.files: outf, copied = file_util.copy_file(f, os.path.join(package_prefix, f), update=1) if copied and outf.endswith(".py"): #and outf != dist_script: outfiles_2to3.append(outf) if copied and outf.endswith('api_tests.txt'): # XXX support this in distutils as well from lib2to3.main import main main('lib2to3.fixes', [ '-wd', os.path.join(package_prefix, 'tests', 'api_tests.txt') ])
package_prefix='.' if sys.version_info >= (3,): print("Using 2to3 to translate Python2-only idioms into Python3 code. Please wait...") # Python 3 and we need to translate code package_prefix = os.path.join('build', 'python3_rpy') from distutils import filelist, dir_util, file_util, util#, log #log.set_verbosity(1) fl = filelist.FileList() tmp = open("MANIFEST.in") for line in tmp: line = line.rstrip() if line != '': fl.process_template_line(line) tmp.close() dir_util.create_tree(package_prefix, fl.files) outfiles_2to3 = [] #dist_script = os.path.join("build", "src", "distribute_setup.py") for f in fl.files: outf, copied = file_util.copy_file(f, os.path.join(package_prefix, f), update=1) if copied and outf.endswith(".py"): #and outf != dist_script: outfiles_2to3.append(outf) if copied and outf.endswith('api_tests.txt'): # XXX support this in distutils as well from lib2to3.main import main main('lib2to3.fixes', ['-wd', os.path.join(package_prefix, 'tests', 'api_tests.txt')]) util.run_2to3(outfiles_2to3)
def run (self): name = self.distribution.metadata.name version = self.distribution.metadata.version fullname = "%s-%s" % (name, version) description = self.distribution.metadata.description self.run_command('build') install = self.reinitialize_command('install', reinit_subcommands=1) install.root = self.bdist_dir install.warn_dir = 0 log.info("installing to %s" % self.bdist_dir) self.run_command('install') bin = os.path.join(self.bdist_dir, "usr/bin") create_tree(bin, self.distribution.scripts) for script in self.distribution.scripts: copy_file(script, bin) if not os.path.exists(self.dist_dir): os.mkdir(self.dist_dir) pkg_dir = os.path.join(self.dist_dir, "pkg") if not os.path.exists(pkg_dir): os.mkdir(pkg_dir) pkg = os.path.join(pkg_dir, fullname + ".pkg") if os.path.exists(pkg): remove_tree(pkg) copy_file('README', 'gamera/mac/resources/ReadMe.txt') copy_file('LICENSE', 'gamera/mac/resources/License.txt') import buildpkg import __version__ log.info("Building %s.pkg..." % fullname) pm = buildpkg.PackageMaker(fullname, version, description) pm.build(self.bdist_dir, "gamera/mac/resources", DefaultLocation="/", Relocatable='NO', NeedsAuthorization='YES', UseUserMask='YES', OutputDir=pkg_dir) remove_tree(self.bdist_dir) removals = [os.path.join(self.dist_dir, fullname + ".dmg")] for removal in removals: if os.path.exists(removal): os.remove(removal) dmg_dir = join(self.dist_dir, 'pkg') dmg_dir_gamera = join(dmg_dir, 'Gamera') copy_tree('gamera/mac/gameraclick', join(dmg_dir, 'Gamera')) readmes = ['README', 'readme.txt', 'LICENSE', 'ACKNOWLEDGEMENTS'] for readme in readmes: if os.path.exists(readme): copy_file(readme, dmg_dir_gamera) # dmg background image copy_tree('gamera/mac/dmg_images', join(dmg_dir, '.images')) # wxPython link copy_file('gamera/mac/wxPython.html', join(dmg_dir, 'wxPython Build on Sourceforge.html')) imagename = "%s.osx.dmg" % fullname if self.nightly: d = datetime.date.today() monthstring = str(d.month) daystring = str(d.day) if d.month < 10: monthstring = '0' + monthstring if d.day < 10: daystring = '0' + daystring imagename = "gamera-2-nightly-%s%s%s.osx.dmg" % (d.year,monthstring,daystring) log.info("Making %s..." % imagename) # Make a read/write DMG output = run_command_at(self.dist_dir, "hdiutil", "create", "-format", "UDRW", "-fs", "HFS+", "-volname", "Gamera", "-srcfolder", "pkg", "temp.dmg") # Mount it output = run_command_at(self.dist_dir, "hdiutil", "mount", "temp.dmg") # Change the DS Store so the background image and icon sizes will be fixed copy_file('gamera/mac/dmg_ds_store', join('/Volumes', 'Gamera', '.DS_Store')) # Unmount it output = run_command("hdiutil unmount /Volumes/Gamera") # Make it read only output = run_command_at(self.dist_dir, "hdiutil", "convert", "-format", "UDRO", "-o", imagename, "temp.dmg") # Internet Enable it (why I can do this read only, but I can't do the background, I dunno) output = run_command_at(self.dist_dir, "hdiutil internet-enable -no", imagename) # Delete the temporary image os.remove(join(self.dist_dir, "temp.dmg")) remove_tree(pkg_dir)
# Allow to run setup.py from another directory. os.chdir(os.path.dirname(os.path.abspath(__file__))) src_root = None if sys.version_info >= (3,): tmp_src = os.path.join("build", "src") from distutils.filelist import FileList from distutils import dir_util, file_util, util, log log.set_verbosity(1) fl = FileList() manifest_file = open("MANIFEST.in") for line in manifest_file: fl.process_template_line(line) manifest_file.close() dir_util.create_tree(tmp_src, fl.files) outfiles_2to3 = [] dist_script = os.path.join("build", "src", "ez_setup.py") for f in fl.files: outf, copied = file_util.copy_file(f, os.path.join(tmp_src, f), update=1) if copied and outf.endswith(".py") and outf != dist_script: outfiles_2to3.append(outf) if copied and outf.endswith('api_tests.txt'): # XXX support this in distutils as well from lib2to3.main import main main('lib2to3.fixes', ['-wd', os.path.join(tmp_src, 'tests', 'api_tests.txt')]) util.run_2to3(outfiles_2to3) # arrange setup to use the copy sys.path.insert(0, os.path.abspath(tmp_src))