def sbot_executable(): """ Find shoebot executable """ gsettings = load_gsettings() venv = gsettings.get_string("current-virtualenv") if venv == "Default": sbot = which("sbot") elif venv == "System": # find system python env_venv = os.environ.get("VIRTUAL_ENV") if not env_venv: return which("sbot") # First sbot in path that is not in current venv for p in os.environ["PATH"].split(os.path.pathsep): sbot = "%s/sbot" % p if not p.startswith(env_venv) and os.path.isfile(sbot): return sbot else: sbot = os.path.join(venv, "bin/sbot") if not os.path.isfile(sbot): print("Shoebot not found, reverting to System shoebot") sbot = which("sbot") return os.path.realpath(sbot)
def sbot_executable(): """ Find shoebot executable """ gsettings=load_gsettings() venv = gsettings.get_string('current-virtualenv') if venv == 'Default': sbot = which('sbot') elif venv == 'System': # find system python env_venv = os.environ.get('VIRTUAL_ENV') if not env_venv: return which('sbot') # First sbot in path that is not in current venv for p in os.environ['PATH'].split(os.path.pathsep): sbot='%s/sbot' % p if not p.startswith(env_venv) and os.path.isfile(sbot): return sbot else: sbot = os.path.join(venv, 'bin/sbot') if not os.path.isfile(sbot): print('Shoebot not found, reverting to System shoebot') sbot = which('sbot') return os.path.realpath(sbot)
class LinuxFileChooser(FileChooser): '''FileChooser implementation for GNu/Linux. Accepts one additional keyword argument, *desktop_override*, which, if set, overrides the back-end that will be used. Set it to "gnome" for Zenity, to "kde" for KDialog and to "yad" for YAD (Yet Another Dialog). If set to None or not set, a default one will be picked based on the running desktop environment and installed back-ends. ''' desktop = None if (str(os.environ.get("XDG_CURRENT_DESKTOP")).lower() == "kde" and which("kdialog")): desktop = "kde" elif which("yad"): desktop = "yad" elif which("zenity"): desktop = "gnome" def _file_selection_dialog(self, desktop_override=desktop, **kwargs): if not desktop_override: desktop_override = desktop # This means we couldn't find any back-end if not desktop_override: raise OSError("No back-end available. Please install one.") chooser = CHOOSERS[desktop_override] c = chooser(**kwargs) return c.run()
class LinuxFileChooser(FileChooser): desktop = None if str(os.environ.get("XDG_CURRENT_DESKTOP")).lower() == "kde" \ and which("kdialog"): desktop = "kde" elif which("yad"): desktop = "yad" elif which("zenity"): desktop = "gnome" def __init__(self): self.chooser = None def _file_selection_dialog(self, desktop_override=desktop, **kwargs): if not desktop_override: desktop_override = desktop # This means we couldn't find any back-end if not desktop_override: raise OSError("No back-end available. Please install one.") chooser_cls = CHOOSERS[desktop_override] self.chooser = chooser_cls(**kwargs) selection = self.chooser.run() self.chooser = None return selection def cancel(self): if self.chooser: self.chooser.force_cancel = True
def sbot_executable(): """ Find shoebot executable """ gsettings = load_gsettings() venv = gsettings.get_string('current-virtualenv') if venv == 'Default': sbot = which('sbot') elif venv == 'System': # find system python env_venv = os.environ.get('VIRTUAL_ENV') if not env_venv: return which('sbot') # First sbot in path that is not in current venv for p in os.environ['PATH'].split(os.path.pathsep): sbot = '%s/sbot' % p if not p.startswith(env_venv) and os.path.isfile(sbot): return sbot else: sbot = os.path.join(venv, 'bin/sbot') if not os.path.isfile(sbot): print('Shoebot not found, reverting to System shoebot') sbot = which('sbot') return os.path.realpath(sbot)
def parse_tinc_stats(): import subprocess from time import sleep from distutils.spawn import find_executable as which #newest tinc if which("tinc"): return parse_new_input("tinc") #new tinc elif which("tincctl"): return parse_new_input("tincctl") #old tinc else: raise Exception("no tinc executable found!")
def getFirewall(): "Funcion de ayuda para obtener la clase de firewall" # ruta = which("firewall-cmd") # if ruta: # return Firewall(FirewallD(ruta)) ruta = which("awk") if not ruta: raise OSError("No se encontro el binario de awk.") ruta = which("iptables") if ruta: return Firewall(Iptables(ruta)) raise OSError("No se encontro firewall-cmd ni iptables.")
def report_error(summary, message=""): print(summary + ': ' + message) # http://stackoverflow.com/a/12611523/2257038 if not ytdl_config.NOTIFY_COMMAND == '' and which(ytdl_config.NOTIFY_COMMAND): subprocess.Popen([ytdl_config.NOTIFY_COMMAND, "YoutubeDL mpv: " + summary, message]) else: print("Error: NOTIFY_COMMAND is unset, or does not exist")
def get_processor_resource_types(executable, ocrd_tool=None): """ Determine whether a processor has resource parameters that represent directories (``has_dirs``), files (``has_files``) or neither. Returns a pair ``(has_dir, has_files)`` """ if not ocrd_tool: # if the processor in question is not installed, assume both files and directories if not which(executable): return (True, True) result = run([executable, '--dump-json'], stdout=PIPE, check=True, universal_newlines=True) ocrd_tool = loads(result.stdout) if not next( (True for p in ocrd_tool['parameters'].values() if 'content-type' in p), False): # None of the parameters for this processor are resources (or not # the resource parametrs are not properly declared, so output both # directories and files return (True, True) has_dirs = next((True for p in ocrd_tool['parameters'].values() if p.get('content-type', None) == 'text/directory'), False) has_files = next( (True for p in ocrd_tool['parameters'].values() if 'content-type' in p and p['content-type'] != 'text/directory'), False) return (has_dirs, has_files)
def start_shoebot(self): if not which('sbot'): textbuffer = self.output_widget.get_buffer() textbuffer.set_text('Cannot find sbot in path.') while Gtk.events_pending(): Gtk.main_iteration() return False if self.bot and self.bot.process.poll() == None: print('Has a bot already') return False # get the text buffer doc = self.window.get_active_document() if not doc: return title = doc.get_short_name_for_display() cwd = os.path.dirname(doc.get_uri_for_display()) or None start, end = doc.get_bounds() code = doc.get_text(start, end, False) if not code: return False textbuffer = self.output_widget.get_buffer() textbuffer.set_text('') while Gtk.events_pending(): Gtk.main_iteration() self.bot = ShoebotProcess(code, self.use_socketserver, self.show_varwindow, self.use_fullscreen, title, cwd=cwd) GObject.idle_add(self.update_shoebot)
def main(): parser = argparse.ArgumentParser( description="Generate thrift code for remote file system service") parser.add_argument( "-l", "--lan", action="store", dest="language", choices=["js:node", "java", "php", "python", "perl", "ruby"], default="js:node", help="Compile thrift to given language.", ) args = parser.parse_args() if not which("thrift"): print( "thrift is not installed. See https://thrift.apache.org/ to install." ) exit(1) try: run_thrift(args.language) except ThriftError: print("There was an error running thrift") exit(1)
def _gen_cmdline(self): cmdline = [ which(self.executable), "--file-selection", "--confirm-overwrite" ] if self.multiple: cmdline += ["--multiple"] if self.mode == "save": cmdline += ["--save"] elif self.mode == "dir": cmdline += ["--directory"] if self.path: cmdline += ["--filename", self.path] if self.title: cmdline += ["--name", self.title] if self.icon: cmdline += ["--window-icon", self.icon] for f in self.filters: if type(f) == str: cmdline += ["--file-filter", f] else: cmdline += [ "--file-filter", "{name} | {flt}".format(name=f[0], flt=" ".join(f[1:])) ] return cmdline
def main(): parser = argparse.ArgumentParser( description= "Generate thrift code for all .thrift files in subdirectories") parser.add_argument( "-l", "--lan", action="store", dest="language", choices=["js:node", "java", "php", "python", "perl", "ruby"], default="js:node", help="Compile thrift to given language.", ) args = parser.parse_args() if not which("thrift"): print( "thrift is not installed. See https://thrift.apache.org/ to install." ) exit(1) try: start_dir = Path(os.path.dirname(os.path.realpath(__file__))) thrift_files = list(start_dir.glob('**/*.thrift')) run_thrift(args.language, thrift_files) except ThriftError: print("There was an error running thrift") exit(1)
def _gen_cmdline(self): cmdline = [which(self.executable)] filt = [] for f in self.filters: if type(f) == str: filt += [f] else: filt += list(f[1:]) if self.mode == "dir": cmdline += [ "--getexistingdirectory", (self.path if self.path else os.path.expanduser("~")) ] elif self.mode == "save": cmdline += [ "--getopenfilename", (self.path if self.path else os.path.expanduser("~")), " ".join(filt) ] else: cmdline += [ "--getopenfilename", (self.path if self.path else os.path.expanduser("~")), " ".join(filt) ] if self.multiple: cmdline += ["--multiple", "--separate-output"] if self.title: cmdline += ["--title", self.title] if self.icon: cmdline += ["--icon", self.icon] return cmdline
def readxcf(xcf_filename, formatstr, _flags): ''' im = readxcf(xcf_filename, formatstr) Returns a numpy array with the (flattened) XCF file. Depends on `xcf2png` being available. Parameters ---------- xcf_filename : str Filename formatstr : str format. Must be 'xcf' Returns ------- im : ndarray ''' from os import system from tempfile import NamedTemporaryFile from distutils.spawn import find_executable as which if formatstr != 'xcf': raise ValueError('imread.imread.readxcf: Format string must be \'xcf\'') if not which('xcf2png'): raise OSError('imread.readxcf: xcf format is only supported through the xcf2png utility, which imread could not find') N = NamedTemporaryFile(suffix='.png') output = system('xcf2png %s >%s' % (xcf_filename,N.name)) if output: raise OSError('imread.readxcf: xcf format is only supported through the xcf2png utility, which failed to run') return imread.imread(N.name, return_metadata=True)
def run_iter(cmd, interp=None, stdin=None): if interp is not None: cmd = interp + [which(cmd[0])] + cmd[1:] return subprocess.Popen(cmd, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def has_c_compiler(compiler="gcc"): if os.path.exists(compiler): path = compiler else: path = which(compiler) set_runopt("ENABLE_WEAVE", bool(path)) return compiler
def get_bazel_paths(bazel_path_flag): """Yields a sequence of guesses about bazel path. Some of sequence elements can be None. The resulting iterator is lazy and potentially has a side effects.""" yield bazel_path_flag yield which("bazel") yield download_and_verify_bazel()
def validate(self): if not which(self.executable): raise Exception("Executable not found in PATH: %s" % self.executable) if not self.input_file_grps: raise Exception("Task must have input file group") # TODO uncomment and adapt once OCR-D/spec#121 lands # # make implicit input/output groups explicit by defaulting to what is # # provided in ocrd-tool.json # actual_output_grps = [*self.ocrd_tool_json['output_file_grp']] # for i, grp in enumerate(self.output_file_grps): # actual_output_grps[i] = grp # self.output_file_grps = actual_output_grps # actual_input_grps = [*self.ocrd_tool_json['input_file_grp']] # for i, grp in enumerate(self.input_file_grps): # actual_input_grps[i] = grp # self.input_file_grps = actual_input_grps param_validator = ParameterValidator(self.ocrd_tool_json) report = param_validator.validate(self.parameters) if not report.is_valid: raise Exception(report.errors) # TODO remove once OCR-D/spec#121 lands if 'output_file_grp' in self.ocrd_tool_json and not self.output_file_grps: raise Exception( "Processor requires output_file_grp but none was provided.") return report
def has_xcf2png(): # there is no native xcf2png utility for Windows from distutils.spawn import find_executable as which if which('xcf2png'): # test iff xcf2png is present on the system def test_xcf(): im = imread('imread/tests/data/diag.xcf') assert im.shape == (8, 8, 3) assert im.max(2).diagonal().sum() == 0 if sys.platform.startswith('win'): return False try: from shutil import which except: from distutils.spawn import find_executable as which c = which('xcf2png') return (c is not None)
def whichFirst(nameList): from distutils.spawn import find_executable as which os.environ.setdefault("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ) for name in nameList: path = which(name) if path is not None: yield path
def parse_tinc_stats(): import subprocess from time import sleep from distutils.spawn import find_executable as which #newest tinc if which("tinc"): return parse_new_input("tinc") #new tinc elif which("tincctl"): return parse_new_input("tincctl") #old tinc elif which("tincd"): # TODO refactor me subprocess.call(["pkill", "-SIGUSR2", "tincd"]) sleep(1) return parse_input(get_tinc_block(get_tinc_log_file())) #no tinc else: raise Exception("no tinc executable found!")
def parse_tinc_stats(): import subprocess from time import sleep from distutils.spawn import find_executable as which #newest tinc if which("tinc"): return parse_new_input("tinc") #new tinc elif which("tincctl"): return parse_new_input("tincctl") #old tinc elif which("tincd"): # TODO refactor me subprocess.call(["pkill","-SIGUSR2", "tincd"]) sleep(1) return parse_input(get_tinc_block(get_tinc_log_file())) #no tinc else: raise Exception("no tinc executable found!")
def validate(self): if self.parameter_path and not os.access(self.parameter_path, os.R_OK): raise Exception("Parameter file not readable: %s" % self.parameter_path) if not self.input_file_grps: raise Exception("Task must have input file group") if not self.output_file_grps: raise Exception("Task must have output file group") if not which(self.executable): raise Exception("Executable not found in PATH: %s" % self.executable)
def uninstall(): #First step is to unregister the startup script using update-rc.d or chkconfig depending on the linux flavour pa_init = which(STARTUP_SCRIPT_NAME) if flavour()[0] == 'Ubuntu': cmd = which('update-rc.d') update_rc_d = utils.create_subprocess([cmd, '-f', pa_init, 'remove']) utils.call_subprocess(update_rc_d) if update_rc_d.returncode != 0: LOG.error("Failed to execute update-rc.d command. Exit code = " + str(update_rc_d.returncode)) raise Exception("Failed to remove statrup script") if flavour()[0] == 'Red Hat Enterprise Linux Server': cmd = which('chkconfig') chkconfig = utils.create_subprocess([cmd, '--del', pa_init]) utils.call_subprocess(chkconfig) if chkconfig.returncode != 0: LOG.error("Failed to execute chkconfig command. Exit code = " + str(chkconfig.returncode)) raise Exception("Failed to remove startup script") if os.path.exists(INIT_DIR) and os.path.isdir(INIT_DIR): STARTUP_SCRIPT=os.path.join(INIT_DIR, STARTUP_SCRIPT_NAME) LOG.debug("Removing startup script : " + STARTUP_SCRIPT) os.remove(STARTUP_SCRIPT) #Remove policyagent-init symlink os.remove(pa_init) pa = which(MODULE_NAME) #Remove policyagent symlink os.remove(pa) #Remove the policyagent directory if os.path.exists(PA_HOME) and os.path.isdir(PA_HOME): shutil.rmtree(PA_HOME) #Remove the selinux policy in case of RHEL if flavour()[0] == 'Red Hat Enterprise Linux Server': semodule = utils.create_subprocess(['semodule', '-r', 'policyagent']) utils.call_subprocess(semodule) if semodule.returncode != 0: LOG.error("Failed to execute semodule command. Exit code = " + str(semodule.returncode)) raise Exception("Failed to remove selinux policy")
def check_exists(fips_dir) : """test if 'clion' is in the path :returns: True if clion is in the path """ host = util.get_host_platform() if host == 'linux': # See if CLion was installed from a tar.gz and manually added to the path ("clion.sh"), # or added to the path using the "create launcher" command in CLion, which would by default # create a symlink from clion.sh to /usr/local/bin/clion. # This will also pick up CLion if it was installed using snap. if which("clion.sh") is not None or which("clion") is not None: return True else: return False elif host == 'osx': try: subprocess.check_output("mdfind -name CLion.app | grep 'CLion'", shell=True) return True except (OSError, subprocess.CalledProcessError): return False else: return False
def relion_symmetry_group(sym): relion = which("relion_refine") if relion is None: raise RuntimeError( "Need relion_refine on PATH to obtain symmetry operators") stdout = subprocess.check_output( ("%s --sym %s --i /dev/null --o /dev/null --print_symmetry_ops" % (relion, sym)).split()) lines = stdout.split("\n")[2:-1] return [ np.array([[np.double(val) for val in l.split()] for l in lines[i:i + 3]]) for i in range(1, len(lines), 4) ]
def get_bazel_path(bazel_path_flag): """Returns the path to a Bazel binary, downloading Bazel if not found.""" if bazel_path_flag: return bazel_path_flag bazel = download_and_verify_bazel() if bazel: return bazel bazel = which("bazel") if bazel: return bazel print("Cannot find or download bazel. Please install bazel.") sys.exit(-1)
def validate(self): if not which(self.executable): raise Exception("Executable not found in PATH: %s" % self.executable) if not self.input_file_grps: raise Exception("Task must have input file group") parameters = {} if self.parameter_path: parameters = parse_json_string_or_file(self.parameter_path) param_validator = ParameterValidator(self.ocrd_tool_json) report = param_validator.validate(parameters) if not report.is_valid: raise Exception(report.errors) if 'output_file_grp' in self.ocrd_tool_json and not self.output_file_grps: raise Exception( "Processor requires output_file_grp but none was provided.") return report
def __init__(self, img): """ Arguments: img (`PIL.Image`): PIL image technical metadata is about. """ # print(img.__dict__) self.width = img.width self.height = img.height self.photometricInterpretation = img.mode self.n_frames = img.n_frames if 'n_frames' in img.__dict__ else 1 if which('identify'): self.run_identify(img) else: getLogger('ocrd_exif').warning( "ImageMagick 'identify' not available, Consider installing ImageMagick for more robust pixel density estimation" ) self.run_pil(img)
def validate(self): if not which(self.executable): raise Exception("Executable not found in PATH: %s" % self.executable) if not self.input_file_grps: raise Exception("Task must have input file group") result = run([self.executable, '--dump-json'], stdout=PIPE, check=True, universal_newlines=True) ocrd_tool_json = json.loads(result.stdout) parameters = {} if self.parameter_path: parameters = parse_json_string_or_file(self.parameter_path) param_validator = ParameterValidator(ocrd_tool_json) report = param_validator.validate(parameters) if not report.is_valid: raise Exception(report.errors) if 'output_file_grp' in ocrd_tool_json and not self.output_file_grps: raise Exception( "Processor requires output_file_grp but none was provided.") return True
def _build_command(self): cmd = [which(self._freeling_cmd)] # Either use the config file if self._config_file_path is not None: cmd.append('-f %s' % os.path.abspath(self._config_file_path)) else: cmd.append('-f %s.cfg' % self._language) cmd.append('--input %s' % self._input_format) cmd.append('--inplv %s' % self._input_level) cmd.append('--output %s' % self._output_format) cmd.append('--outlv %s' % self._output_level) cmd.append('--loc' if self._multiword else '--noloc') cmd.append('--ner' if self._ner else '--noner') cmd.append('--nec' if self._nec else '--nonec') if self._sense: cmd.append('--sense %s' % self._sense) return cmd
def build(self): """ Build LBLRTM or LNFL """ # OS determination # https://docs.python.org/2/library/sys.html#sys.platform compPath = which(self.compiler) platform = sys.platform if platform in ['linux', 'linux2']: self.opSys = 'linux' elif platform == 'darwin': self.opSys = 'osx' elif platform == 'win32': self.opSys = 'mingw' else: sys.exit('Could not determine OS, returning') # endif OS # compiler string generation if self.compiler == 'ifort': self.compStr = 'INTEL' elif self.compiler == 'gfortran': self.compStr = 'GNU' elif self.compiler == 'pgf90': self.compStr = 'PGI' # endif compiler cmd = '%s%s%s' % (self.opSys, self.compStr, self.precision) cwd = os.getcwd() os.chdir('%s/build' % self.modelDir) print('Building %s' % self.modelStr) status = sub.call(['make', '-f', self.makeStr, cmd]) if status != 0: sys.exit('%s not built' % self.modelStr) os.chdir(cwd) return self
def main(): args = get_parser().parse_args() windows = os.name == 'nt' if windows: exeExtention = '.exe' pydExtention = '.pyd' rsync = None else: exeExtention = '' pydExtention = '.so' rsync = which('rsync') if rsync: rsync = Rsync(rsync) pids = [] zipDir = env['VIP_INSTALL_DIR'] if windows: zipDir = path_join(zipDir, 'vxl') #Cause that's how its done in windows... :( vxlBinDir = env['VIP_VXL_BUILD_BIN_DIR'] vxlLibDir = env['VIP_VXL_BUILD_LIB_DIR'] zipBinDir = path_join(zipDir, 'bin') zipRoamDir = path_join(zipDir, 'roam') zipPythonDir = path_join(zipDir, 'lib', 'python2.7', 'site-packages', 'vxl') zipShareDir = path_join(zipDir, 'share', 'vxl') zipClDir = path_join(zipShareDir, 'cl') pyscript_dirs = ['contrib/brl/bseg/boxm2/pyscripts', 'contrib/brl/bseg/boxm2_multi/pyscripts', 'contrib/brl/bseg/bstm/pyscripts', 'contrib/brl/bseg/bvxm/pyscripts'] pyscript_dirs = map(lambda x: path_join(env['VIP_VXL_SRC_DIR'], x), pyscript_dirs) cl_dirs = ['contrib/brl/bseg/boxm2/ocl/cl', 'contrib/brl/bseg/boxm2/reg/ocl/cl', 'contrib/brl/bseg/boxm2/vecf/ocl/cl', 'contrib/brl/bseg/boxm2/volm/cl', 'contrib/brl/bseg/bstm/ocl/cl'] cl_dirs = map(lambda x: path_join(env['VIP_VXL_SRC_DIR'], x), cl_dirs) cl_dest_dirs = ['boxm2', 'reg', 'vecf', 'volm', 'bstm'] cl_dest_dirs = map(lambda x: path_join(zipClDir, x), cl_dest_dirs) mkpath(zipBinDir) mkpath(zipPythonDir) mkpath(zipClDir) #bin files if not args.skip_bin: if rsync: pids.append(rsync.sync([path_join(vxlBinDir, '*'+exeExtention)], zipBinDir)) else: files = glob(path_join(vxlBinDir, '*'+exeExtention)) for file in files: copy_file(file, zipBinDir) #python libraries if rsync: pids.append(rsync.sync([path_join(vxlLibDir, '*'+pydExtention)] + map(lambda x: path_join(x, '*'), pyscript_dirs), zipPythonDir)) else: files = glob(path_join(vxlLibDir, '*'+pydExtention)) for file in files: copy_file(file, zipPythonDir) for d in pyscript_dirs: copy_tree(d, zipPythonDir) #setup python .pth so imports in vxl works without "vxl." with open(zipPythonDir+'.pth', 'w') as fid: fid.write('vxl') #cl files if rsync: for src, dest in zip(cl_dirs, cl_dest_dirs): pids.append(rsync.sync([src+'/'], dest)) else: for src, dest in zip(cl_dirs, cl_dest_dirs): copy_tree(src, dest) files = glob(path_join(env['VIP_VXL_SRC_DIR'], 'contrib', 'brl', 'bbas', 'volm', '*_*.txt')) for file in files: copy_file(file, zipShareDir) #wait for rsyncs to finish if rsync: for pid in pids: pid.wait() if windows: copy_file(path_join(env['VIP_GLEW_BIN_DIR'], 'glew32.dll'), zipBinDir) subprocess.Popen(['7z.exe', 'a', path_join(env['VIP_SRC_DIR'], 'vxl.zip'), 'vxl'], cwd=env['VIP_INSTALL_DIR']).wait(); else: mkpath(zipRoamDir) files = glob(path_join(vxlBinDir, '*'+exeExtention)) roamFile = path_join(zipRoamDir, 'roam') for file in files: try: os.link(roamFile, path_join(zipRoamDir, os.path.basename(file))) except OSError: pass
def __init__(self, cmd=None): if cmd: self.exe = cmd else: self.exe = which('rsync')
def ensure_executable(name): try: which(name) except: raise SystemExit(name + ' not found')
from .. import Commands if len(sys.argv) < 2: print("""Usage: %s <destdir> [mhWrap path] destdir - required: a destination directory for the links mhiWrap path - optional: path to mhiWrap. If unspecified, tries to find it on $PATH """) sys.exit(1) destdir = sys.argv[1] if len(sys.argv) > 2: mhiWrap = sys.argv[2] else: mhiWrap = which('mhiWrap') if mhiWrap == 'mhiWrap': print("Can't find mhiWrap on your path; you'll have to specify it.") sys.exit(1) # make the dir if it doesn't exist ; remove regular files there if needed if not os.path.isdir(destdir): if os.path.exists(destdir): os.remove(destdir) else: os.makedirs(destdir) if not os.path.isdir(destdir): print("Problem making the directory %r" % destdir) sys.exit(1)
cmd = ["python", "-c", "import sys; print '{}/share/shoebot/examples/'.format(sys.prefix)"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) output, errors = p.communicate() if errors: print('Could not find shoebot examples') print('Errors: {}'.format(errors)) return None else: examples_dir = output.decode('utf-8').strip() if os.path.isdir(examples_dir): return examples_dir else: print('Could not find shoebot examples at {}'.format(examples_dir)) if not which('sbot'): print('Shoebot executable not found.') _example_dir = find_example_dir() # regex taken from openuricontextmenu.py and slightly changed # to work with Python functions RE_DELIM = re.compile(r'[\w#/\?:%@&\=\+\.\\~-]+', re.UNICODE|re.MULTILINE) BASE_QUICKTORIAL_URL = "http://www.quicktorials.org/id/org.shoebot=en=0.3=%s" # function name -> quicktorial id mapping QUICKTORIAL_KEYWORDS = { 'rect': 'rect01', 'oval': 'ellipse01', 'var': 'var01'
def svnCheckout(url, revision, destination, cache=""): """ The cache system improves performance of initial branch builds on continuous integration""" svnDestination = destination ret = 0 useCache=False if cache: if(not os.access(destination+"/"+".svn", os.R_OK)): svnDestination = cache + "/" + re.sub("[.][.]/","/", destination) if not os.access(svnDestination, os.R_OK): os.makedirs(svnDestination) if not which(rsync): print("need rsync in the PATH to use the cache") exit(1) useCache=True print("Will use cache since this is an initial checkout") else: useCache=False print("Will not use cache, checkout has already been done") #cleanup in case the previous run failed os.system("svn cleanup " + svnDestination) # checkout to the final dest or to the cache if revision != "trunk": revParam = "-r " + revision revURL = "@"+revision else: revParam = "" revURL = "" if(not os.access(destination+"/"+".svn", os.R_OK)): print("svn checkout") ret = os.system("svn checkout " + svnoptions + " " + url + revURL + " " + svnDestination) else: print("svn update") # ignore conflicts # FIXME: should be an option #ret += os.system("svn resolve --accept theirs-full -R " + svnDestination) #ret += os.system("svn switch " + url + revURL + " " + svnDestination) #ret += os.system("svn update --accept theirs-full --force " + revParam + " " + svnDestination) ret += os.system("svn update " + svnoptions + " " + revParam + " " + svnDestination) if(ret != 0): print("Error updating SVN, will use fallback") os.rename(svnDestination, svnDestination + '.bak.'+datetime.datetime.now().strftime("%Y%m%d%H%M%S")) ret = os.system("svn checkout " + svnoptions + " " + url + revURL + " " + svnDestination) if(ret != 0): print("Fallback failed, exit") exit(1) if useCache: print("Copy the cache to the final destination") if not os.access(destination, os.R_OK): os.makedirs(destination) if hostOS == "win": command = rsync + " -avW --no-compress --chmod=ug=rwX \"" + \ re.sub(r"[\/\\ ]+","/",re.sub("([A-Za-z]):","/cygdrive/\\1",svnDestination)) + "/\" " + destination + "/" else: command = "cp -al " + svnDestination + " " + destination print("execute " + command) ret += os.system(command) return ret