def test(options, buildout): from subprocess import Popen, PIPE import os import sys python = options['python'] if not os.path.exists(python): raise IOError("There is no file at %s" % python) if sys.platform == 'darwin': output = Popen( [python, "-c", "import platform; print (platform.mac_ver())"], stdout=PIPE).communicate()[0] if not output.startswith("('10."): raise IOError( "Your python at %s doesn't return proper data for platform.mac_ver(), got: %s" % (python, output)) elif sys.platform == 'linux2' and (2, 4) <= sys.version_info < (2, 5): output = Popen( [python, "-c", "import socket; print (hasattr(socket, 'ssl'))"], stdout=PIPE).communicate()[0] if not output.startswith("True"): raise IOError( "Your python at %s doesn't have ssl support, got: %s" % (python, output)) output = Popen([python, "-c", "import readline; print (readline)"], stdout=PIPE).communicate()[0] # The leading escape sequence is sometimes printed by readline on import (see https://bugs.python.org/msg191824) if not output.lstrip("\x1b[?1034h").startswith("<module"): raise IOError( "Your python at %s doesn't have readline support, got: %s" % (python, output))
def check_python_path(): try: py_path_ver = Popen(['python', '-c', 'import platform;print(platform.python_version())'], stdout=PIPE, stderr=STDOUT, shell=True).communicate()[0].strip() print(" - The python version on your path is " + py_path_ver) except: print(" - Looks like python is not in your path...") return if py_path_ver.startswith('3'): print(" - You need to have python 2.7.X on your path to run the telemetry server using this script (python 3 won't work)") elif not py_path_ver.startswith('2'): print(" - The python executable on your path is messed up...")
def get_git_version(): """ Returns the project version as derived by git. """ path = os.path.dirname(__file__) branch = Popen(f'git -C "{path}" rev-parse --abbrev-ref HEAD', stdout=PIPE, shell=True).stdout.read().rstrip().decode('ascii') rev = Popen(f'git -C "{path}" describe --always --tags', stdout=PIPE, shell=True).stdout.read().rstrip().decode('ascii') if branch.startswith('fatal') or rev.startswith('fatal'): raise ValueError("Could not determine git version") return f"({branch}) {rev}"
def test_image_metadata( format, filename, meta_test, meta_test_cnv=None ): print print '---------------------------------------' print '%s - %s'%(format, filename) print '---------------------------------------' out_name = 'tests/_test_metadata_%s.ome.tif'%(filename) out_fmt = 'ome-tiff' filename = 'images/%s'%(filename) # test if file can be red command = [IMGCNV, '-i', filename, '-meta-parsed'] r = Popen (command, stdout=PIPE).communicate()[0] meta_org = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(meta_org)<=0: print_failed('loading metadata', format) return #print str(meta_org) # test if converted file has same info if compare_info(meta_org, meta_test)==True: print_passed('reading metadata') # convert the file into format command = [IMGCNV, '-i', filename, '-o', out_name, '-t', out_fmt] r = Popen (command, stdout=PIPE).communicate()[0] # get info from the converted file command = [IMGCNV, '-i', out_name, '-meta-parsed'] r = Popen (command, stdout=PIPE).communicate()[0] meta_cnv = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(meta_cnv)<=0: print_failed('loading written metadata', format) return else: print_passed('loading written metadata') #print str(meta_cnv) if meta_test_cnv is None: meta_test_cnv=meta_test if compare_info(meta_cnv, meta_test_cnv)==True: print_passed('writing metadata') print
def encode(self): """ Note: The output *needs* to have a different name than the original The tip for adding the "-g" flag: http://www.infinitecube.com/?p=9 """ version, _ = Popen(["ffmpeg", "-version"], stdout=PIPE, stderr=STDOUT).communicate() if version.startswith("ffmpeg version 1"): scale = "-qscale 0" else: scale = "-sameq" print "Running ffmpeg: encoding and creating keyframes" cmd = "ffmpeg -y -i %s -g %s " + scale + " %s" if self.h264: cmd = ("ffmpeg -y -i %s -vcodec libx264 -coder 0 -flags -loop" " -cmp +chroma -partitions -parti8x8-parti4x4-partp8x8-partb8x8" " -me_method dia -subq 0 -me_range 16 -g %s -keyint_min 25" " -sc_threshold 0 -i_qfactor 0.71 -b_strategy 0 -qcomp 0.6" " -qmin 10 -qmax 51 -qdiff 4 -bf 0 -refs 1 -directpred 1 -trellis 0" " -flags2 -bpyramid-mixed_refs-wpred-dct8x8+fastpskip-mbtree -wpredp" " 0 -aq_mode 0 -crf 30 %s") os.system(cmd % (self.filepath, self.framerate * self.seconds_per_keyframe, self.tempfilepath))
def main(): print "World of Warcraft LUA Unlocker (x86)" osx_version = Popen(["sw_vers", "-productVersion"], stdout=PIPE).communicate()[0] if not osx_version.startswith("10.9"): print "ERROR: OSX Mavericks is required!" sys.exit(1) if not os.path.exists(LLDB_BINARY): print "ERROR: Missing LLDB - Please Install Xcode Command Line Tools via 'xcode-select --install'" sys.exit(1) if len(sys.argv) != 2: print_usage() sys.exit(2) try: pid = int(sys.argv[1]) except ValueError: print "ERROR: Invalid PID '%s' - must be a number!" % sys.argv[1] print_usage() sys.exit(2) if pid not in get_all_wow_pids(): print "ERROR: %d is not a valid PID of a World of Warcraft Process!" % pid print_usage() sys.exit(2) try: print "Unlocking %d..." % pid lldb = LLDB(pid) print "...LUA unlocked!" lldb.wait_for_exit() except KeyboardInterrupt: print "\nExiting LUA Unlocker..." lldb.detach()
def test(options, buildout): from subprocess import Popen, PIPE import os import sys python = options['python'] if not os.path.exists(python): raise IOError("There is no file at %s" % python) if sys.platform == 'darwin': output = Popen([python, "-c", "import platform; print (platform.mac_ver())"], stdout=PIPE).communicate()[0] if not output.startswith("('10."): raise IOError("Your python at %s doesn't return proper data for platform.mac_ver(), got: %s" % (python, output)) elif sys.platform == 'linux2' and (2, 4) <= sys.version_info < (2, 5): output = Popen([python, "-c", "import socket; print (hasattr(socket, 'ssl'))"], stdout=PIPE).communicate()[0] if not output.startswith("True"): raise IOError("Your python at %s doesn't have ssl support, got: %s" % (python, output))
def getEncoding(self, scriptfile): out = Popen(['file', '--', scriptfile], stdout=PIPE).communicate()[0].decode('utf-8', 'replace') if out.startswith(scriptfile + ': Python script, ') and out.endswith(' text executable\n'): out = out[len(scriptfile + ': Python script, '):] out = out.split(' ')[0].lower() return out return None
def test_image_video( format, filename, meta_test ): print print '---------------------------------------' print '%s - %s'%(format, filename) print '---------------------------------------' out_name = 'tests/_test_metadata_%s.ome.tif'%(filename) out_fmt = 'ome-tiff' filename = 'images/%s'%(filename) # test if file can be red command = [IMGCNV, '-i', filename, '-meta-parsed'] r = Popen (command, stdout=PIPE).communicate()[0] meta_org = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(meta_org)<=0: print_failed('reading video', format) return #print str(meta_org) # test if converted file has same info if compare_info(meta_org, meta_test)==True: print_passed('reading video info') print
def get_block_device_names(self): data = Popen( "cat /proc/partitions | awk '{print $4}'", shell=True, stdout=PIPE ).stdout.read() if data.startswith('name'): data = data[4:] data = data.strip() return data.split('\n')
def call(self): unread_text = Popen(["newsbeuter", "-x", "print-unread"], stdout=PIPE).communicate()[0] if unread_text.startswith("Error:"): return unread_items = int(unread_text.split()[0]) if unread_items > 0: yield animate(10, "Newsbeuter: %d unread news." % (unread_items,)) else: yield animate(10, "Newsbeuter: No unread news.")
def _checkInstalled(name, cmdline, expected): try: out, err = Popen(cmdline, shell=False, stdout=PIPE, stderr=PIPE).communicate() out = (out + err).strip() if not out.startswith(expected): raise RuntimeError() except: raise RuntimeError(name + " does not appear to be installed")
def _java_installed(): # This alternative allows for java detection on Windows. try: p = Popen(["which", "java"], stdout=PIPE).stdout.readlines() found = len(p) != 0 except WindowsError: p = Popen('java -version', stderr=PIPE, stdout=PIPE).stderr.read() found = p.startswith('java version') return found
def _update_data(self): res = Popen(["watson", "status"], stdout=PIPE).communicate()[0] res = res.decode() if not res.startswith("No project started"): out = self._color_text(res.split()[1].strip(), fg=self.cfg.watson.color_fg, bg=self.cfg.watson.color_bg) else: out = "" return (self.__module__, self._out_format(out))
def test_video_write( format, filename ): print print '---------------------------------------' print '%s - %s'%(format, filename) print '---------------------------------------' out_name = 'tests/_test_writing_%s.%s'%(filename, format) out_fmt = format filename = 'images/%s'%(filename) # test if file can be red command = [IMGCNV, '-i', filename, '-info'] r = Popen (command, stdout=PIPE).communicate()[0] info_org = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(info_org)<=0: print_failed('loading input info', format) return # convert the file into format command = [IMGCNV, '-i', filename, '-o', out_name, '-t', out_fmt] r = Popen (command, stdout=PIPE).communicate()[0] # get info from the converted file command = [IMGCNV, '-i', out_name, '-info'] r = Popen (command, stdout=PIPE).communicate()[0] info_cnv = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(info_cnv)<=0: print_failed('loading written info', format) return else: print_passed('loading written info') # test if converted file has same info info_test = copy_keys(info_cnv, ('width', 'height')) if compare_info(info_org, info_test)==True: print_passed('written geometry') print
def test(options, buildout): from subprocess import Popen, PIPE import os import sys python = options['python'] if not os.path.exists(python): raise IOError("There is no file at %s" % python) if sys.platform == 'darwin': output = Popen([python, "-c", "import platform; print (platform.mac_ver())"], stdout=PIPE).communicate()[0] if not output.startswith("('10."): raise IOError("Your python at %s doesn't return proper data for platform.mac_ver(), got: %s" % (python, output))
def test(options, buildout): from subprocess import Popen, PIPE import os import sys python = options['python'] if not os.path.exists(python): raise IOError("There is no file at %s" % python) if sys.platform == 'darwin': output = Popen([python, "-c", "import platform; print (platform.mac_ver())"], stdout=PIPE).communicate()[0] if not output.startswith("('10."): raise IOError("Your python at %s doesn't return proper data for platform.mac_ver(), got: %s" % (python, output)) elif sys.platform == 'linux2' and (2, 4) <= sys.version_info < (2, 5): output = Popen([python, "-c", "import socket; print (hasattr(socket, 'ssl'))"], stdout=PIPE).communicate()[0] if not output.startswith("True"): raise IOError("Your python at %s doesn't have ssl support, got: %s" % (python, output)) output = Popen([python, "-c", "import readline; print (readline)"], stdout=PIPE).communicate()[0] # The leading escape sequence is sometimes printed by readline on import (see https://bugs.python.org/msg191824) if not output.lstrip("\x1b[?1034h").startswith("<module"): raise IOError("Your python at %s doesn't have readline support, got: %s" % (python,output))
def js_optimizer(filename, passes): if not check_engine(NODE_JS): raise Exception('Node.js appears to be missing or broken, looked at: ' + str(NODE_JS)) if type(passes) == str: passes = [passes] input = open(filename, 'r').read() output, err = Popen([NODE_JS, JS_OPTIMIZER] + passes, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate(input) assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + err + '\n\n' + output filename += '.jo.js' f = open(filename, 'w') f.write(output) f.close() return filename
def js_optimizer(filename, passes): if not check_engine(NODE_JS): raise Exception("Node.js appears to be missing or broken, looked at: " + str(NODE_JS)) if type(passes) == str: passes = [passes] # XXX Disable crankshaft to work around v8 bug 1895 output = Popen([NODE_JS, "--nocrankshaft", JS_OPTIMIZER, filename] + passes, stdout=PIPE).communicate()[0] assert len(output) > 0 and not output.startswith("Assertion failed"), "Error in js optimizer: " + output filename += ".jo.js" f = open(filename, "w") f.write(output) f.close() return filename
def js_optimizer(filename, passes): if not check_engine(NODE_JS): raise Exception('Node.js appears to be missing or broken, looked at: ' + str(NODE_JS)) if type(passes) == str: passes = [passes] # XXX Disable crankshaft to work around v8 bug 1895 output, err = Popen([NODE_JS, '--nocrankshaft', JS_OPTIMIZER, filename] + passes, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + err + '\n\n' + output filename += '.jo.js' f = open(filename, 'w') f.write(output) f.close() return filename
def js_optimizer(filename, passes): if not check_engine(NODE_JS): raise Exception('Node.js appears to be missing or broken, looked at: ' + str(NODE_JS)) if type(passes) == str: passes = [passes] # XXX Disable crankshaft to work around v8 bug 1895 output = Popen([NODE_JS, '--nocrankshaft', JS_OPTIMIZER, filename] + passes, stdout=PIPE).communicate()[0] assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + output filename += '.jo.js' f = open(filename, 'w') f.write(output) f.close() return filename
def __init__(self): # Need to find GNU time. If /usr/bin/time is not GNU time # then PUQ expects it to be in the path and called 'gtime' tstr = 'gtime' try: ver = Popen("/usr/bin/time --version", shell=True, stderr=PIPE).stderr.read() if ver.startswith("GNU"): tstr = '/usr/bin/time' except: pass #self.timestr = tstr + " -f \"HDF5:{'name':'time','value':%e,'desc':''}:5FDH\"" self.timestr="" #FR self.run_num = 0
def js_optimizer(filename, passes): if not check_engine(NODE_JS): raise Exception("Node.js appears to be missing or broken, looked at: " + str(NODE_JS)) if type(passes) == str: passes = [passes] input = open(filename, "r").read() output, err = Popen([NODE_JS, JS_OPTIMIZER] + passes, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate(input) assert len(output) > 0 and not output.startswith("Assertion failed"), ( "Error in js optimizer: " + err + "\n\n" + output ) filename += ".jo.js" f = open(filename, "w") f.write(output) f.close() return filename
def __init__(self): # Need to find GNU time. If /usr/bin/time is not GNU time # then PUQ expects it to be in the path and called 'gtime' tstr = 'gtime' try: ver = Popen("/usr/bin/time --version", shell=True, stderr=PIPE).stderr.read() if ver.startswith("GNU"): tstr = '/usr/bin/time' except: pass #self.timestr = tstr + " -f \"HDF5:{'name':'time','value':%e,'desc':''}:5FDH\"" self.timestr = "" #FR self.run_num = 0
def js_optimizer(filename, passes, maybe_big=True): if maybe_big: # When we split up, we cannot do unGlobalize, the only pass which is *not* function-local args = [filter(lambda p: p != 'unGlobalize', passes)] ret = Building.splitter(filename, addendum='.jo.js', func=Building.js_optimizer, args=args) if ret: return ret if type(passes) == str: passes = [passes] # XXX Use '--nocrankshaft' to disable crankshaft to work around v8 bug 1895, needed for older v8/node (node 0.6.8+ should be ok) output = Popen([NODE_JS, JS_OPTIMIZER, filename] + passes, stdout=PIPE).communicate()[0] assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + output filename += '.jo.js' f = open(filename, 'w') f.write(output) f.close() return filename
def print_completions(abs_path, call_line, pos_in_line): ''' Print completions at given cursor pos in given file to stdout: In order to do it, we make a modified copy of the file by @abs_path, and call simulation.py as a separate process, capture its output, and remove the file we created. ''' with open(abs_path) as in_file: lines = in_file.readlines() # TODO - normalize expression, if it spans multiple lines lines[call_line - 1] = inject_completions(lines[call_line - 1], pos_in_line) temp_py_file = abs_path.rsplit('.', 1)[0] + py_file_suffix + '.py' with open(temp_py_file, 'w') as out_file: out_file.writelines(lines) output = Popen(['python', simulation_abs_path, 'call_fn', temp_py_file, str(call_line), str(pos_in_line)], stdout = PIPE).communicate()[0] os.unlink(temp_py_file) if output.startswith(completions_list_prefix): print output.split('\n', 1)[1].strip()
def encode(self, downscale=False): """ Note: The output *needs* to have a different name than the original The tip for adding the "-g" flag: http://www.infinitecube.com/?p=9 """ version, _ = Popen(["ffmpeg", "-version"], stdout=PIPE, stderr=STDOUT).communicate() if version.startswith("ffmpeg version 1"): scale = "-qscale 0" else: scale = "-sameq" newsize = "" if downscale: DOWNSCALE_WIDTH = 1024 w, h = self._get_size(self.filepath) log.info("Downscaling enabled, orig video size %sx%s", w, h) if w and h and w > DOWNSCALE_WIDTH: new_w = DOWNSCALE_WIDTH new_h = int((new_w / float(w)) * h) # it needs to be divisiable by 2 if new_h % 2 != 0: new_h += 1 log.info("Size after downscaling %sx%s", new_w, new_h) newsize = "-s %sx%s " % (new_w, new_h) print "Running ffmpeg: encoding and creating keyframes" cmd = "ffmpeg -y -i %s -g %s " + scale + " %s%s" if self.h264: cmd = ("ffmpeg -y -i %s -vcodec libx264 -coder 0 -flags -loop" " -cmp +chroma -partitions -parti8x8-parti4x4-partp8x8-partb8x8" " -me_method dia -subq 0 -me_range 16 -g %s -keyint_min 25" " -sc_threshold 0 -i_qfactor 0.71 -b_strategy 0 -qcomp 0.6" " -qmin 10 -qmax 51 -qdiff 4 -bf 0 -refs 1 -directpred 1 -trellis 0" " -flags2 -bpyramid-mixed_refs-wpred-dct8x8+fastpskip-mbtree -wpredp" " 0 -aq_mode 0 -crf 30 %s%s") os.system(cmd % (self.filepath, self.framerate * self.seconds_per_keyframe, newsize, self.tempfilepath))
def _write_image_to_disk(image_file_path: Path, disk_number: int): print(f'Writing image from {image_file_path} to disk {disk_number}') um_response = Popen(['sudo', 'diskutil', 'unmountDisk', f'/dev/disk{disk_number}'], stderr=PIPE)\ .stderr.read().decode('ascii') if um_response.startswith(f'Unmount of disk{disk_number} failed:'): print(um_response) exit(1) time.sleep(0.1) # https://gist.github.com/hikoz/741643, though needed some tweaking for Python3 dd = Popen([ 'dd', 'bs=1m', f'if={image_file_path.absolute()}', f'of=/dev/rdisk{disk_number}' ], stderr=PIPE) # https://stackoverflow.com/a/10759061/1040915 poll_obj = select.poll() poll_obj.register(dd.stderr, select.POLLIN) try: while dd.poll() is None: time.sleep(.3) # Note - `SIGUSR1` if not on Mac dd.send_signal(signal.SIGINFO) poll_result = poll_obj.poll(2000) if poll_result: l = dd.stderr.readline().decode('ascii') if 'records in' in l: print(f'{l[:l.index("+")]} records, ', end='') if 'bytes' in l: print(f'{l.strip()}\r', end='') else: # No poll result break else: print(f'Image-write complete') except KeyboardInterrupt: # I don't _think_ this is necessary, but better safe than sorry! dd.kill() raise
def watson(self): res = Popen(["watson", "status"], stdout=PIPE).communicate()[0] res = res.decode() if not res.startswith("No project started"): out = res[0:res.index("(") - 1] out = " ".join(out.split()[1:]) out = out.replace(" started ", ": ") out = out.replace(" ago", "") out = out.strip() else: out = "No project" res = Popen("watson report --json -d".split(' '), stdout=PIPE).communicate()[0] doc = json.loads(res.decode()) seconds_today = int(doc['time']) hours = int(seconds_today / 3600) minutes = int((seconds_today % 3600) / 60) out += " ({}h{}m)".format(hours, minutes) return { 'full_text': out, 'cached_until': self.py3.time_in(30), }
def test_metadata_read( format, filename, meta_test ): print print '---------------------------------------' print '%s - %s'%(format, filename) print '---------------------------------------' filename = 'images/%s'%(filename) # test if file can be red command = [IMGCNV, '-i', filename, '-meta'] r = Popen (command, stdout=PIPE).communicate()[0] meta_org = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(meta_org)<=0: print_failed('reading meta-data', format) return # test if converted file has same info if compare_info(meta_org, meta_test)==True: print_passed('reading meta-data') print
import os import sys import glob from subprocess import Popen, PIPE from tqdm import tqdm # usage: python benchmark.py dataset_name dataset = sys.argv[1] # wiki_ts_200M_uint64 db_dataset=f"./data/{dataset}" assert os.path.exists(db_dataset), db_dataset # query="../data/{dataset}_queries_10M_in" for query in tqdm(sorted(glob.glob(db_dataset+"_*_test"))): query_name = os.path.basename(query) for i in range(3, 7): cmd=f"./build/benchmark {db_dataset} {query} 5 rmi ./rmi_data/baseline/{dataset}_{i}_PARAMETERS" print("====>running ", cmd, file=sys.stderr) outs, errs = Popen(cmd, shell=True, stdout=PIPE, universal_newlines=True).communicate() outs = outs.strip().split('\n')[-1] assert outs.startswith("RESULT"), outs print(outs[len("RESULT: "):]+","+query_name)
def screen_is_running(): out = Popen("screen -list", shell=True, stdout=PIPE).communicate()[0] return not out.startswith("No Sockets found")
def test_image_read( format, filename ): print print '---------------------------------------' print '%s - %s'%(format, filename) print '---------------------------------------' #------------------------------------------------------------------------ # reading and converting into TIFF #------------------------------------------------------------------------ out_name = 'tests/_test_converting_%s.tif'%(filename) thumb_name = 'tests/_test_thumbnail_%s.jpg'%(filename) out_fmt = 'tiff' filename = 'images/%s'%(filename) # test if file can be red command = [IMGCNV, '-i', filename, '-info'] r = Popen (command, stdout=PIPE).communicate()[0] info_org = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(info_org)<=0: print_failed('loading info', format) return else: print_passed('loading info') # convert the file into TIFF command = [IMGCNV, '-i', filename, '-o', out_name, '-t', out_fmt] r = Popen (command, stdout=PIPE).communicate()[0] # get info from the converted file command = [IMGCNV, '-i', out_name, '-info'] r = Popen (command, stdout=PIPE).communicate()[0] info_cnv = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(info_cnv)<=0: print_failed('loading converted info', format) return else: print_passed('loading converted info') # test if converted file has same info info_test = copy_keys(info_cnv, ('pages', 'channels', 'width', 'height', 'depth')) if compare_info(info_org, info_test)==True: print_passed('geometry') #------------------------------------------------------------------------ # Writing thumbnail #------------------------------------------------------------------------ command = [IMGCNV, '-i', filename, '-o', thumb_name, '-t', 'jpeg', '-depth', '8,d', '-page', '1', '-display', '-resize', '128,128,BC,AR'] r = Popen (command, stdout=PIPE).communicate()[0] command = [IMGCNV, '-i', thumb_name, '-info'] r = Popen (command, stdout=PIPE).communicate()[0] info_thb = parse_imgcnv_info(r) if r is None or r.startswith('Input format is not supported') or len(info_thb)<=0: print_failed('loading thumbnail info', format) return else: print_passed('loading thumbnail info') if compare_info( info_thb, {'pages':'1', 'channels':'3', 'depth':'8'} )==True: if compare_info(info_thb, {'width':'128', 'height':'128'}, InfoNumericLessEqual())==True: print_passed('thumbnail geometry') print
def screen_is_running(): out = Popen("screen -list",shell=True,stdout=PIPE).communicate()[0] return not out.startswith("No Sockets found")
def test_rosservice(self): # wait for network to initialize services = ['/add_two_ints', '/foo/add_two_ints', '/bar/add_two_ints'] for s in services: rospy.wait_for_service(s) cmd = 'rosservice' names = [ 'add_two_ints', '/add_two_ints', 'foo/add_two_ints', '/bar/add_two_ints' ] # list # - hard to exact match as we are still adding builtin services to nodes (e.g. set_logger_level) output = Popen([cmd, 'list'], stdout=PIPE).communicate()[0] l = set(output.split()) for s in services: self.assert_(s in l) for name in names: # args output = Popen([cmd, 'args', name], stdout=PIPE).communicate()[0] self.assertEquals('a b', output.strip()) # type output = Popen([cmd, 'type', name], stdout=PIPE).communicate()[0] self.assertEquals('test_rosmaster/AddTwoInts', output.strip()) # find output = Popen([cmd, 'find', 'test_rosmaster/AddTwoInts'], stdout=PIPE).communicate()[0] values = [v.strip() for v in output.split('\n') if v.strip()] self.assertEquals(set(values), set(services)) # uri output = Popen([cmd, 'uri', name], stdout=PIPE).communicate()[0] # - no exact answer self.assert_(output.startswith('rosrpc://'), output) # call output = Popen([cmd, 'call', '--wait', name, '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) output = Popen([cmd, 'call', name, '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) name = 'header_echo' # test with a Header so we can validate keyword args import yaml import time t = time.time() # test with empty headers for v in ['{}', '{header: {}}', '{header: {seq: 0}}']: output = Popen([cmd, 'call', name, v], stdout=PIPE).communicate()[0] output = output.strip() self.assert_(output, output) val = yaml.load(output)['header'] self.assertEquals('', val['frame_id']) self.assert_(val['seq'] >= 0) self.assertEquals(0, val['stamp']['secs']) self.assertEquals(0, val['stamp']['nsecs']) # test with auto headers for v in ['{header: auto}', '{header: {stamp: now}}']: output = Popen([cmd, 'call', name, v], stdout=PIPE).communicate()[0] val = yaml.load(output.strip())['header'] self.assertEquals('', val['frame_id']) self.assert_(val['seq'] >= 0) self.assert_(val['stamp']['secs'] >= int(t)) # verify that it respects ROS_NS # - the uris should be different as the names should resolve differently env = os.environ.copy() env['ROS_NAMESPACE'] = 'foo' uri1 = Popen([cmd, 'uri', 'add_two_ints'], stdout=PIPE).communicate()[0] uri2 = Popen([cmd, 'uri', 'add_two_ints'], env=env, stdout=PIPE).communicate()[0] self.assert_(uri2.startswith('rosrpc://')) self.assertNotEquals(uri1, uri2) # test_call_wait def task1(): output = Popen([cmd, 'call', '--wait', 'wait_two_ints', '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) timeout_t = time.time() + 5. t1 = TestTask(task1) t1.start() rospy.init_node('test_call_wait') rospy.Service("wait_two_ints", test_rosmaster.srv.AddTwoInts, lambda x: x.a + x.b) while not t1.done and time.time() < timeout_t: time.sleep(0.5) self.assert_(t1.success)
conflicts.append(st) elif st[0] != ' ': staged.append(st) status_message = Popen(['git','status',],stdout=PIPE).communicate()[0].decode("utf-8") status = '0' # print(status_message) if status_message.find('You are currently rebasing') >= 0: status = 'R' elif status_message.find('interactive rebase in progress') >= 0: status = 'iR' elif status_message.find('You are currently cherry-picking') >= 0: status = 'C' elif status_message.find('You are currently reverting') >= 0: status = 'Rv' elif status_message.startswith('On') and len(conflicts) > 0: status = 'S' out = ' '.join([ branch, str(ahead), str(behind), str(len(staged)), str(len(conflicts)), str(len(changed)), str(len(untracked)), status, str(local_branch), ]) print(out, end='')
def test_rosservice(self): # wait for network to initialize services = ['/add_two_ints', '/foo/add_two_ints', '/bar/add_two_ints'] for s in services: rospy.wait_for_service(s) cmd = 'rosservice' names = ['add_two_ints', '/add_two_ints', 'foo/add_two_ints', '/bar/add_two_ints'] # list # - hard to exact match as we are still adding builtin services to nodes (e.g. set_logger_level) output = Popen([cmd, 'list'], stdout=PIPE).communicate()[0] l = set(output.split()) for s in services: self.assert_(s in l) for name in names: # args output = Popen([cmd, 'args', name], stdout=PIPE).communicate()[0] self.assertEquals('a b', output.strip()) # type output = Popen([cmd, 'type', name], stdout=PIPE).communicate()[0] self.assertEquals('test_ros/AddTwoInts', output.strip()) # find output = Popen([cmd, 'find', 'test_ros/AddTwoInts'], stdout=PIPE).communicate()[0] values = [v.strip() for v in output.split('\n') if v.strip()] self.assertEquals(set(values), set(services)) # uri output = Popen([cmd, 'uri', name], stdout=PIPE).communicate()[0] # - no exact answer self.assert_(output.startswith('rosrpc://'), output) # call output = Popen([cmd, 'call', '--wait', name, '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) output = Popen([cmd, 'call', name, '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) # verify that it respects ROS_NS # - the uris should be different as the names should resolve differently env = os.environ.copy() env['ROS_NAMESPACE'] = 'foo' uri1 = Popen([cmd, 'uri', 'add_two_ints'], stdout=PIPE).communicate()[0] uri2 = Popen([cmd, 'uri', 'add_two_ints'], env=env, stdout=PIPE).communicate()[0] self.assert_(uri2.startswith('rosrpc://')) self.assertNotEquals(uri1, uri2) # test_call_wait def task1(): output = Popen([cmd, 'call', '--wait', 'wait_two_ints', '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) timeout_t = time.time() + 5. t1 = TestTask(task1) t1.start() rospy.init_node('test_call_wait') rospy.Service("wait_two_ints", test_ros.srv.AddTwoInts, lambda x: x.a + x.b) while not t1.done and time.time() < timeout_t: time.sleep(0.5) self.assert_(t1.success)
def metadata_read(filename): command = [IMGCNV, '-i', filename, '-meta'] r = Popen(command, stdout=PIPE).communicate()[0] if r is None or r.startswith('Input format is not supported'): return None return parse_imgcnv_info(r)
def test_rosservice(self): # wait for network to initialize services = ['/add_two_ints', '/foo/add_two_ints', '/bar/add_two_ints'] for s in services: rospy.wait_for_service(s) cmd = 'rosservice' names = ['add_two_ints', '/add_two_ints', 'foo/add_two_ints', '/bar/add_two_ints'] # list # - hard to exact match as we are still adding builtin services to nodes (e.g. set_logger_level) output = Popen([cmd, 'list'], stdout=PIPE).communicate()[0] l = set(output.split()) for s in services: self.assert_(s in l) for name in names: # args output = Popen([cmd, 'args', name], stdout=PIPE).communicate()[0] self.assertEquals('a b', output.strip()) # type output = Popen([cmd, 'type', name], stdout=PIPE).communicate()[0] self.assertEquals('test_ros/AddTwoInts', output.strip()) # find output = Popen([cmd, 'find', 'test_ros/AddTwoInts'], stdout=PIPE).communicate()[0] values = [v.strip() for v in output.split('\n') if v.strip()] self.assertEquals(set(values), set(services)) # uri output = Popen([cmd, 'uri', name], stdout=PIPE).communicate()[0] # - no exact answer self.assert_(output.startswith('rosrpc://'), output) # call output = Popen([cmd, 'call', '--wait', name, '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) output = Popen([cmd, 'call', name, '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) name = 'header_echo' # test with a Header so we can validate keyword args import yaml import time t = time.time() # test with empty headers for v in ['{}', '{header: {}}', '{header: {seq: 0}}']: output = Popen([cmd, 'call', name, v], stdout=PIPE).communicate()[0] val = yaml.load(output.strip())['header'] self.assertEquals('', val['frame_id']) self.assert_(val['seq'] >= 0) self.assertEquals(0, val['stamp']['secs']) self.assertEquals(0, val['stamp']['nsecs']) # test with auto headers for v in ['{header: auto}', '{header: {stamp: now}}']: output = Popen([cmd, 'call', name, v], stdout=PIPE).communicate()[0] val = yaml.load(output.strip())['header'] self.assertEquals('', val['frame_id']) self.assert_(val['seq'] >= 0) self.assert_(val['stamp']['secs'] >= int(t)) # verify that it respects ROS_NS # - the uris should be different as the names should resolve differently env = os.environ.copy() env['ROS_NAMESPACE'] = 'foo' uri1 = Popen([cmd, 'uri', 'add_two_ints'], stdout=PIPE).communicate()[0] uri2 = Popen([cmd, 'uri', 'add_two_ints'], env=env, stdout=PIPE).communicate()[0] self.assert_(uri2.startswith('rosrpc://')) self.assertNotEquals(uri1, uri2) # test_call_wait def task1(): output = Popen([cmd, 'call', '--wait', 'wait_two_ints', '1', '2'], stdout=PIPE).communicate()[0] self.assertEquals('sum: 3', output.strip()) timeout_t = time.time() + 5. t1 = TestTask(task1) t1.start() rospy.init_node('test_call_wait') rospy.Service("wait_two_ints", test_ros.srv.AddTwoInts, lambda x: x.a + x.b) while not t1.done and time.time() < timeout_t: time.sleep(0.5) self.assert_(t1.success)
#! /usr/bin/python from struct import calcsize from subprocess import Popen, PIPE from distutils.core import setup, Extension version = Popen(["git", "describe", "--tags"], stdout=PIPE).communicate()[0]\ .strip().decode("utf8") if len(version) == 0 or version.startswith('fatal'): version = '0.0.0' if calcsize("P") == 8: # 64-bit platform ext_modules = [ Extension( "curve25519._curve25519", ["curve25519module.c", "curve25519-donna-c64.c"], ) ] elif calcsize("P") == 4: # 32-bit platform ext_modules = [ Extension( "curve25519._curve25519", ["curve25519module.c", "curve25519-donna.c"], ) ] else: raise Exception( "This module is only supported on 32-bit and 64-bit platforms") short_description = "Python wrapper for the Curve25519 cryptographic library" long_description = """\
stdout=PIPE, stderr=PIPE).communicate()[0] behead = revlist.decode("utf-8").splitlines() ahead = len([x for x in behead if x[0] == '>']) behind = len(behead) - ahead status_message = Popen([ 'git', 'status', ], stdout=PIPE).communicate()[0].decode("utf-8") status = '0' # print(status_message) if status_message.find('You are currently rebasing') >= 0: status = 'R' elif status_message.find('You are currently cherry-picking') >= 0: status = 'C' elif status_message.startswith('On') and nb_U > 0: status = 'S' out = ' '.join([ branch, str(ahead), str(behind), staged, conflicts, changed, untracked, status, ]) print(out, end='')
try: from setuptools import setup except ImportError: from distutils.core import setup from subprocess import Popen, PIPE import boatd version = Popen(['git', 'describe'], stdout=PIPE).communicate()[0].decode('utf8') if not version.startswith(str(boatd.api.VERSION)): version = boatd.api.VERSION setup( name='boatd', version=version, author='Louis Taylor', author_email='*****@*****.**', description=('Experimental daemon to control an autonomous sailing robot'), license='LGPL', keywords='boat sailing wrapper rest', url='https://github.com/boatd/boatd', packages=['boatd'], scripts=['bin/boatd'], requires=['PyYAML'], install_requires=[ 'PyYAML >= 3.11' ], classifiers=[
tag = m.group (1) cmd = 'git describe --tags --dirty=-modified --match=%s' % tag break else : cmd = 'git status --porcelain' version = Popen (cmd.split (), stdout = PIPE).communicate () [0].strip () # No tags yet: if cmd.endswith ('porcelain') : for l in version.split ('\n') : if l.startswith ('??') : continue if l [0:2] != ' ' : v += '-modified' break version = v if version.startswith ('V_') or version.startswith ('V-') : version = version [2:] cmd = 'git log -n 1' log = Popen (cmd.split (), stdout = PIPE).communicate () [0].strip () for line in log.split ('\n') : if line.startswith ('Date:') : date = line.split (':', 1) [1].strip () break f = open ('pyspkac/version.py', 'w') print >> f, 'VERSION = "%s"' % version print >> f, 'DATE = "%s"' % date f.close () from pyspkac.version import VERSION setup \
def main(): parser = argparse.ArgumentParser( prog=__name__, description='a lightweight virtual environment manager.') parser.add_argument('--setuptools', default=True, action='store_true', dest='with_setuptools', help='Install setuptools in virtual environment.') parser.add_argument('--pip', default=True, action='store_true', dest='with_pip', help='Install pip in virtual environment.') parser.add_argument('--system_site_packages', default=False, action='store_true', dest='system_site_packages', help='Give access to system_site_packages.') use_symlinks = False if os.name == 'nt' else True parser.add_argument('--symlinks', default=use_symlinks, action='store_true', dest='symlinks', help='Use symlink rather than copy systm packages.') parser.add_argument( '--clear', default=False, action='store_true', dest='clear', help='Delete virtual environment contents if folder is exist.') parser.add_argument('--upgrade', default=False, action='store_true', dest='upgrade', help='Upgrade virtual environment python.') parser.add_argument('--verbose', default=False, action='store_true', dest='verbose', help='Display output from processing.') parser.add_argument('--rm', default=False, action='store_true', dest='remove', help='Remove virtual environment.') subparsers = parser.add_subparsers( title='Sub Commands', description='Sub commands for management of virtual environment.', help='sub commands help') group_install = subparsers.add_parser('install') group_install.add_argument('install', default=False, action='store_true', help='Install packages in virtual environment.') group_install.add_argument('install_cmds', metavar='cmds', nargs='+', help='Commands arguments for pip command.') group_list = subparsers.add_parser('list') group_list.add_argument( 'list', default=False, action='store_true', help='List install packages in virtual environment.') group_list.add_argument('-r', '--requirement', action='store_true', dest='rfile', help='Output to requirements.txt') group_upgrade = subparsers.add_parser('upgrade') group_upgrade.add_argument('upgrade', default=False, action='store_true', help='Upgrade packages in virtual environment.') group_upgrade.add_argument('upgrade_cmds', default='', nargs='*', help='Commands arguments for upgrade package.') group_uninstall = subparsers.add_parser('uninstall') group_uninstall.add_argument( 'uninstall', default=False, action='store_true', help='Uninstall packages in virtual environment.') group_uninstall.add_argument( 'uninstall_cmds', default='', nargs='*', help='Commands arguments for uninstall package') group_run = subparsers.add_parser('run') group_run.add_argument('run', default=False, action='store_true', help='Run command in virtual environment.') group_run.add_argument('run_cmds', default='', nargs='*', help='Commands arguments for run') group_shell = subparsers.add_parser('shell') group_shell.add_argument('shell', default='False', action='store_true', help='Spawn shell in virtual environment.') paraent_dir = user_cache_dir(APP_NAME, roaming=True if os.name == 'nt' else False) venv_location = paraent_dir / Path(get_venv_name()) options = parser.parse_args() venv_exists = venv_location.exists() if not venv_exists: builder = VenvBuilder( system_site_packages=options.system_site_packages, clear=options.clear, symlinks=options.symlinks, upgrade=options.upgrade, with_pip=options.with_pip, with_setuptools=options.with_setuptools, venv_name=venv_location, verbose=options.verbose) return 0 venv_name = venv_location if os.name == 'nt': venv_python = Path(venv_name) / 'Scripts' else: venv_python = Path(venv_name) / 'bin' venv_python = venv_location / venv_python exe = 'python.exe' if os.name == 'nt' else 'python' exe = str(venv_python / exe) if venv_python.exists(): sys.path.insert(0, venv_python) if hasattr(options, 'install') and options.install: params = [v for v in options.install_cmds if v.startswith('-')] packages = [p for p in options.install_cmds if not p.startswith('-')] cmd_args = [exe, '-m', 'pip', 'install'] + params + packages p = Popen(cmd_args) p.communicate() if p.returncode != 0: raise RuntimeError('install {} fail.'.format(','.join(packages))) elif hasattr(options, 'upgrade') and options.upgrade: params = [v for v in options.upgrade_cmds if v.startswith('-')] packages = [p for p in options.upgrade_cmds if not p.startswith('-')] cmd_args = [exe, '-m', 'pip', 'install', '-U'] + params + packages p = Popen(cmd_args) p.communicate() if p.returncode != 0: raise RuntimeError('upgrade {} fail.'.format(','.join(packages))) elif hasattr(options, 'list') and options.list: cmd_args = [exe, '-m', 'pip', 'freeze'] output = check_output(cmd_args, shell=True) if hasattr(options, 'rfile') and options.rfile: with open('requirements.txt', 'w') as f: f.write(output.decode('utf-8').replace('\r\n', '\n')) else: sys.stderr.write(output.decode('utf-8')) sys.stderr.flush() elif hasattr(options, 'uninstall') and options.uninstall: params = [v for v in options.uninstall_cmds if v.startswith('-')] packages = [p for p in options.uninstall_cmds if not p.startswith('-')] cmd_args = [ exe, '-m', 'pip', 'uninstall', ] + params + packages p = Popen(cmd_args) p.communicate() return p.returncode elif options.clear and options.upgrade: raise ValueError('Cannot --upgrade and --clear at the same time.') elif hasattr(options, 'run') and options.run: cmd_args = [v for v in options.run_cmds if len(v) != 0] env = os.environ.copy() env['PATH'] = str(venv_python) + ';' + env['PATH'] env['VIRTUAL_ENV'] = str(venv_python) if cmd_args[0] == 'pip' or cmd_args[0] == 'pip.exe': cmd_args[0] = str(venv_python / 'pip') if cmd_args[0] == 'python' or cmd_args[0] == 'python.exe': cmd_args[0] = str(venv_python / 'python') p = Popen(cmd_args, env=env) p.communicate() return p.returncode elif hasattr(options, 'shell') and options.shell: if os.environ.get('PYVENV', None) is not None: sys.stderr.write('Cannot use nested virtual environment shell.') sys.stderr.flush() return 1 env = os.environ.copy() env['PATH'] = str(venv_python) + ';' + env['PATH'] env['VIRTUAL_ENV'] = str(venv_python) if os.name == 'nt': env['PROMPT'] = str(venv_python) + ' (pyvenv):' shell = env.get('COMSPEC', None) else: env['PS1'] = str(venv_python) + ' (pyvenv):' shell = env.get('SHELL', None) if shell is None: raise RuntimeError('Shell not found.') env['PYVENV'] = '1' p = Popen([ shell, ], env=env) p.communicate() return p.returncode elif options.remove: if Path(venv_name).exists(): shutil.rmtree(str(venv_location)) sys.stderr.write( 'Remove virtual environment {}.\n'.format(venv_name)) sys.stderr.flush() else: sys.stderr.write('Virtual environment not exists.\n') sys.stderr.flush() return 0