def launchCommand(self, cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=None, nice=0): """Execute a program in a new process Args: command: a string representing a unix command to execute stdout: this attribute is a file object that provides output from the child process stderr: this attribute is a file object that provides error from the child process timeout: Number of seconds before a process is consider inactive, usefull against deadlock nice: run cmd with an adjusted niceness, which affects process scheduling Returns return a 3 elements tuples representing the command execute, the standards output and the standard error message Raises OSError: the function trying to execute a non-existent file. ValueError : the command line is called with invalid arguments """ binary = cmd.split(" ").pop(0) if util.which(binary) is None: self.error("Command {} not found".format(binary)) self.info("Launch {} command line...".format(binary)) self.info("Command line submit: {}".format(cmd)) (executedCmd, output, error)= util.launchCommand(cmd, stdout, stderr, timeout, nice) if not (output is "" or output is "None" or output is None): self.info("Output produce by {}: {} \n".format(binary, output)) if not (error is '' or error is "None" or error is None): self.info("Error produce by {}: {}\n".format(binary, error)) self.info("------------------------\n")
def __correctionEddy(self, source, mask, topup, index, acqp, bVecs, bVals): """Performs eddy correction on a dwi file. Args: source: File containing all the images to estimate distortions for mask: Mask to indicate brain topup: Base name for output files from topup index: File containing indices for all volumes in --imain into --acqp and --topup acqp: File containing acquisition parameters bvecs: File containing the b-vectors for all volumes in --imain bvals: File containing the b-values for all volumes in --imain Returns: The resulting file name """ self.info("Launch eddy correction from fsl") tmp = self.buildName(source, "tmp") target = self.buildName(source, "eddy") if util.which('eddy_openmp_patch'): cmd = "eddy_openmp_patch --imain={} --mask={} --index={} --acqp={} --bvecs={} --bvals={} --out={} --data_is_shelled " \ .format(source, mask, index, acqp, bVecs, bVals, tmp) else: cmd = "eddy_openmp --imain={} --mask={} --index={} --acqp={} --bvecs={} --bvals={} --out={} " \ .format(source, mask, index, acqp, bVecs, bVals, tmp) if topup is not None: cmd += " --topup={}".format(topup) self.getNTreadsEddy() self.launchCommand(cmd, nice=5*60*60) return self.rename(tmp, target)
def __correctionEddy(self, source, mask, topup, index, acqp, bVecs, bVals): """Performs eddy correction on a dwi file. Args: source: File containing all the images to estimate distortions for mask: Mask to indicate brain topup: Base name for output files from topup index: File containing indices for all volumes in --imain into --acqp and --topup acqp: File containing acquisition parameters bvecs: File containing the b-vectors for all volumes in --imain bvals: File containing the b-values for all volumes in --imain Returns: The resulting file name """ self.info("Launch eddy correction from fsl") tmp = self.buildName(source, "tmp") target = self.buildName(source, "eddy") if util.which('eddy_openmp_patch'): cmd = "eddy_openmp_patch --imain={} --mask={} --index={} --acqp={} --bvecs={} --bvals={} --out={} --data_is_shelled " \ .format(source, mask, index, acqp, bVecs, bVals, tmp) else: cmd = "eddy_openmp --imain={} --mask={} --index={} --acqp={} --bvecs={} --bvals={} --out={} " \ .format(source, mask, index, acqp, bVecs, bVals, tmp) if topup is not None: cmd += " --topup={}".format(topup) self.getNTreadsEddy() self.launchCommand(cmd, nice=5 * 60 * 60) return self.rename(tmp, target)
def launchCommand(self, cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, nice=0): """Execute a program in a new process Args: command: a string representing a unix command to execute stdout: this attribute is a file object that provides output from the child process stderr: this attribute is a file object that provides error from the child process nice: run cmd with an adjusted niceness, which affects process scheduling Returns return a 3 elements tuples representing the command execute, the standards output and the standard error message Raises OSError: the function trying to execute a non-existent file. ValueError : the command line is called with invalid arguments """ binary = cmd.split(" ").pop(0) if util.which(binary) is None: self.error("Command {} not found".format(binary)) self.info("Launch {} command line...\n".format(binary)) self.info("Command line submit: {}\n".format(cmd)) out = None err = None if stdout == 'log': out = self.getLog() self.info("Output will be log in {} \n".format(out.name)) if stderr == 'log': err = self.getLog() self.info("Error will be log in {} \n".format(err.name)) (output, error) = util.launchCommand(cmd, out, err, nice) if stdout is not "None": self.info("Output produce by {}: {} \n".format(binary, output)) if error != '' or error != "None": self.info("Error produce by {}: {}\n".format(binary, error)) self.info("------------------------\n")
def launchCommand(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=None, nice=0): import sys sys.path.append('/home/grg/toad') from lib import util """Execute a program in a new process Args: command: a string representing a unix command to execute stdout: this attribute is a file object that provides output from the child process stderr: this attribute is a file object that provides error from the child process timeout: Number of seconds before a process is consider inactive, usefull against deadlock nice: run cmd with an adjusted niceness, which affects process scheduling Returns return a 3 elements tuples representing the command execute, the standards output and the standard error message Raises OSError: the function trying to execute a non-existent file. ValueError : the command line is called with invalid arguments """ binary = cmd.split(" ").pop(0) if util.which(binary) is None: print("Command {} not found".format(binary)) print("Launch {} command line...".format(binary)) print("Command line submit: {}".format(cmd)) (executedCmd, output, error) = util.launchCommand(cmd, stdout, stderr, timeout, nice) if not (output is "" or output is "None" or output is None): print("Output produce by {}: {} \n".format(binary, output)) if not (error is '' or error is "None" or error is None): print("Error produce by {}: {}\n".format(binary, error))
dirs = '- ' + err.strerror + '\n' for entry in listing: absolute = os.path.join(target, entry) if os.path.isdir(absolute): dirs += '+ %s/\n' % entry else: entry = slash(entry, '\\+$-') files += '%s\n' % entry output = (dirs + files) or '\n' elif sign == '-': # dunno here pass elif tree: if which('ruby'): cmd = ['ruby', which('xiki')] else: cmd = ['xiki'] cmd += tree.split(' ') if cmd: if persist: insert(view, edit, sel, '', indent + INDENTATION) spawn(view, edit, indent, cmd, sel) else: output = communicate(cmd, None, 3, return_error=True) if oldcwd: os.chdir(oldcwd)
sys.path.append( os.path.join(os.path.dirname(os.path.realpath(__file__)), '../..')) print os.path.join(os.path.dirname(os.path.realpath(__file__)), '..') from lib import util __author__ = "Guillaume Valet" __copyright__ = "Copyright (C) 2014, TOAD" __credits__ = ["Guillaume Valet", "Mathieu Desrosiers"] # Run this script from its own directory cwd = os.getcwd() if not 'toad/doc/toad' in cwd: print "Please Run this script from its own directory, toad/doc/toad" sys.exit() pandoc = util.which("pandoc") if pandoc is None: print("pandoc not found. Please install the package") sys.exit() # French version target_dir = 'src/fr/tuto/' target_file = '../../../Toad_Tuto_fr.pdf' header = '../../../head_tuto_fr' tpl = '../../../../doc_latex.template' os.chdir(target_dir) print(os.getcwd()) cmd = "pandoc -s -S %s *.md -o %s --template=%s --number-sections" % ( header, target_file, tpl) print cmd os.system(cmd)
def xiki(view): settings = view.settings() output = None cmd = None oldcwd = None if settings.get('xiki'): indent, sign, path, tag, tree = find_tree(view) print 'xiki', sign, path, tree pos = get_pos(view) if get_line(view, 1).startswith(indent + INDENTATION): if sign == '-': replace_line(view, pos, indent + '+ ' + tag) edit = view.begin_edit() cleanup(view, edit, pos, indent + INDENTATION) select(view, pos) view.end_edit(edit) return elif sign == '$': if path: oldcwd = os.getcwd() # maybe this should be offloaded into find_tree # so path will be multiple directories instead of just a base dir path_re = r'^(.+)/%s$' % re.escape(tag) match = re.match(path_re, tree) if match: os.chdir(os.path.join(path, match.group(1))) else: os.chdir(path) cmd = shlex.split(tag.encode('ascii', 'replace'), True) elif path: # directory listing or file open target = os.path.join(path, tree) if os.path.isfile(target): sublime.active_window().open_file(target) return elif os.path.isdir(target): dirs = '' files = '' for entry in os.listdir(target): absolute = os.path.join(target, entry) if os.path.isdir(absolute): dirs += '+ %s/\n' % entry else: files += '%s\n' % entry output = (dirs + files) or '\n' elif sign == '-': # dunno here return elif tree: if which('ruby'): cmd = ['ruby', which('xiki')] else: cmd = ['xiki'] cmd += tree.split(' ') if cmd: output = communicate(cmd, None, 3, return_error=True) if oldcwd: os.chdir(oldcwd) if output: if sign == '+': replace_line(view, pos, indent + '- ' + tag) insert(view, output, indent + INDENTATION)
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../..')) print os.path.join(os.path.dirname(os.path.realpath(__file__)), '..') from lib import util __author__ = "Guillaume Valet" __copyright__ = "Copyright (C) 2014, TOAD" __credits__ = ["Guillaume Valet", "Mathieu Desrosiers"] # Run this script from its own directory cwd = os.getcwd() if not 'toad/doc/toad' in cwd: print "Please Run this script from its own directory, toad/doc/toad" sys.exit() pandoc = util.which("pandoc") if pandoc is None: print("pandoc not found. Please install the package") sys.exit() # French version target_dir = 'src/fr/tuto/' target_file = '../../../Toad_Tuto_fr.pdf' header = '../../../head_tuto_fr' tpl = '../../../../doc_latex.template' os.chdir(target_dir) print(os.getcwd()) cmd = "pandoc -s -S %s *.md -o %s --template=%s --number-sections" % (header, target_file, tpl) print cmd os.system(cmd)