def run(self): """Execute install command""" subprocess.check_call(['make', '-C', 'doc']) install_data.run(self) # Old style base class # Create empty directories for directory in DIRECTORIES_TO_CREATE: if self.root: directory = change_root(self.root, directory) if not os.path.exists(directory): log.info("creating directory '%s'", directory) os.makedirs(directory) # Recursively overwrite directories for target, source in DIRECTORIES_TO_COPY: if self.root: target = change_root(self.root, target) if os.path.exists(target): remove_tree(target) log.info("recursive copy '%s' to '%s'", source, target) shutil.copytree(source, target, symlinks=True)
def run(self): # install into hicolor icon theme basepath = os.path.join(self.prefix, 'share', 'icons', 'hicolor') if self.root is not None: basepath = change_root(self.root, basepath) local = os.path.join("quodlibet", "images", "hicolor") scalable = os.path.join(local, "scalable", "apps") scalable_dst = os.path.join(basepath, "scalable", "apps") self.copy_tree(scalable, scalable_dst) png = os.path.join(local, "64x64", "apps") png_dst = os.path.join(basepath, "64x64", "apps") self.copy_tree(png, png_dst) # this fails during packaging.. so ignore the outcome subprocess.call(['gtk-update-icon-cache', basepath]) # install png versions to /usr/share/pixmaps basepath = os.path.join(self.prefix, 'share', 'pixmaps') if self.root is not None: basepath = change_root(self.root, basepath) self.copy_tree(png, basepath)
def install_app_config(self): source = os.path.join(resource_dir, 'app.config.template') dest = '/boot/system/non-packaged/data/miro/resources/app.config' from miro import buildutils config_file = buildutils.read_simple_config_file(source) print "Trying to figure out the git revision...." if config_file["appVersion"].endswith("git"): revision = buildutils.query_revision() if revision is None: revision = "unknown" revisionurl = "unknown" revisionnum = "unknown" else: revisionurl = revision[0] revisionnum = revision[1] revision = "%s - %s" % (revisionurl, revisionnum) else: revisionurl = "" revisionnum = "" revision = "" print "Using %s" % revisionnum if self.root: dest = change_root(self.root, dest) self.mkpath(os.path.dirname(dest)) # We don't use the dist utils copy_file() because it only copies # the file if the timestamp is newer shutil.copyfile(source, dest) expand_file_contents(dest, APP_REVISION=revision, APP_REVISION_NUM=revisionnum, APP_REVISION_URL=revisionurl, APP_PLATFORM='haiku', BUILD_MACHINE="%s@%s" % (getlogin(), os.uname()[1]), BUILD_TIME=str(time.time()), MOZILLA_LIB_PATH="") self.outfiles.append(dest) locale_dir = os.path.join(resource_dir, "locale") for source in glob(os.path.join(locale_dir, "*.mo")): lang = os.path.basename(source)[:-3] if 'LINGUAS' in os.environ and lang not in os.environ['LINGUAS']: continue dest = '/boot/system/non-packaged/data/locale/%s/LC_MESSAGES/miro.mo' % lang if self.root: dest = change_root(self.root, dest) self.mkpath(os.path.dirname(dest)) self.copy_file(source, dest) self.outfiles.append(dest)
def run(self): # If we are just doing an update, pass this if is_update: return #log.warn('>>> %s', self.lib) log.warn('>>> %s', self.etc_path) if not self.skip_build: self.run_command('build_config') etc_path = self.etc_path if self.root: etc_path = change_root(self.root, self.etc_path) self.outfiles = self.copy_tree(self.build_dir, etc_path) # if root is set, it's for pacakge, so NO chown if pwd and not self.root: # assume a posix system uid = self.get_uid(self.owner) gid = self.get_gid(self.group) for file in self.get_outputs(): log.info("Changing owner of %s to %s:%s", file, self.owner, self.group) if not self.dry_run: os.chown(file, uid, gid) # recursivly changing permissions for etc/shinken and var/lib/shinken self.recursive_chown(self.etc_path, uid, gid, self.owner, self.group) self.recursive_chown(self.var_path, uid, gid, self.owner, self.group) self.recursive_chown(self.run_path, uid, gid, self.owner, self.group) self.recursive_chown(self.log_path, uid, gid, self.owner, self.group)
def run(self): if not os.path.exists(self.install_dir): self.outfiles.extend(self.mkpath(self.install_dir)) for item in self.appdata: if isinstance(item, basestring): # put it right into the installation directory if os.path.isfile(item): (f, copied) = self.copy_file(item, self.install_dir) self.outfiles.append(f) elif os.path.isdir(item): target = os.path.join(self.install_dir, item) files = self.copy_tree(item, target) self.outfiles.extend(files) else: self.warn('Unable to find %s...' % item) else: # assume we have a tupel-like thing here. target directory # relative to install_dir is in first element target_dir = item[0] if self.root: target_dir = util.change_root(self.root, target_dir) else: target_dir = os.path.join(self.install_dir, target_dir) for fso in item[1]: if os.path.isdir(fso): files = self.copy_tree(fso, target_dir) self.outfiles.extend(files) elif os.path.isfile(fso): (f, copied) = self.copy_file(fso, target_dir) self.outfiles.append(f) else: self.warn('Unable to find %s...' % fso)
def run(self): self.mkpath(self.install_dir) for f in self.data_files: if isinstance(f, str): # it's a simple file, so copy it f = convert_path(f) if self.warn_dir: self.warn("setup script did not provide a directory for " "'%s' -- installing right in '%s'" % (f, self.install_dir)) (out, _) = self.copy_file(f, self.install_dir) self.outfiles.append(out) else: # it's a tuple with path to install to and a list of files dir = convert_path(f[0]) 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 f[1] == []: # If there are no files listed, the user must be # trying to create an empty directory, so add the # directory to the list of output files. self.outfiles.append(dir) else: # Copy files, adding them to the list of output files. for data in f[1]: data = convert_path(data) (out, _) = self.copy_file(data, dir) self.outfiles.append(out)
def run(self): """ This is where the meat is. Basically the data_files list must now be a list of tuples of 3 entries. The first entry is one of 'base', 'platbase', etc, which indicates which base to install from. The second entry is the path to install too. The third entry is a list of files to install. """ for lof in self.data_files: if lof[0]: base = getattr(self, 'install_' + lof[0]) else: base = getattr(self, 'install_base') dir = convert_path(lof[1]) if not os.path.isabs(dir): dir = os.path.join(base, dir) elif self.root: dir = change_root(self.root, dir) self.mkpath(dir) files = lof[2] if len(files) == 0: # If there are no files listed, the user must be # trying to create an empty directory, so add the the # directory to the list of output files. self.outfiles.append(dir) else: # Copy files, adding them to the list of output files. for f in files: f = convert_path(f) (out, _) = self.copy_file(f, dir) # print "DEBUG: ", out # dbg self.outfiles.append(out) return self.outfiles
def run(self): if not self.skip_build: self.run_command("build_scripts") for script in self.distribution.scripts: if isinstance(script, str): fn = os.path.join(self.build_dir, os.path.basename(convert_path(script))) out, _ = self.copy_file(fn, self.install_dir) self.outfiles.append(out) else: dn = convert_path(script[0]) if not os.path.isabs(dn): dn = os.path.join(self.install_dir, dn) elif self.root: dn = change_root(self.root, dn) self.mkpath(dn) if not script[1]: self.outfiles.append(dn) else: for s in script[1]: fn = os.path.join(self.build_dir, os.path.basename(convert_path(s))) out, _ = self.copy_file(fn, dn) self.outfiles.append(out) if os.name == "posix": for fn in self.get_outputs(): mode = S_IMODE(os.stat(fn).st_mode) | 0555 log.info("changing mode of %s to %o", fn, mode) if not self.dry_run: os.chmod(fn, mode)
def run(self): # install_data is a classic class so super() won't work. Call it # directly to copy the files first. _install_data.run(self) # Now gzip them for f in self.data_files: if type(f) is StringType: # it's a simple file f = convert_path(f) cmd = '/bin/gzip %s/%s' % (self.install_dir, f) log.info("gzipping %s/%s" % (self.install_dir, f)) os.system(cmd) else: # it's a tuple with path and a list of files dir = convert_path(f[0]) if not os.path.isabs(dir): dir = os.path.join(self.install_dir, dir) elif self.root: dir = change_root(self.root, dir) if f[1] == []: # If there are no files listed the user must be # trying to create an empty directory. So nothing # to do here. pass else: # gzip the files for data in f[1]: data = convert_path(data) cmd = '/bin/gzip %s/%s' % (dir, data) log.info("gzipping %s/%s" % (dir, data)) os.system(cmd)
def run(self): # Before importing markdown, tweak sys.path to import from the # build directory (2to3 might have run on the library). bld_cmd = self.get_finalized_command("build") sys.path.insert(0, bld_cmd.build_lib) try: import markdown except ImportError: print ('skipping build_docs: Markdown "import" failed!') else: template = codecs.open('docs/_template.html', encoding='utf-8').read() md = markdown.Markdown(extensions=['extra', 'toc']) menu = md.convert(self.sitemap) md.reset() for infile, title in self.docs: outfile, ext = os.path.splitext(infile) if ext == '.txt': outfile += '.html' outfile = change_root(self.build_base, outfile) self.mkpath(os.path.split(outfile)[0]) if self.force or newer(infile, outfile): if self.verbose: print ('Converting %s -> %s' % (infile, outfile)) if not self.dry_run: src = codecs.open(infile, encoding='utf-8').read() out = template % { 'title': title, 'body' : md.convert(src), 'toc' : md.toc, } md.reset() doc = open(outfile, 'wb') doc.write(out.encode('utf-8')) doc.close()
def run(self): self.mkpath(self.install_dir) for f in self.data_files: # it's a tuple with dict to install to and a list of files tdict = f[0] dir = convert_path(tdict['path']) 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) os.chmod(dir, tdict['mode']) if(os.geteuid() == 0): try: uinfo = pwd.getpwnam(tdict['owner']) except KeyError: print "Error: Unkown user %s" % tdict['owner'] sys.exit(1) uid, gid = uinfo[2], uinfo[3] os.chown(dir, uid, gid) if f[1] == []: # If there are no files listed, the user must be # trying to create an empty directory, so add the # directory to the list of output files. self.outfiles.append(dir) else: # Copy files, adding them to the list of output files. for data, mode in f[1]: data = convert_path(data) (out, _) = self.copy_file(data, dir) self.outfiles.append(out) os.chmod(out, mode) if(os.geteuid() == 0): os.chown(out, uid, gid) self.run_command('install_locales')
def run(self): for f in self.data_files: if isinstance(f, str): # don't copy files without path information pass else: # it's a tuple with path to install to and a list of files dir = convert_path(f[0]) 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 f[1] == []: # If there are no files listed, the user must be # trying to create an empty directory, so add the # directory to the list of output files. self.outfiles.append(dir) else: # Copy files, adding them to the list of output files. for data in f[1]: data = convert_path(data) (out, _) = self.copy_file(data, dir) self.outfiles.append(out) for scriptname in scripts.keys(): pathname = scripts[scriptname]['dest'] dir = convert_path(pathname) dir = os.path.dirname(dir) dir = change_root(self.root, dir) self.mkpath(dir) data = os.path.join('dist', scriptname) (out, _) = self.copy_file(data, dir, preserve_mode=True) self.outfiles.append(out) if self.record: outputs = self.get_outputs() if self.root: # strip any package prefix root_len = len(self.root) for counter in xrange(len(outputs)): outputs[counter] = outputs[counter][root_len:] self.execute(write_file, (self.record, outputs), "writing list of installed files to '%s'" % self.record)
def run(self): # Before importing markdown, tweak sys.path to import from the # build directory (2to3 might have run on the library). bld_cmd = self.get_finalized_command("build") sys.path.insert(0, bld_cmd.build_lib) try: import markdown except ImportError: print('skipping build_docs: Markdown "import" failed!') else: with codecs.open('docs/_template.html', encoding='utf-8') as f: template = f.read() self.md = markdown.Markdown( extensions=[ 'extra', 'toc(permalink=true)', 'meta', 'admonition', 'smarty' ] ) for infile in self.docs: outfile, ext = os.path.splitext(infile) if ext == '.txt': # Copy src to .txt file srcfile = outfile + '.txt' srcfile = change_root(self.build_base, srcfile) self.mkpath(os.path.split(srcfile)[0]) self.copy_file(infile, srcfile) # Render html file outfile += '.html' outfile = change_root(self.build_base, outfile) self.mkpath(os.path.split(outfile)[0]) if self.force or newer(infile, outfile): if self.verbose: print('Converting %s -> %s' % (infile, outfile)) if not self.dry_run: with codecs.open(infile, encoding='utf-8') as f: src = f.read() out = template % self._get_context(src, outfile) doc = open(outfile, 'wb') doc.write(out.encode('utf-8')) doc.close() else: outfile = change_root(self.build_base, infile) self.mkpath(os.path.split(outfile)[0]) self.copy_file(infile, outfile)
def finalize_options(self): self.set_undefined_options('install', ('root', 'root')) self.set_undefined_options('build', ('build_base', 'build_base')) if self.docdir is None: self.docdir = change_root(self.build_base, 'doc')
def run(self): if not self.skip_build: self.run_command("build_mo") src = os.path.join(self.build_base, "share", "locale") dest = os.path.join(self.install_base, "share", "locale") if self.root != None: dest = change_root(self.root, dest) self.copy_tree(src, dest)
def run(self): prog = find_executable('epydoc') pkg_dirs = [change_root(self.build_lib, pkg) for pkg in self.distribution.packages] cmd = [prog, '-v', '--%s' % self.action, '--docformat', 'restructuredtext', '-o', self.docdir] #if self.verbose: cmd.append('-v') cmd.extend(pkg_dirs) self.mkpath(self.docdir) spawn(cmd)
def run(self): if not self.skip_build: self.run_command('build_mo') src = os.path.join(self.build_base, "share", "locale") dest = os.path.join(self.install_base, "share", "locale") if self.root is not None: dest = change_root(self.root, dest) out = self.copy_tree(src, dest) self.outfiles.extend(out)
def run(self): if not self.skip_build: self.run_command('build_doc') dst_root = change_root(self.root, self.docdir) self.copy_transformed_tree(doc_manifest, dst_root=dst_root, substitutions={'docdir' : self.docdir})
def run(self): self.finalize_options() self.ensure_finalized() print "Running Installer" instloc = self.install_doc if self.root: instloc = change_root(self.root, instloc) self.mkpath(instloc) copy_tree(self.build_dest, instloc) print "Installation complete"
def test_change_root(self): # linux/mac os.name = "posix" def _isabs(path): return path[0] == "/" os.path.isabs = _isabs def _join(*path): return "/".join(path) os.path.join = _join self.assertEqual(change_root("/root", "/old/its/here"), "/root/old/its/here") self.assertEqual(change_root("/root", "its/here"), "/root/its/here") # windows os.name = "nt" def _isabs(path): return path.startswith("c:\\") os.path.isabs = _isabs def _splitdrive(path): if path.startswith("c:"): return ("", path.replace("c:", "")) return ("", path) os.path.splitdrive = _splitdrive def _join(*path): return "\\".join(path) os.path.join = _join self.assertEqual(change_root("c:\\root", "c:\\old\\its\\here"), "c:\\root\\old\\its\\here") self.assertEqual(change_root("c:\\root", "its\\here"), "c:\\root\\its\\here") # BugsBunny os (it's a great os) os.name = "BugsBunny" self.assertRaises(DistutilsPlatformError, change_root, "c:\\root", "its\\here")
def run(self): basepath = os.path.join(self.prefix, "share", "man") if self.root != None: basepath = change_root(self.root, basepath) self.mkpath(basepath) for man_page in self.man_pages: manpath = os.path.join(basepath, "man" + man_page[-1]) self.mkpath(manpath) fullpath = os.path.join(manpath, os.path.basename(man_page)) self.copy_file(man_page, fullpath)
def run(self): basepath = os.path.join( self.prefix, 'share', 'gnome-shell', 'search-providers') if self.root is not None: basepath = change_root(self.root, basepath) out = self.mkpath(basepath) self.outfiles.extend(out or []) (out, _) = self.copy_file(self.search_provider, basepath) self.outfiles.append(out)
def finalize_options(self): self.set_undefined_options('install', ('root', 'root'), (self.var_name, 'install_dir')) install_scripts.finalize_options(self) self.build_dir = os.path.join(self.build_dir, self.dir_name) # prepend root if self.root is not None: self.install_dir = change_root(self.root, self.install_dir)
def finalize_options(self): self.set_undefined_options("build_locale", ("build_dir", "build_dir")) self.set_undefined_options("install", ("skip_build", "skip_build")) if self.install_dir is None: self.set_undefined_options("install", ("root", "root")) self.set_undefined_options("install", ("prefix", "prefix")) prefix = self.prefix if self.root is not None: prefix = change_root(self.root, prefix) self.install_dir = os.path.join(prefix, "share", "locale")
def finalize_options(self): """Finalize options""" self.set_undefined_options('install', ('root', 'root'), ) if not self.prefix: self.prefix = '/usr/share/man' if self.root: self.prefix = change_root(self.root, self.prefix)
def run(self): if not self.skip_build: self.run_command('build_man') srcdir = os.path.join(self.build_base, 'man') mandir = os.path.join(self.install_base, self.manprefix, 'man1') if self.root is not None: mandir = change_root(self.root, mandir) self.mkpath(mandir) self.copy_tree(srcdir, mandir)
def test_install_package_with_root(script, data): """ Test installing a package using pip install --root """ root_dir = script.scratch_path/'root' result = script.pip('install', '--root', root_dir, '-f', data.find_links, '--no-index', 'simple==1.0') normal_install_path = script.base_path / script.site_packages / 'simple-1.0-py%s.egg-info' % pyversion #use distutils to change the root exactly how the --root option does it from distutils.util import change_root root_path = change_root(os.path.join(script.scratch, 'root'), normal_install_path) assert root_path in result.files_created, str(result)
def run(self): if not self.skip_build: self.run_command('build_shortcuts') basepath = os.path.join(self.prefix, 'share', 'applications') if self.root != None: basepath = change_root(self.root, basepath) srcpath = os.path.join(self.build_base, 'share', 'applications') self.mkpath(basepath) for shortcut in self.shortcuts: fullsrc = os.path.join(srcpath, shortcut) fullpath = os.path.join(basepath, shortcut) self.copy_file(fullsrc, fullpath)
def test_install_package_with_root(): """ Test installing a package using pip install --root """ env = reset_env() root_dir = env.scratch_path/'root' find_links = path_to_url(os.path.join(here, 'packages')) result = run_pip('install', '--root', root_dir, '-f', find_links, '--no-index', 'simple==1.0') normal_install_path = env.root_path / env.site_packages / 'simple-1.0-py%s.egg-info' % pyversion #use distutils to change the root exactly how the --root option does it from distutils.util import change_root root_path = change_root(os.path.join(env.scratch, 'root'), normal_install_path) assert root_path in result.files_created, str(result)
def finalize_options(self): self.set_undefined_options('build', ('build_base', 'build_base'), ('build_lib', 'build_lib')) if self.action is None: self.action = 'html' if self.docdir is None: if self.action == 'html': self.docdir = change_root(self.get_finalized_command('build_doc').docdir, 'html') else: self.docdir = self.get_finalized_command('build_doc').docdir
def finalize_options(self): # This method (and its pliant slaves, like 'finalize_unix()', # 'finalize_other()', and 'select_scheme()') is where the default # installation directories for modules, extension modules, and # anything else we care to install from a Python module # distribution. Thus, this code makes a pretty important policy # statement about how third-party stuff is added to a Python # installation! Note that the actual work of installation is done # by the relatively simple 'install_*' commands; they just take # their orders from the installation directory options determined # here. # Check for errors/inconsistencies in the options; first, stuff # that's wrong on any platform. if ((self.prefix or self.exec_prefix or self.home) and (self.install_base or self.install_platbase)): raise DistutilsOptionError, \ ("must supply either prefix/exec-prefix/home or " + "install-base/install-platbase -- not both") # Next, stuff that's wrong (or dubious) only on certain platforms. if os.name == 'posix': if self.home and (self.prefix or self.exec_prefix): raise DistutilsOptionError, \ ("must supply either home or prefix/exec-prefix -- " + "not both") else: if self.exec_prefix: self.warn("exec-prefix option ignored on this platform") self.exec_prefix = None if self.home: self.warn("home option ignored on this platform") self.home = None # Now the interesting logic -- so interesting that we farm it out # to other methods. The goal of these methods is to set the final # values for the install_{lib,scripts,data,...} options, using as # input a heady brew of prefix, exec_prefix, home, install_base, # install_platbase, user-supplied versions of # install_{purelib,platlib,lib,scripts,data,...}, and the # INSTALL_SCHEME dictionary above. Phew! self.dump_dirs("pre-finalize_{unix,other}") if os.name == 'posix': self.finalize_unix() else: self.finalize_other() self.dump_dirs("post-finalize_{unix,other}()") # Expand configuration variables, tilde, etc. in self.install_base # and self.install_platbase -- that way, we can use $base or # $platbase in the other installation directories and not worry # about needing recursive variable expansion (shudder). py_version = (string.split(sys.version))[0] self.config_vars = { 'dist_name': self.distribution.get_name(), 'dist_version': self.distribution.get_version(), 'dist_fullname': self.distribution.get_fullname(), 'py_version': py_version, 'py_version_short': py_version[0:3], 'sys_prefix': sysconfig.PREFIX, 'sys_exec_prefix': sysconfig.EXEC_PREFIX, } self.expand_basedirs() self.dump_dirs("post-expand_basedirs()") # Now define config vars for the base directories so we can expand # everything else. self.config_vars['base'] = self.install_base self.config_vars['platbase'] = self.install_platbase if DEBUG: from pprint import pprint print "config vars:" pprint(self.config_vars) # Expand "~" and configuration variables in the installation # directories. self.expand_dirs() self.dump_dirs("post-expand_dirs()") # Pick the actual directory to install all modules to: either # install_purelib or install_platlib, depending on whether this # module distribution is pure or not. Of course, if the user # already specified install_lib, use their selection. if self.install_lib is None: if self.distribution.ext_modules: # has extensions: non-pure self.install_lib = self.install_platlib else: self.install_lib = self.install_purelib # Well, we're not actually fully completely finalized yet: we still # have to deal with 'extra_path', which is the hack for allowing # non-packagized module distributions (hello, Numerical Python!) to # get their own directories. self.handle_extra_path() self.install_libbase = self.install_lib # needed for .pth file self.install_lib = os.path.join(self.install_lib, self.extra_dirs) # If a new root directory was supplied, make all the installation # dirs relative to it. if self.root is not None: for name in ('libbase', 'lib', 'purelib', 'platlib', 'scripts', 'data', 'headers'): attr = "install_" + name new_val = change_root(self.root, getattr(self, attr)) setattr(self, attr, new_val) self.dump_dirs("after prepending root") # Find out the build directories, ie. where to install from. self.set_undefined_options('build', ('build_base', 'build_base'), ('build_lib', 'build_lib'))
def finalize_options(self): install.finalize_options(self) if self.pymol_path is None: self.pymol_path = os.path.join(self.install_libbase, 'pymol', 'pymol_path') elif self.root is not None: self.pymol_path = change_root(self.root, self.pymol_path)
def change_roots(self, *names): """Change the install directories pointed by name using root.""" for name in names: attr = "install_" + name setattr(self, attr, change_root(self.root, getattr(self, attr)))
def prepend_root(path: str) -> str: if root is None or not os.path.isabs(path): return path else: return change_root(root, path)
def change_roots(self, *names): for name in names: attr = "install_" + name setattr(self, attr, change_root(self.root, getattr(self, attr)))