def props(self): # {{{2 # type: () -> Tuple[List[bool], List[int]] cmd = [self.cmd_bin, self.cmd_wat, str(self.dev)] curs = common.check_output(cmd) _btns = {} # type: Dict[int, bool] _vals = {} # type: Dict[int, int] for line in curs.splitlines(): line = line.strip() if line.startswith("button"): try: l, r = line.split("=") idx = int(line.split("[")[1].split("]")[0]) - 1 _btns[idx] = True if r == "down" else False except: pass continue if line.startswith("valuator"): try: l, r = line.split("=") idx = int(line.split("[")[1].split("]")[0]) _vals[idx] = int(r) except: pass continue btns = [_btns.get(i, False) for i in range(max(_btns.keys()) + 1)] vals = [_vals.get(i, 0) for i in range(max(_vals.keys()) + 1)] return btns, vals
def __init__(self, ros_distro, sudo=False, no_chroot=False): self.r2a = {} self.a2r = {} self.env = os.environ self.env['ROS_DISTRO'] = ros_distro if no_chroot: print("Skip initializing and updating rosdep database") else: print("Ininitalize rosdep database") apt_get_install(['lsb-release', 'python-rosdep'], sudo=sudo) try: call("rosdep init", self.env) except: print("Rosdep is already initialized") call("rosdep update", self.env) print("Building dictionaries from a rosdep's db") raw_db = check_output("rosdep db", self.env, verbose=False).split('\n') for entry in raw_db: split_entry = entry.split(' -> ') if len(split_entry) < 2: continue ros_entry = split_entry[0] if split_entry[1]: apt_entries = split_entry[1].split(' ') else: apt_entries = [] self.r2a[ros_entry] = apt_entries for a in apt_entries: self.a2r[a] = ros_entry
def _gen_agentid(self): aid = None if ostype() in [OSType.WIN, OSType.SUNOS]: aid = self._hostname else: aid = check_output(['hostid']).strip() logging.info('agent id %s generated for %s', aid, self._hostname) return aid
def export(cls, rev, path): os.mkdir(path) cmd1 = ['git', 'archive', rev] data = common.check_output(cmd1, cwd=cls.main_path) cmd2 = ['tar', '-x', '-C', path] p = subprocess.Popen(cmd2, stdin=subprocess.PIPE) p.communicate(data) if p.returncode != 0: raise subprocess.CalledProcessError(p.returncode, cmd2)
def make_translation_memory(lang): locale_dir = os.path.join(os.getcwd(), 'modules') glob_path = os.path.join(locale_dir, '*', 'locale', lang + '.po') dst_file = os.path.join('/tmp', str(uuid.uuid4())) + ".po" entries = [] po = polib.POFile() po.metadata = { 'Project-Id-Version': '1.0', 'Report-Msgid-Bugs-To': '*****@*****.**', 'Language-Team': 'English <*****@*****.**>', 'MIME-Version': '1.0', 'Content-Type': 'text/plain; charset=utf-8', 'Content-Transfer-Encoding': '8bit', } for src_file in glob.glob(glob_path): pot = polib.pofile(src_file) entries += pot.translated_entries() entries += pot.fuzzy_entries() entries += pot.obsolete_entries() terms = [] for e in entries: if e.msgid == e.msgstr: continue keys = re.findall('\%\(\w+\)s',e.msgid) for key in keys: po.append(polib.POEntry( msgid=key, msgstr=key)) term = (e.msgid, e.msgstr) if term not in terms: terms.append(term) if e.flags: e.flags.remove('fuzzy') po.append(e) po.save(dst_file) check_output(['po2tmx', '-l', lang[:2], '-i', dst_file, '-o', 'en-%s.tmx' % lang[:2]])
def generate_messages_catkin(env): try: targets = check_output("make help", env).split('\n') except BuildException: return genpy_targets = [t.split()[1] for t in targets if t.endswith("genpy")] print(genpy_targets) for t in genpy_targets: call("make %s" % t, env)
def generate_messages_catkin(env): try: targets = check_output("make help", env).split('\n') except BuildException: return genpy_targets = [t.split()[1] for t in targets if t.endswith("genpy")] print genpy_targets for t in genpy_targets: call("make %s" % t, env)
def get_repo_revision(repo_folder, vcs_type): #Make sure we're in the right directory old_dir = os.getcwd() os.chdir(repo_folder) if vcs_type == 'git': rev = check_output("git rev-parse HEAD").split('\n')[0] elif vcs_type == 'hg': rev = check_output("hg id -i").split('\n')[0] elif vcs_type == 'bzr': rev = check_output("bzr revno").split('\n')[0] elif vcs_type == 'svn': rev = check_output("svnversion").split('\n')[0] else: rev = "" print >> sys.stderr, "Don't know how to get the version for vcs_type %s, doc generation will always run" % vcs_type #Make sure we go back to the original dir os.chdir(old_dir) return rev
def prop_get(self, key): # {{{1 # type: (int) -> List[Text] curs = common.check_output(self.cmd_shw + [Text(self.dev)]) for line in curs.splitlines(): if "({}):".format(key) in line: curs = line break else: return [] assert key > 0 seq = curs.split(":")[1].split(",") return [i.strip() for i in seq]
def get_touchpad_id(cls): # type: () -> Text _id = "" for line in common.check_output(["xinput"]).splitlines(): if "Touchpad" not in line: continue seq = line.split("\t") for src in seq: if not src.startswith("id="): continue _id = src.replace("id=", "") return _id return ""
def _get_cmd_result(self, cmd): """ Execute cmd on local OS and return output of cmd :param cmd: :return: result string """ result = 'NOT COLLECTED' try: result = check_output(cmd) except Exception: logging.exception('call cmd %s failed', cmd) result = 'call cmd %s failed.' % cmd return result
def determine_devid(cls): # cls {{{2 # type: () -> int seq = common.check_output([cls.cmd_bin, "list"]).splitlines() seq = [s for s in seq if "touchpad" in s.lower()] if len(seq) < 1: return True curs = seq[0].strip() if "id=" not in curs: return True curs = curs[curs.find("id="):] curs = curs[3:] curs = curs.split("\t")[0] # TODO: use regex for more robust operation ret = int(curs) return ret
def cmdreport(self): # {{{2 # type: () -> None import sys import platform from datetime import datetime fname = datetime.now().strftime("report-%Y%m%d-%H%M%S.txt") fp = open_file(fname, "a") msg = common.check_output(["uname", "-a"]) fp.write(msg + "\n") msg = common.check_output(["python3", "-m", "platform"]) fp.write(msg + "\n") fp.write("Python: {}\n".format(str(sys.version_info))) if sys.version_info[0] == 2: sbld = platform.python_build() # type: ignore scmp = platform.python_compiler() # type: ignore else: sbld = platform.python_build() scmp = platform.python_compiler() fp.write("Python: {} {}\n".format(sbld, scmp)) msg = common.check_output(["xinput", "list"]) fp.write(msg + u"\n") msg = common.check_output(["xinput", "list-props", Text(xi.dev)]) fp.write(msg + u"\n") fp.write(u"\n\n--- current settings (in app)---\n") fp.write(xi.dumps()) fp.write(u"\n\n--- initial settings (at app startup)---") cmds = u"" for i in cmdorg: cmds += u"\n" + u" ".join(i) fp.write(cmds + "\n") fp.close() msg = u"Report: {} was made,\n" \ u"use this file to report a issue.".format(fname) messagebox.showinfo(u"Make a Report", msg)
def commit_db(self, exclude=[]): if not 'tags' in exclude: self.write_folder('tags', self.tags) if not 'deps' in exclude: self.write_folder('deps', self.forward_deps) if not 'metapackages' in exclude: self.write_folder('metapackages', self.metapackages) if not 'rosinstall_hashes' in exclude: self.write_folder('rosinstall_hashes', self.rosinstall_hashes) old_dir = os.getcwd() os.chdir(self.path) changes = check_output('git status -s').strip() if changes: print("Commiting changes to tags and deps lists....") call("git add %s" % os.path.join(self.path, self.distro_name)) command = [ 'git', '-c', 'user.name=jenkins.ros.org', 'commit', '-m', 'Updating tags and deps lists for %s' % (self.distro_name) ] call_with_list(command) env = os.environ env['GIT_SSH'] = "%s/git_ssh" % self.jenkins_scripts_path #Have some tolerance for things commiting to the db at the same time num_retries = 3 i = 0 while True: try: call("git fetch origin", env) call("git merge origin/master", env) call("git push origin master", env) except BuildException as e: print("Failed to fetch and merge...") if i >= num_retries: raise e time.sleep(2) i += 1 print("Trying again attempt %d of %d..." % (i, num_retries)) continue break else: print('No changes to tags and deps lists') os.chdir(old_dir)
def generate_messages_dry(env, name, messages, services): try: targets = check_output("make help", env).split('\n') except BuildException: return if [t for t in targets if t.endswith("ROSBUILD_genaction_msgs")]: call("make ROSBUILD_genaction_msgs", env) if [t for t in targets if t.endswith("rospack_genmsg")] and messages: call("make rospack_genmsg", env) print("Generated messages for %s" % name) if [t for t in targets if t.endswith("rospack_gensrv")] and services: call("make rospack_gensrv", env) print("Generated services for %s" % name)
def generate_messages_dry(env, name, messages, services): try: targets = check_output("make help", env).split('\n') except BuildException: return if [t for t in targets if t.endswith("ROSBUILD_genaction_msgs")]: call("make ROSBUILD_genaction_msgs", env) if [t for t in targets if t.endswith("rospack_genmsg")] and messages: call("make rospack_genmsg", env) print "Generated messages for %s" % name if [t for t in targets if t.endswith("rospack_gensrv")] and services: call("make rospack_gensrv", env) print "Generated services for %s" % name
def commit_db(self, exclude=[]): if not 'tags' in exclude: self.write_folder('tags', self.tags) if not 'deps' in exclude: self.write_folder('deps', self.forward_deps) if not 'metapackages' in exclude: self.write_folder('metapackages', self.metapackages) if not 'rosinstall_hashes' in exclude: self.write_folder('rosinstall_hashes', self.rosinstall_hashes) old_dir = os.getcwd() os.chdir(self.path) changes = check_output('git status -s').strip() if changes: print("Commiting changes to tags and deps lists....") call("git add %s" % os.path.join(self.path, self.distro_name)) command = ['git', '-c', 'user.name=jenkins.ros.org', 'commit', '-m', 'Updating tags and deps lists for %s' % (self.distro_name)] call_with_list(command) env = os.environ env['GIT_SSH'] = "%s/git_ssh" % self.jenkins_scripts_path #Have some tolerance for things commiting to the db at the same time num_retries = 3 i = 0 while True: try: call("git fetch origin", env) call("git merge origin/master", env) call("git push origin master", env) except BuildException as e: print("Failed to fetch and merge...") if i >= num_retries: raise e time.sleep(2) i += 1 print("Trying again attempt %d of %d..." % (i, num_retries)) continue break else: print('No changes to tags and deps lists') os.chdir(old_dir)
def oom(args): oom = [] retcode, result = common.check_output( ["grep -i 'killed process' /var/log/messages"], shell=True) if not retcode: current_year = time.strftime("%Y") if args['--period']: time_start = time.time() - 60 * int(args['--period']) for row in reversed(result.strip().split("\n")): if time.mktime( time.strptime(current_year + ' ' + row[:15], '%Y %b %d %H:%M:%S')) > time_start: oom.append(row) else: break else: for row in reversed(result.strip().split("\n")): oom.append(row) return oom
def __init__(self, ros_distro, sudo=False, no_chroot=False, additional_rosdeps=None): self.r2a = {} self.a2r = {} self.env = os.environ self.env['ROS_DISTRO'] = ros_distro if no_chroot: print("Skip initializing and updating rosdep database") else: print("Initialize rosdep database") apt_get_install(['lsb-release', 'python-rosdep'], sudo=sudo) try: call("rosdep init", self.env) except: print("Rosdep is already initialized") if additional_rosdeps: print("Installing additional rosdeps") for (k, v) in additional_rosdeps.items(): print(" Installing additional rosdeps %s into %s" % (v, k)) dn = os.path.dirname(k) call("mkdir -p %s" % dn, self.env) call( "curl -o %s %s" % ( k, v), self.env) call("rosdep update", self.env) print("Building dictionaries from a rosdep's db") raw_db = check_output("rosdep db", self.env, verbose=False).split('\n') for entry in raw_db: split_entry = entry.split(' -> ') if len(split_entry) < 2: continue ros_entry = split_entry[0] if split_entry[1]: apt_entries = split_entry[1].split(' ') else: apt_entries = [] self.r2a[ros_entry] = apt_entries for a in apt_entries: self.a2r[a] = ros_entry
def auto_id(cls, verbose=False): # type: (bool) -> int _id = cls.get_touchpad_id() cmd = ["xinput", "list-props", _id] for p, v in cls.__dict__.items(): if not isinstance(v, NProp): continue v.prop_id = -1 # clear id ret = 0 for line in common.check_output(cmd).splitlines(): for p, v in cls.__dict__.items(): if not isinstance(v, NProp): continue if v.key not in line: continue mo = re.search(r"([0-9]+)", line) if not mo: continue _id = mo.group(1) v.prop_id = int(_id) info("id:{:3} as {} - {}".format(_id, p, v.key)) num = cls.parse_props(v, line, verbose) if num != len(v.vals): warn("id:{:3}, {} - {}".format(_id, num, len(v.vals))) ret += 1 break else: if verbose: print("???????:" + line) cls.props_copy(NProp) if verbose: for p, key in NProp.props(): if key.prop_id > 0: print("{:3} was loaded as {}".format(getattr(cls, p), p)) else: print("{} was not found...".format(p)) return ret
def translate(self, text): lang = '%s-%s' % (self.source, self.target) translation = check_output(['apertium', '-m', lang + ".tmx", '-u', lang], text) return translation