path = tmp.name logger.debug(" ... saving to: %s" % path) tmp.write(content) else: path = re.sub('^file://', '', uri) path = os.path.expanduser(path) return path def set_column(self, objects, key, value, static=False): ''' Save an additional column/field to all objects in memory :param objects: objects (rows) to manipulate :param key: key name that will be assigned to each object :param value: value that will be assigned to each object :param static: flag if value should applied to key per object 'as-is' ''' if type(value) is type or hasattr(value, '__call__'): # class or function; use the resulting object after init/exec [o.update({key: value(o)}) for o in objects] elif static: [o.update({key: value}) for o in objects] else: [o.update({key: o[value]}) for o in objects] return objects if __name__ == '__main__': from metriquec.argparsers import cube_cli cube_cli(Rows)
* sourcepackage * sourcerpm * summary ''' fmt = ':::'.join('%%{%s}' % f for f in self.fields) if self.ssh_host: output = self._ssh_cmd(fmt) else: output = self._local_cmd(fmt) if isinstance(output, basestring): output = output.strip().split('\n') lines = [l.strip().split(':::') for l in output] now = dt2ts(datetime.now()) host = self.ssh_host or socket.gethostname() objects = [] for line in lines: obj = {'host': host, '_start': now} for i, item in enumerate(line): if item == '(none)': item = None obj[self.fields[i]] = item obj['_oid'] = '%s__%s' % (host, obj['nvra']) objects.append(obj) objects = self.normalize(objects) return objects if __name__ == '__main__': from metriquec.argparsers import cube_cli cube_cli(Rpm)
jsondata_objs = get_cube('jsondata_objs') tmp = os.path.expanduser('~/.metrique/tmp/') cwd = os.path.dirname(os.path.abspath(__file__)) here = '/'.join(cwd.split('/')[0:-2]) test_file_path = 'meps.json' JSON_FILE = os.path.join(here, test_file_path) class Local(jsondata_objs): name = 'tests_jsondata' def get_objects(self, uri=JSON_FILE, save=False, autosnap=False, **kwargs): content = self.load(uri) # the content needs to be re-grouped objects = [] for k, v in content.items(): v.update({'_oid': k}) objects.append(v) objects = self.normalize(objects) if save: self.cube_save(objects, autosnap=autosnap) return objects if __name__ == '__main__': from metriquec.argparsers import cube_cli cube_cli(Local)
#!/usr/bin/env python # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 # Author: "Chris Ward <*****@*****.**> import os from metriquec.csvobject import CSVObject cwd = os.path.dirname(os.path.abspath(__file__)) tests_root = '/'.join(cwd.split('/')[0:-2]) fixtures = os.path.join(tests_root, 'fixtures') DEFAULT_URI = os.path.join(fixtures, 'us-idx-eod.csv') DEFAULT_ID = 'symbol' class Csvfile(CSVObject): """ Test Cube; csv based """ name = 'eg_csvfile' def extract(self, uri=DEFAULT_URI, _oid=DEFAULT_ID, **kwargs): return super(Csvfile, self).extract(uri=uri, _oid=_oid, **kwargs) if __name__ == '__main__': from metriquec.argparsers import cube_cli cube_cli(Csvfile)
''' Walk through repo commits to generate a list of repo commit objects. Each object has the following properties: * repo uri * general commit info (see gittle.utils.git.commit_info) * files added, removed fnames * lines added, removed * acked_by * signed_off_by * resolves * related ''' logger.debug("Extracting GIT repo: %s" % uri) self.repo = self.get_repo(uri, fetch) cmd = 'git rev-list --all' p = subprocess.Popen(cmd.split(), stderr=subprocess.PIPE, stdout=subprocess.PIPE) p = p.communicate()[0] repo_shas = set(x for x in p.split('\n') if x) logger.debug("Total Commits: %s" % len(repo_shas)) objects = self._build_commits(repo_shas, uri) objects = self.normalize(objects) return objects if __name__ == '__main__': from metriquec.argparsers import cube_cli cube_cli(Repo)
objects.append(obj) break objects = self.normalize(objects) return objects @property def proxy(self): ''' Given a github auth token or username and password, connect to the github API using github python module, cache it and return it to the caller. ''' try: import github except ImportError: msg = "requires https://github.com/jacquev6/PyGithub" raise ImportError(msg) if not self._proxy: if self.config.github_token: self._proxy = github.Github(self.config.github_token) else: self._proxy = github.Github(self.config.github_user, self.config.github_pass) return self._proxy if __name__ == '__main__': from metriquec.argparsers import cube_cli cube_cli(Issue)
logger.error('OOPS! (%s) %s' % (job_uri, e)) build_content = {'load_error': e} _build['_oid'] = _oid _build['job_name'] = job_name _build['job_uri'] = job_uri _build['number'] = build_number _build.update(build_content) report_uri = '%s%s/testReport/%s?%s' % (uri, _job_path, self.api_path, _args) logger.debug('Loading (%s)' % report_uri) try: _page = rget(report_uri).content report_content = json.loads(_page, strict=False, object_hook=obj_hook) except Exception as e: logger.error('OOPS! (%s) %s' % (report_uri, e)) report_content = {'load_error': e} _build['report_uri'] = report_uri _build['report'] = report_content return _build if __name__ == '__main__': from metriquec.argparsers import cube_cli cube_cli(Build)