How to use _get_cmd_stdout method in stestr

Best Python code snippet using stestr_python

print_package_tag.py

Source:print_package_tag.py Github

copy

Full Screen

...14class PackageVersion(object):15 def __init__(self, package_name):16 self._package_name = package_name17 def get_version(self):18 response_raw = self._get_cmd_stdout('dcos package describe {}'.format(self._package_name))19 try:20 return json.loads(response_raw)['version']21 except:22 logger.error('Failed to parse version from output of command "{}": {}'.format(cmd, response_raw))23 raise24 def get_version_sha_for_path(self, repo_path):25 version_tag = self.get_version()26 try:27 # ensure the tag is visible in the repo copy:28 repo_dotgit_path = os.path.join(repo_path, '.git')29 self._get_cmd_stdout('git --git-dir={} fetch origin --tags'.format(repo_dotgit_path))30 # get the rev for the tag. use % instead of .format() to preserve a literal '{}':31 return self._get_cmd_stdout('git --git-dir=%s rev-parse %s^{}' % (repo_dotgit_path, version_tag))32 except:33 logger.error('Failed to retrieve SHA1 from git for tag "{}"'.format(version_tag))34 raise35 def get_version_sha_for_url(self, repo_url):36 version_tag = self.get_version()37 try:38 # get the rev for the remote tag. use % instead of .format() to preserve a literal '{}':39 rev = self._get_cmd_stdout('git ls-remote --tags %s refs/tags/%s^{}' % (repo_url, version_tag))40 if len(rev) == 0:41 # no tag with '^{}' suffix was found. retry without the suffix:42 rev = self._get_cmd_stdout('git ls-remote --tags {} refs/tags/{}'.format(repo_url, version_tag))43 # output format: '<tag> <refname>'44 return rev.split()[0]45 except:46 logger.error('Failed to retrieve SHA1 from git for tag "{}"'.format(version_tag))47 raise48 def _get_cmd_stdout(self, cmd):49 try:50 logger.info("CMD: {}".format(cmd))51 output = subprocess.check_output(cmd.split(' ')).decode('utf-8').strip()52 logger.info("Output ({}b):\n{}".format(len(output), output))53 return output54 except:55 logger.error('Failed to run command: "{}"'.format(cmd))56 raise57def main(argv):58 if len(argv) != 2 and len(argv) != 3:59 logger.error('Syntax: {} <package> [/local/repo/path or git@host.com:remote/repo]'.format(argv[0]))60 logger.error('Received arguments {}'.format(str(argv)))61 return 162 if len(argv) == 2:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stestr automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful