from subprocess import Popen, PIPE with open("README.asciidoc", "r") as fin: with open("README", "w") as fout: fout.write(fin.read()) try: # Attempt to try and get the version string using 'git describe'. cmd = "git describe --abbrev=8 --dirty" ver = Popen(cmd.split(), stdout=PIPE).communicate()[0].strip() except: # Not in a Git repository. ver = None else: # Check if the checkout is dirty. if ver.endswith("dirty"): ver = ver[:-5] + time.strftime("%Y%m%d%H%M") # Write the version string to '__version__.py' with open("__version__.py", "w") as f: f.write("# this file is autogenerated by setup.py\n") f.write('version = "{0}"\n'.format(ver)) try: # Try to get the version number from __version__.py import __version__ ver = __version__.version except ImportError: # Import failed, version is unknown. ver = "unknown"
def test_offline(self): cmd = 'rostopic' # point at a different 'master' env = os.environ.copy() env['ROS_MASTER_URI'] = 'http://localhost:11312' kwds = {'env': env, 'stdout': PIPE, 'stderr': PIPE} msg = "ERROR: Unable to communicate with master!" + os.linesep output = Popen([cmd, 'bw', 'chatter'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg)) output = Popen([cmd, 'echo', 'chatter'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg)) output = Popen([cmd, 'hz', 'chatter'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg)) output = Popen([cmd, 'delay', 'chatter'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg)) output = Popen([cmd, 'list'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg)) output = Popen([cmd, 'pub', 'chatter', 'std_msgs/String', 'hello'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg)) output = Popen([cmd, 'type', 'chatter'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg)) output = Popen([cmd, 'type', 'std_msgs/String'], **kwds).communicate()[1].decode() self.assert_(output.endswith(msg))
def append_content_if_needed(path, content): """ Ensure the file has the desired content, if not the content is appended. """ # Bail out if the current file content if os.path.exists(path): user_sudo = True current_content = Popen(['cat', path], capture=True, force_sudo=use_sudo).communicate[0] if current_content.count(content) > 0: return else: use_sudo = True current_content = '' # Work with our temporary file with temporary_file() as fobj: if len(current_content): if current_content.endswith('\n'): new_content = current_content + content else: new_content = current_content + '\n' + content else: new_content = content fobj.write(new_content) fobj.flush() Popen(['cp', fobj.path, path], force_sudo=use_sudo).comunicate[0]
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 spawn_pipe(*command): ''' Spawn an external process and read its output @param command:*str The command arguments @return :str The output to the command's stdout, with at most one trailing LF removed ''' out = Popen(command, stdin = sys.stdin, stdout = PIPE, stderr = sys.stderr).communicate()[0] out = out.decode('utf-8', 'replace') return out[:-1] if out.endswith('\n') else out
def spawn_pipe(*command): ''' Spawn an external process and read its output @param command:*str The command arguments @return :str The output to the command's stdout, with at most one trailing LF removed ''' out = Popen(command, stdin=sys.stdin, stdout=PIPE, stderr=sys.stderr).communicate()[0] out = out.decode('utf-8', 'replace') return out[:-1] if out.endswith('\n') else out
def sha3override(self, filename): ''' Calculate the hash sum of an entire file @param filename:str The filename of which to calculate the hash @return :str The hash sum in uppercase hexadecimal ''' hashsum = Popen(['spike-ckeccak', filename], stdout = PIPE).communicate()[0] hashsum = hashsum.decode('utf-8', 'error') if hashsum.endswith('\n'): hashsum = hashsum[:-1] if '*' in hashsum: return sha3override_old(self, filename) return hashsum
def expand_signature(sig): if not sig: return u'' output = '' enc = locale.getpreferredencoding() if sig.endswith(u'|'): output = Popen(sig[:-1], shell=True, stdout=PIPE).communicate()[0] else: try: f = open(os.path.expanduser(sig), 'r') output = f.read() except IOError: pass else: f.close() output = unicode(output, enc) if output.endswith(u'\n'): output = output[:-1] return output
def clipboard_get(self, reg): if reg in selections: txt = Popen(['xclip', '-selection', selections[reg], '-o'], stdout=PIPE).communicate()[0] # emulate vim behavior if txt.endswith('\n'): txt = txt[:-1] regtype = 'V' else: regtype = 'v' return txt.split('\n'), regtype else: if self.choice is not None: c = self.choice self.choice = None return c with HistoryFile(hfile) as hlist: if len(hlist) == 0: return '' return hlist[0]