def rc_update (self, clobberSwitch=False) : """effects: do our part of rc update""" if not os.path.isdir (self.dir()) : return svninfo = SvnInfoSvn (None, self.dir()) self = self.useSvnuser (svninfo.svnuser()) self = self.resolveTags () if self.tag() != svninfo.tag() : cmd = ["svn", "switch", self.m_url] if not clobberSwitch : status = "\n" + self.svn_status() if status.find ("\nM") != -1 or status.find ("\nC") != -1: print "you currently have changes in package " + self.name() print "either check them in, or switch versions manually using:" print " cd " + self.dir() print " " + " ".join(cmd) #print " " + string.join (cmd, " ") return pass print "switching " + self.name() + " to " + self.tag() shell_exec (cmd, workDir=self.dir(), retries=2, noReturn=True) return if os.path.basename (os.path.dirname (self.m_url)) == "tags" : print "package " + self.name() + " already at version " + self.tag() return print "updating " + svninfo.name() + " from head" shell_exec (["svn", "update"], workDir=self.dir(), retries=2, noReturn=True) return
def format_partition(self, partition): device = partition['device'] fs_type = partition['fs_type'] if not fs_type: msg = _("Error formatting partition {0}:\n" "It has no file system type.".format(device)) self.queue.put([1, 110, None, None, msg]) return False # Build format command if fs_type == "swap": cmd = "mkswap %s" % device elif fs_type[:3] == 'ext': cmd = "mkfs.%s -F -q %s" % (fs_type, device) elif fs_type == "jfs": cmd = "mkfs.%s -q %s" % (fs_type, device) elif fs_type == "xfs": cmd = "mkfs.%s -f %s" % (fs_type, device) elif fs_type == "vfat": cmd = "mkfs.%s %s -F 32" % (fs_type, device) else: cmd = "mkfs.%s %s" % ( fs_type, device) # works with bfs, btrfs, minix, msdos, ntfs self.log.write(cmd, 'format_partition') shell_exec(cmd) fs = get_filesystem(device) if fs == fs_type: return True return False
def step_mount_partitions(self, setup): self.step_mount_source(setup) # Mount the target partition for partition in setup.partitions: if(partition.mount_as is not None and partition.mount_as != ""): if partition.mount_as == "/": self.update_progress(total=4, current=3, message=_("Mounting %(partition)s on %(mountpoint)s") % {'partition':partition.partition.path, 'mountpoint':"/target/"}) print " ------ Mounting partition %s on %s" % (partition.partition.path, "/target/") if partition.type == "fat32": fs = "vfat" else: fs = partition.type self.do_mount(partition.partition.path, "/target", fs, None) break # Mount the other partitions for partition in setup.partitions: if(partition.mount_as is not None and partition.mount_as != "" and partition.mount_as != "/" and partition.mount_as != "swap"): print " ------ Mounting %s on %s" % (partition.partition.path, "/target" + partition.mount_as) shell_exec("mkdir -p /target" + partition.mount_as) if partition.type == "fat16" or partition.type == "fat32": fs = "vfat" else: fs = partition.type self.do_mount(partition.partition.path, "/target" + partition.mount_as, fs, None)
def manually_edit_partitions(): """ Edit only known disks in gparted, selected one first """ model, itr = installer.go("treeview_disks").get_selection().get_selected() preferred = model[itr][-1] if itr else '' # prefer disk currently selected and show it first in gparted disks = ' '.join(sorted((disk for disk, desc, sdd, detachable in installer.setup.disks), key=lambda disk: disk != preferred)) shell_exec('umount -f ' + disks) # umount disks (if possible) so gparted works out-of-the-box shell_exec('gparted {} &'.format(disks))
def svn_cp_tags (self, tag, message): """effects: copy this url to the tags directory, as in 'svn cp -m >message< >url< >base_url</tags/>tag<'""" shell_exec (["svn", "cp", "-m", message, self.m_base + "/trunk", self.m_base + "/tags/" + tag], noReturn=True, retries=2) pass
def copySource (self, target) : """effects: copy our source directory to the source directory of the target""" if self.srcdir() == target.srcdir(): print "using " + self.name() + " source from release" pass else: print "copying " + self.name() + " source" ignore = [".svn", "*~"] if self.name() == "RootCore": ignore += ["bin", "include", "obj", "rootcore_config", "root_config_*", "load_packages_info_*", "load_packages_success", "data", "lib", "python", "user_scripts"] pass rel_dir = self.m_wa.relPath (target.m_wa.area(), self.srcdir(), self.srcdir()) if rel_dir[0] != "/" and rel_dir != ".": ignore.append (os.path.basename (rel_dir)) pass if rel_dir != ".": shutil.copytree (self.srcdir(), target.srcdir(), symlinks = True, ignore = shutil.ignore_patterns (*ignore)) shell_exec (["chmod", "-R", "u+rw", target.srcdir()]) pass pass pass
def root_conf(self): """effects: determine the root parameters used for compilation returns: the path to the configuration file generated failures: incompatible root installation""" if not self.m_root_conf: file = os.path.join(self.bin(), "root_config_" + self.arch()) ROOTSYS = os.getenv("ROOTSYS") if ROOTSYS == None: if os.path.isfile(file): ROOTSYS = get_field(file, "ROOTSYS") if ROOTSYS and ROOTSYS != "": raise RCError("no valid root version found, try setting up root using\n" + " source " + ROOTSYS + "/bin/thisroot.sh") if os.path.isdir("/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase"): raise RCError("no valid root version found, try setting up root using\n" + " export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase\n" + " source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh\n" + " localSetupROOT") if shell_exec(["which", "root-config"], allowFail=True) != "": raise RCError("no valid root version found, try setting up root using\n" + " source `root-config --prefix`/bin/thisroot.sh") raise RCError("no valid root version found, please set up root") if os.path.isfile(file): myrootversion = get_field(file, "ROOT_VERSION") if not myrootversion: set_field(file, "ROOT_VERSION", self.root_version()) elif self.root_version() != myrootversion: myrootsys = get_field(file, "ROOTSYS") raise RCError("Root Version: " + self.root_version() + "\n" + "is not the same as previous version:\n" + " " + myrootversion + "\n" + "either set up the correct root version e.g. via:\n" + " source " + myrootsys + "/bin/thisroot.sh\n" + "or clean out the old object files via:\n" + " rc clean") self.m_root_conf = file return file myarch = shell_exec(["root-config", "--etcdir"]) + "/Makefile.arch" if not os.path.isfile(myarch): myarch = os.getenv("ROOTSYS") + "/share/doc/root/test/Makefile.arch" if not os.path.isfile(myarch): shell_args = ["find", os.getenv("ROOTSYS") + "/.", "-name", "Makefile.arch"] search = shell_exec(shell_args).strip().split("\n") if len(search) > 0: myarch = search[0] if not os.path.isfile(myarch): raise RCError("failed to find Makefile.arch in " + os.getenv("ROOTSYS")) with open(file + "-", "w") as f: shell_args = ["make", "-f", self.dir() + "/Makefile-print", "MAKEFILE_ARCH=" + myarch] rc = shell_exec(shell_args, stdout=f, returnRC=True) if rc != 0: raise RCError("could not determine compilation parameters") os.rename(file + "-", file) self.m_root_conf = file return self.m_root_conf
def svn_commit (self, message): """effects: commit this package, as with 'svn commit -m >message<'""" if not self.dir() : raise Exception ("no directory associated with the url") shell_exec (["git", "commit", "-a", "-m", message], workDir=self.m_dir, noReturn=True) pass
def mount_device(self, device_path): # Check if mounted mount_point = get_mount_point(device_path) if mount_point == '': mount_point = TMP_MOUNTPOINT #print((">> mount %s ro on %s" % (device_path, mount_point))) shell_exec('mount --read-only {} {}'.format(device_path, mount_point)) return mount_point
def set_timezone(self): # set the timezone if '/' in self.timezone and len(self.timezone) > 3: print((" --> Set time zone %s" % self.timezone)) self.queue_progress() shell_exec("echo \"%s\" > /etc/timezone" % self.timezone) shell_exec("cp /usr/share/zoneinfo/%s /etc/localtime" % self.timezone)
def unmount_partition(device): shell_exec("umount -f {}".format(device)) if is_connected(device): shell_exec("cryptsetup close {} 2>/dev/null".format(device)) ret = getoutput("grep '%s ' /proc/mounts" % device)[0] if not device in ret: return True return False
def get_device_mount(self, device): shell_exec("udisks --mount {}1".format(device)) mount = getoutput( "grep %s1 /etc/mtab | awk '{print $2}' | sed 's/\\040/ /g'" % device) if mount: return mount[0] return ''
def encrypt_partition(device, passphrase): if is_mounted(device): unmount_partition(device) # Cannot use echo to pass the passphrase to cryptsetup because that adds a carriadge return shell_exec( "printf \"%s\" | cryptsetup luksFormat --cipher aes-xts-plain64 --key-size 512 --hash sha512 --iter-time 5000 --use-random %s" % (passphrase, device)) return connect_block_device(device, passphrase)
def unmount_device(self, device_path): if is_encrypted(device_path): unmount_partition(device_path) else: fs = self._get_filesystem(device_path) if fs is not None: return self._unmount_filesystem(fs) else: shell_exec("umount --force {}".format(device_path))
def detectTotalRace(self, detect_dir, sched): for trace_file in list_dir(detect_dir, ext='.trace'): if sched is not None and sched not in trace_file: continue race_file = trace_file.replace('.trace', '.race') if not os.path.exists(race_file): print 'TO detect:', trace_file bin = os.path.join(PROJ_DIR, 'bin/detect') shell_exec('%s %s' % (bin, trace_file))
def mount_device(self, device_path): # Check if mounted mount_point = get_mount_point(device_path) if mount_point == '': mount_point = TMP_MOUNTPOINT #print((">> mount %s ro on %s" % (device_path, mount_point))) shell_exec('mount --read-only {} {}'.format( device_path, mount_point)) return mount_point
def mount_device(self, device_path, mount_point=None, filesystem=None, options=None, passphrase=None): if mount_point is None: mount_point = '' if filesystem is None: filesystem = '' if options is None: options = '' if passphrase is None: passphrase = '' # Connect encrypted partition connected = False if passphrase: if is_encrypted(device_path) and not is_connected(device_path): device_path, filesystem = connect_block_device(device_path, passphrase) # Do not mount swap partition if filesystem == 'swap': #print((">>>> swap partition: return device_path=%s, filesystem=%s" % (device_path, filesystem))) return (device_path, '', filesystem) # Try udisks way if no mount point has been given if not mount_point: fs = self._get_filesystem(device_path) if fs is not None: mount_points = self._mount_filesystem(fs) if mount_points: # Set mount point and free space for this device total, free, used = self.get_mount_size(mount_points[0]) self.devices[device_path]['mount_point'] = mount_points[0] self.devices[device_path]['free_size'] = free filesystem = get_filesystem(device_path) return (device_path, mount_points[0], filesystem) # Try a temporary mount point on uuid uuid = get_uuid(device_path) if uuid: mount_point = join('/media', uuid) else: return (device_path, mount_point, filesystem) # Mount the device to the given mount point if not exists(mount_point): makedirs(mount_point, exist_ok=True) if exists(mount_point): if options: if options[0:1] != '-': options = '-o ' + options else: options = '' fs = '-t ' + filesystem if filesystem else '' cmd = "mount {options} {fs} {device_path} {mount_point}".format(**locals()) shell_exec(cmd) if self.is_mounted(device_path): filesystem = get_filesystem(device_path) return (device_path, mount_point, filesystem) return (device_path, '', filesystem)
def do_mount(device, mountpoint, filesystem=None, options=None): if get_mount_point(device, mountpoint) == '': if options: if options[0:1] != '-': options = '-o ' + options else: options = '' filesystem = '-t ' + filesystem if filesystem else '' cmd = "mount {options} {filesystem} {device} {mountpoint}".format(**locals()) shell_exec(cmd)
def clear_partition(partition): unmount_partition(partition) enc_key = '-pbkdf2' openssl_version = get_package_version('openssl') if compare_package_versions(openssl_version, '1.1.1') == 'smaller': # deprecated key derivation in openssl 1.1.1+ enc_key = '-aes-256-ctr' shell_exec( "openssl enc {0} -pass pass:\"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)\" -nosalt < /dev/zero > {1}" .format(enc_key, partition.enc_status['device']))
def connect_block_device(device, passphrase): if exists(device): mapped_name = basename(device) shell_exec("printf \"{}\" | cryptsetup open --type luks {} {}".format( passphrase, device, mapped_name)) # Collect info to return mapped_device = join('/dev/mapper', mapped_name) if exists(mapped_device): filesystem = get_filesystem(mapped_device) return (mapped_device, filesystem) return ('', '')
def do_mount(device, mountpoint, filesystem=None, options=None): if get_mount_point(device, mountpoint) == '': if options: if options[0:1] != '-': options = '-o ' + options else: options = '' filesystem = '-t ' + filesystem if filesystem else '' cmd = "mount {options} {filesystem} {device} {mountpoint}".format( **locals()) shell_exec(cmd)
def stop(self): """Stops vm. Destroys changes on it """ if self.destroy_on_exit: if self.started: if self.use_libvirt: self.vm.destroy() else: shell_exec('lxc-stop -n "{0}"'.format(self.lxc_name)) self.fs.umount() shell_exec('rm -rf "{0}"'.format(self.fs.mpoint))
def create_snapshot(self): self.snapname = str(uuid.uuid1()) self.snappath = os.path.join(self.mpoint, "snapshots", self.snapname) shell_exec('btrfs subvolume snapshot "{0}" "{1}"'.format(self.mpoint, self.mpoint)) for subvolid, subvolume in self.subvolumes(): if subvolume.endswith(self.snapname): break assert subvolume.endswith(self.snapname) self.subvolid = subvolid
def manually_edit_partitions(): """ Edit only known disks in gparted, selected one first """ model, itr = installer.go("treeview_disks").get_selection().get_selected() preferred = model[itr][ -1] if itr else '' # prefer disk currently selected and show it first in gparted disks = ' '.join( sorted((disk for disk, desc, sdd, detachable in installer.setup.disks), key=lambda disk: disk != preferred)) shell_exec( 'umount -f ' + disks) # umount disks (if possible) so gparted works out-of-the-box shell_exec('gparted {} &'.format(disks))
def language_specific(self): localizeConf = join(self.scriptDir, "localize/%s" % self.default_locale) if exists(localizeConf): try: print((" --> Localizing %s" % self.edition)) config = get_config_dict(localizeConf) packages = config.get(self.edition, '').strip() if packages != "": self.queue_progress() shell_exec("%s apt-get install %s %s" % (self.debian_frontend, self.apt_options, packages)) except Exception as detail: msg = "ERROR: %s" % detail print(msg)
def unmount_device(self, device_path): fs = self._get_filesystem(device_path) if fs is not None: try: self._unmount_filesystem(fs) except: pass if self.is_mounted(device_path): shell_exec("umount -f {}".format(device_path)) if not self.is_mounted(device_path): if is_encrypted(device_path): shell_exec("cryptsetup close {} 2>/dev/null".format(device_path)) return True return False
def rsa_gen(username, passphrase, key_length=4096, verbose=False): ''' Generate a new RSA keypair username: Name of the keypair passphrase: Passphrase used to open the generated keypair key_length: Length of the keypair to generate ''' shell_exec(sslcmd.RSA_GEN_PRIVATE.format(os.path.join(KEYSTORE, username), passphrase, key_length), verbose=verbose) shell_exec(sslcmd.RSA_GEN_PUBLIC.format(os.path.join(KEYSTORE, username), passphrase), verbose=verbose) return os.path.join(KEYSTORE, username)
def on_btnDelete_clicked(self, widget): selected_isos = self.tvUsbIsosHandler.getToggledValues(toggleColNr=0, valueColNr=2) if selected_isos: msg = _("Are you sure you want to remove the selected ISO from the device?") answer = QuestionDialog(self.btnDelete.get_label(), msg) if answer: for iso in selected_isos: iso_path = join(self.device["mount"], iso) if exists(iso_path): os.remove(iso_path) self.log.write("Remove ISO: {}".format(iso_path)) shell_exec("usb-creator -d {} -g".format(self.device["path"])) self.on_cmbDevice_changed() self.fill_treeview_usbcreator(self.device["mount"])
def __init__(self): self.scriptDir = abspath(dirname(__file__)) self.timezones = getoutput("awk '/^[^#]/{print $3}' /usr/share/zoneinfo/zone.tab | sort -k3") self.refresh() # Genereate locale files with the default locale if they do not exist if not exists('/etc/locale.gen'): shell_exec("echo \"%s.UTF-8 UTF-8\" >> /etc/locale.gen" % DEFAULTLOCALE) shell_exec("locale-gen") if self.default_locale == '': self.default_locale = DEFAULTLOCALE shell_exec("echo \"\" > /etc/default/locale") shell_exec("update-locale LANG=\"%s.UTF-8\"" % self.default_locale) shell_exec("update-locale LANG=%s.UTF-8" % self.default_locale)
def run(self): self.set_locale() self.set_timezone() if has_internet_connection(): self.queue_progress() shell_exec("apt-get update") self.applications() self.language_specific() else: msg = _( "SolydXK System Settings cannot download and install the software localization packages\n" "Please repeat this process when you established an internet connection." ) WarningDialog(_("No internet connection", msg))
def rc_checkout(self, shared=False): """effects: do our part of rc checkout""" if os.path.isdir(self.dir()): return print "checking out " + self.name() mkdir_p(os.path.dirname(self.dir())) if not self.m_url: raise RCError("can not run rc checkout without git url") cmd = ["git", "clone"] if shared: cmd += ["--shared"] pass cmd += [self.m_url, self.dir()] shell_exec(cmd, noReturn=True) pass
def rc_checkout (self, shared=False) : """effects: do our part of rc checkout""" if os.path.isdir (self.dir()) : return print "checking out " + self.name() mkdir_p (os.path.dirname (self.dir())) if not self.m_url : raise RCError ("can not run rc checkout without git url") cmd = ["git", "clone"] if shared : cmd += ["--shared"] pass cmd += [self.m_url, self.dir()] shell_exec (cmd, noReturn=True) pass
def getLibFlags (self, lib, user=False, external=False): """returns: the linker flags to use when linking a library depending on all the packages in the list""" result = "" if not user and not external: result = str(result + " " + get_field (self.m_wa.root_conf(), "SOFLAGS")).strip() #result = string.strip (result + " " + get_field (self.m_wa.root_conf(), "SOFLAGS")) pass result = str(result + " " + shell_exec (["root-config", "--ldflags"])).strip() #result = string.strip (result + " " + shell_exec (["root-config", "--ldflags"])) for var in ["LDFLAGS", "CPPEXFLAGS"]: flags = os.getenv (var) if flags and flags != "": result = str(result + " " + flags).strip() pass pass if not user: result += " " + get_field (self.m_wa.root_conf(), "ROOTLIBS") pass if (not user and not external and get_field (self.m_wa.root_conf(), "PLATFORM") == "macosx"): result = str(result + " -dynamiclib -undefined dynamic_lookup" + " -install_name @rpath/" + os.path.basename (lib)).strip() #result = string.strip (result + " -dynamiclib -undefined dynamic_lookup -install_name @rpath/" + os.path.basename (lib)) pass return result;
def addPkgDep(self, name, required, caller, cycle, catalog, allowMiss, wa): if self.getPkg(name): return for pkg in cycle: if name == pkg: raise Exception("cyclical dependence involving packages: " + string.join(cycle)) pkg = catalog.getPkg(name) if not pkg: if allowMiss or not required: return message = "" if caller: message = "package " + name + " not known, required by " + caller else: message = "package " + name + " not known" shell_args = ["grep", "/" + name + "/tags", wa.dir() + "/all_packages"] known = shell_exec(shell_args, allowFail=True).split("\n") while len(known) > 0 and known[len(known) - 1] == "": known.remove("") if len(known) > 0: message += "\ntry checking it out with" for pkg in known: message += "\n rc checkout_pkg " + pkg raise RCError(message) for dep in pkg.harddep(): addPkgDep(self, dep, True, name, cycle + [name], catalog, allowMiss, wa) for dep in pkg.trydep(): addPkgDep(self, dep, False, name, cycle + [name], catalog, allowMiss, wa) self.addPkg(pkg)
def __init__ (self, url, dir) : if not url : info = shell_exec (["svn", "info", dir], newEnv={"LANG":None}) expr = re.compile ("\nURL: ([^\\n]*)\n") match = expr.search (info) if not match : raise RCError ("failed to parse output of svn info " + dir + ":\n" + info) url = match.group (1) pass super (SvnInfoSvn, self).__init__ (dir) self.m_url = url while url[-1] == "/" : url = url[:-1] pass name1 = os.path.basename (url) name2 = os.path.basename (os.path.dirname (url)) name3 = os.path.basename (os.path.dirname (os.path.dirname (url))) if name2 == "tags" or name2 == "branches" : self.m_name = name3 self.m_tag = name1 self.m_base = os.path.dirname (os.path.dirname (url)) pass elif name1 == "tags" or name1 == "trunk" : self.m_name = name2 self.m_tag = name1 self.m_base = os.path.dirname (url) pass else : self.m_name = name1 self.m_tag = "" self.m_base = url pass pass
def svn_status (self, noReturn=False, update=False, allowNone=False): """effects: same as 'svn status' returns: the status (unless noReturn is specified)""" if update: raise RCError ("-u not supported for git status") return shell_exec (["git", "status", "-s"], workDir=self.m_dir, noReturn=noReturn)
def format_partition(self, partition): device = partition['device'] fs_type = partition['fs_type'] label = partition['label'] if not fs_type: msg = _("Error formatting partition {0}:\n" "It has no file system type.".format(device)) self.queue.put([1, 110, None, None, msg]) return False # Build format command if fs_type == "swap": cmd = "mkswap %s" % device elif fs_type[:3] == 'ext': cmd = "mkfs.%s -F -q %s" % (fs_type, device) elif fs_type == "jfs": cmd = "mkfs.%s -q %s" % (fs_type, device) elif fs_type == "xfs": cmd = "mkfs.%s -f %s" % (fs_type, device) elif fs_type == "vfat": cmd = "mkfs.%s %s -F 32" % (fs_type, device) else: cmd = "mkfs.%s %s" % ( fs_type, device) # works with bfs, btrfs, minix, msdos, ntfs self.log.write(cmd, 'format_partition') ret = shell_exec(cmd) if ret == 0: self.set_label(device, fs_type, label) # Always return True, even if setting the label didn't go right return True msg = "Could not format the partition {} to {}".format(device, fs_type) self.queue.put([1, 115, None, None, msg]) return False
def start_subprocess(self, args, cwd, stdout, stderr, stdin, shell, env): if cwd is None: cwd = self.default_cwd env = Environment(self.log, env.get()) env.set(self.shared_env.get()) return shell_exec(args, cwd=cwd, stdout=stdout, stderr=stderr, stdin=stdin, shell=shell, env=env.get())
def on_btnDelete_clicked(self, widget): selected_isos = self.tvUsbIsosHandler.getToggledValues(toggleColNr=0, valueColNr=2) if selected_isos: msg = _( "Are you sure you want to remove the selected ISO from the device?" ) answer = QuestionDialog(self.btnDelete.get_label(), msg) if answer: for iso in selected_isos: iso_path = join(self.device["mount"], iso) if exists(iso_path): os.remove(iso_path) self.log.write("Remove ISO: {}".format(iso_path)) shell_exec("usb-creator -d {} -g".format(self.device["path"])) self.on_btnRefresh_clicked() self.fill_treeview_usbcreator(self.device["mount"])
def get_last_updated(image_config): image_repo = config["gcr_image_repo"] image_name = image_config["name"] version = image_config["version"] command = "gcloud container images list-tags {}/{} | grep {} | awk '{{print $NF}}'".format(image_repo, image_name, version) ISO8601_date = utils.shell_exec(command) terra_date = ISO8601_date.split("T")[0] return terra_date
def rc_checkout (self, shared=False) : """effects: do our part of rc checkout""" if os.path.isdir (self.dir()) : return print "checking out " + self.name() if self.m_url.find ("svn+ssh://svn.cern.ch") == 0 : if not self.svnuser() : self = self.useSvnuser (os.getenv ("CERN_USER")) pass if not self.svnuser() : self = self.useSvnuser (os.getenv ("CERNUSER")) pass pass self = self.resolveTags() mkdir_p (os.path.dirname (self.dir())) shell_exec (["svn", "checkout", self.m_url, self.dir()], retries=2, noReturn=True) pass
def svn_status (self, noReturn=False, update=False, allowNone=False): """effects: same as 'svn status' returns: the status (unless noReturn is specified)""" cmd = ["svn", "status"] retries = 0 if update: cmd.append ("-u") retries = 2 pass return shell_exec (cmd, workDir=self.dir(), noReturn=noReturn, retries=retries)
def linkPostcompile (self) : """effects: link all the files created during compilation""" if self.name() == "RootCore": return ROOTCORECONFIG = self.m_wa.arch() #for file in "lib" + self.name() + ".so", "lib" + self.name() + "_Reflex.so", "lib" + self.name() + "_Reflex.rootmap", self.name() + "CINT_rdict.pcm", self.name() + "_Reflex_rdict.pcm": for file in ("lib" + self.name() + ".so", "lib" + self.name() + "_Reflex.so", "lib" + self.name() + "_Reflex.rootmap", self.name() + "CINT_rdict.pcm", self.name() + "_Reflex_rdict.pcm"): source = os.path.join (self.libdir(), file) if os.path.isfile (source): self.m_wa.lnRel (source, os.path.join (self.m_wa.bin(), "lib", ROOTCORECONFIG, file)) pass pass dir = self.bindir() if os.path.isdir (dir): for file in os.listdir (dir): self.m_wa.lnRel (os.path.join (dir, file), os.path.join (self.m_wa.bin(), "bin", ROOTCORECONFIG, file)) pass pass file = os.path.join (self.srcdir(), "cmt", "link.RootCore") if os.path.isfile (file): if not os.access (file, os.X_OK): raise RCError ("execute flag not set on " + os.path.basename (file) + ", please run\n chmod +x " + file); newEnv = {} newEnv["ROOTCORECMT"] = self.libdir() newEnv["ROOTCOREBIN"] = self.m_wa.bin() newEnv["ROOTCOREOBJ"] = self.m_wa.obj() shell_exec ([file], workDir=os.path.join (self.srcdir(), "cmt"), noReturn=True, newEnv=newEnv) pass pass
def svn_ls_tags (self): """returns: a list of tags as in 'svn ls >base-svn</tags'""" result = [] shell_args = ["svn", "ls", self.m_base + "/tags"] #for tag in string.split (shell_exec (["svn", "ls", self.m_base + "/tags"], retries=2)) : for tag in shell_exec (shell_args, retries=2).split(): result.append (tag.strip("/")) #result.append(string.strip(tag, "/")) pass return sorted (result)
def root_version(self): """description: the root version description string. rationale: this is mostly used to check that we call 'rc clean' whenever we change root version""" if not hasattr(self, "m_root_version"): try: root_version = shell_exec(["root", "-b", "-q"]) index = root_version.find("\nROOT") if index == -1: raise RCError("failed to read root version, please send me the output of\nroot -b -q") root_version = root_version[index+1:] index = root_version.find("\n") if index == -1: raise RCError("failed to read root version, please send me the output of\nroot -b -q") self.m_root_version = root_version[0:index] except RCError: self.m_root_version = shell_exec(["root-config", "--version"]).rstrip() return self.m_root_version
def step_format_partitions(self, setup): for partition in setup.partitions: if(partition.format_as is not None and partition.format_as != ""): # report it. should grab the total count of filesystems to be formatted .. self.update_progress(total=4, current=1, pulse=True, message=_("Formatting %(partition)s as %(format)s ..." % {'partition':partition.partition.path, 'format':partition.format_as})) #Format it if partition.format_as == "swap": cmd = "mkswap %s" % partition.partition.path else: if (partition.format_as == "jfs"): cmd = "mkfs.%s -q %s" % (partition.format_as, partition.partition.path) elif (partition.format_as == "xfs"): cmd = "mkfs.%s -f %s" % (partition.format_as, partition.partition.path) elif (partition.format_as == "vfat"): cmd = "mkfs.%s %s -F 32" % (partition.format_as, partition.partition.path) else: cmd = "mkfs.%s %s" % (partition.format_as, partition.partition.path) # works with bfs, btrfs, ext2, ext3, ext4, minix, msdos, ntfs, vfat shell_exec(cmd) partition.type = partition.format_as
def start(self): """starts container""" self.vm_file = "/tmp/{0}.qcow2".format(uuid.uuid1()) shell_exec('qemu-img create -f qcow2 -b "{0}" "{1}"'. format(self.img_file, self.vm_file)) self.vm = KVMDomain.construct(self.conn, True, self.name, 1024 * 1024, 1, HDDFileDevice(self.vm_file, type_='qcow2', dev='hda', bus='ide'), ETHNetworkDevice(self.hwaddr, "vnet7", ip=self.ip)) return self
def isMac(self) : """returns: whether this is a mac architecture rationale: this is used in various places in the build procedure where MacOS behaves differently from Linux""" if not hasattr(self, "m_isMac") : if self.m_arch.find("-mac") != -1 : self.m_isMac = True elif self.m_arch.find("-slc") != -1 : self.m_isMac = False else : self.m_isMac =(shell_exec(["uname"]) == "Darwin") return self.m_isMac
def test_compile (self) : if os.path.isfile ("test_file.C"): with open ("test_file.C") as f: env = {} if self.m_incdir: env["ROOTCORETEST_CXXFLAGS"] = "-I" + self.m_incdir pass if shell_exec (["rc", "test_cc", "compile"], stdin=f, newEnv=env, returnRC=True) != 0: raise RCError ("test compilation failed") pass pass pass
def install_test (self) : try: ExternalLocation.install_test (self) return except: pass print "trying manual install" os.environ["options_file"] = self.m_package.m_options_file if shell_exec (["./install"],returnRC=True) != 0: raise RCError ("installation of " + self.m_package.m_pkgname + " failed") self.link_package () ExternalLocation.install_test (self)
def __init__ (self, url, dir) : if not url : lines = shell_exec (["git", "remote", "-v"], workDir=dir).split("\n") #lines = string.split (shell_exec (["git", "remote", "-v"], workDir=dir), "\n") #if len (lines) > 0 and len (string.split (lines[0])) > 1: if len (lines) > 0 and len (lines[0].split()) > 1: url = lines[0].split()[1] #url = string.split(lines[0])[1] pass pass super (SvnInfoGit, self).__init__ (dir) self.m_url = url self.m_svngit = None if not url and os.path.exists (os.path.join (dir, ".git", "svn")) : info = shell_exec (["git", "svn", "info"], workDir=dir) expr = re.compile ("\nURL: ([^\\n]*)\n") match = expr.search (info) if not match : raise RCError ("failed to parse output of git svn info " + dir + ":\n" + info) self.m_svngit = SvnInfoSvn (match.group(1), dir) pass pass
def copyObject (self, target, config) : """effects: copy the object files from the source to the target""" if self.outdir() == target.outdir(): print "using " + self.name() + " object files from release" pass else: print "copying " + self.name() + " for " + config for dir in "bin", "lib", "test-bin": source = os.path.join (self.outdir(), config, self.name(), dir) target_dir = os.path.join (target.outdir(), config, self.name(), dir) if os.path.isdir (source): mkdir_p (os.path.dirname (target_dir)) shutil.copytree (source, target_dir) shell_exec (["chmod", "-R", "u+rw", target_dir]) pass pass pass target.linkPreconfigure() target.linkPrecompile() target.linkPostcompile() pass
def getCxxFlags (self, user=False, opt=True, pedantic=False, external=False): """returns: the compiler flags to use when compiling code depending on all the packages in the list""" result = "" if not user: if opt: result = get_field (self.m_wa.root_conf(), "CXXFLAGS") pass else: result = get_field (self.m_wa.root_conf(), "CXXFLAGS_NOOPT") pass pass result = result.strip() + " -I" + self.m_wa.bin() + "/include -g -Wno-tautological-undefined-compare" #result = string.strip (result + " " + "-I" + self.m_wa.bin() + "/include -g") if not external: result += " -DROOTCORE" pass if not user: result = str(result + " " + shell_exec (["root-config", "--cflags"])).strip() #result = string.strip (result + " " + shell_exec (["root-config", "--cflags"])) pass for var in ["CXXFLAGS", "EXTRA_CFLAGS", "CPPEXFLAGS"]: flags = os.getenv (var) if flags and flags != "": result = str(result + " " + flags).strip() #result = string.strip (result + " " + flags) pass pass # if not user: # boostinc = os.getenv ("BOOSTINCDIR") # if boostinc: # result = string.strip (result + " -I" + boostinc) # pass # pass if pedantic and not external: result = str(result + " -pipe -W -Wall -Wno-deprecated" + " -pedantic -Wwrite-strings -Wpointer-arith" + " -Woverloaded-virtual -Wno-long-long" + " -Wdeprecated-declarations").strip() pass for pkg in self.m_packages: result = str(result + " " + pkg.objflags()).strip() #result = string.strip (result + " " + pkg.objflags()) pass return result
def complete_locations (self): """effects: add in all the locations from global, site-root and local installation""" if self.m_force_local: self.m_locations = [ExternalLocationLocal (self)] return self.m_locations = [] if self.m_allow_global: self.m_locations.append (ExternalLocationGlobal (self)) pass if self.m_siteroot: SITEROOT = os.getenv ("SITEROOT") if SITEROOT: shell_args = ["find", os.path.join (SITEROOT, self.m_siteroot), "-type", "d", "-name", "lib"] for libdir in shell_exec (shell_args).split("\n"): if libdir.find (os.getenv("CMTCONFIG")) != -1: print "found via SITEROOT: " + libdir maindir = os.path.dirname (libdir) incdir = os.path.join (maindir, "include") loc = incdir + ":" + libdir self.m_locations.append (ExternalLocation(self, loc)) pass pass pass pass #for location in string.split (get_field (self.m_options_file, "locations", default=""), " "): for location in get_field (self.m_options_file, "locations", default="").split(): location = expand_env (location) if location and location != "": self.m_locations.append (ExternalLocation (self, location)) pass pass if os.path.exists ("install"): self.m_locations.append (ExternalLocationLocal (self)) pass pass