本文整理汇总了Python中tambo.Transport类的典型用法代码示例。如果您正苦于以下问题:Python Transport类的具体用法?Python Transport怎么用?Python Transport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Source
class Source(object):
help_menu = 'build a source package on the local system'
_help = """
Build a source package on the local system.
"""
name = 'source'
def __init__(self, argv):
self.argv = argv
def main(self):
self.parser = Transport(self.argv)
self.parser.catch_help = self.help()
self.parser.parse_args()
self._run()
def help(self):
return self._help
def _run(self):
""" Build a source package on the local system. """
util.setup_pristine_tar_branch()
cmd = ['gbp', 'buildpackage', '--git-tag', '--git-retag', '-S',
'-us', '-uc']
log.info(' '.join(cmd))
subprocess.check_call(cmd)
示例2: parse_args
def parse_args(self):
options = ['--allowed']
parser = Transport(self.argv, options=options)
parser.catch_help = self._help
parser.parse_args()
delgado.config['allowed'] = parser.get('--allowed') or []
engine = Engine(connection=self.connection)
engine.run_forever()
示例3: parse_args
def parse_args(self):
parser = Transport(self.argv, options=['--socket-location'])
parser.catch_help = self._help
parser.parse_args()
location = parser.get('--socket-location') or '/tmp/pytest.sock'
delgado.config['allowed'] = ['py.test']
engine = Engine(socket_location=location)
engine.run_forever()
示例4: Hello
class Hello(object):
help_menu = 'test authentication to Jenkins'
_help = """
Test authentication to Jenkins and return your user's fullName attribute.
"""
name = 'hello'
def __init__(self, argv):
self.argv = argv
self.options = []
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self.help()
self.parser.parse_args()
self._run()
def help(self):
return self._help
def _run(self):
""" Authenticate to Jenkins and print our username to STDOUT.
Useful for checking that our authentication credentials are
correct. """
jenkins = util.jenkins_connection()
# python-jenkins does not have syntactic support for "whoami" (the
# "/me/api/json" endpoint), so we have to hit it and parse it
# ourselves.
# https://review.openstack.org/307896
whoami_url = posixpath.join(jenkins.url, 'me/api/json')
try:
response = jenkins.jenkins_open(Request(whoami_url))
data = json.loads(response)
except JenkinsException as err:
raise SystemExit(err)
name = data['fullName'] # Our Jenkins instance gets this from LDAP
try:
jenkins_version = jenkins.get_version()
except AttributeError:
# python-jenkins older than 0.4.1 does not have get_version().
version_url = jenkins.server
try:
response = urlopen(Request(version_url))
if six.PY2:
jenkins_version = response.info().getheader('X-Jenkins')
else:
jenkins_version = response.getheader('X-Jenkins')
except (HTTPError, BadStatusLine) as err:
raise SystemExit(err)
print('Hello %s from Jenkins %s' % (name, jenkins_version))
示例5: parse_args
def parse_args(self, argv=None):
""" pass argv during testing """
if argv is None:
argv = self.argv
options = [['--output', '-o']]
parser = Transport(argv, options=options)
parser.catch_help = self.help()
parser.parse_args()
self.source = util.infer_path(parser.unknown_commands)
self.output = parser.get('--output', self.source + '-dvd.iso')
self.check_dependency()
self.make_iso()
self.make_sha256sum()
示例6: Exists
class Exists(object):
_help = dedent("""
Check if a given URL part exists already. Mainly does a HEAD request to the
given endpoint. If the URL does not exist it will return a non-zero exit
status (404).
For example:
chacractl exists binaries/ceph-deploy/master/debian/wheezy
Positional Arguments:
[URL] The endpoint, starting with the full url part (sans fqdn)
""")
help_menu = "check if a given URL part exists already"
options = []
def __init__(self, argv):
self.argv = argv
self.base_url = chacractl.config['url']
def sanitize_url(self, url_part):
# get rid of the leading slash to prevent issues when joining
url = url_part.lstrip('/')
# and add a trailing slash so that the request is done at the correct
# canonical url
if not url.endswith('/'):
url = "%s/" % url
return url
@catches(requests.exceptions.HTTPError, handler=requests_errors)
def head(self, url):
logger.info('HEAD: %s', url)
exists = requests.head(
url,
auth=chacractl.config['credentials'],
verify=chacractl.config['ssl_verify'])
exists.raise_for_status()
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self._help
self.parser.parse_args()
if self.parser.unknown_commands:
url_part = self.sanitize_url(self.parser.unknown_commands[-1])
url = os.path.join(self.base_url, url_part)
return self.head(url)
else:
logger.error('no url was passed in')
示例7: Repo
class Repo(object):
_help = dedent(
"""
Operate on repositories on a remote chacra instance. Both `recreate` and
`update` calls are not immediate. They rely on the async service managing
repos which usually have a delay applied to them.
Options:
recreate Mark a repository to be removed and created from scratch
again.
update Repository will get updated by running the repo tools on
it again.
"""
)
help_menu = "recreate, delete, or update repositories"
options = ["recreate", "update"]
def __init__(self, argv):
self.argv = argv
@property
def base_url(self):
return os.path.join(chacractl.config["url"], "repos")
@catches(requests.exceptions.HTTPError, handler=requests_errors)
def post(self, url):
exists = requests.head(url, auth=chacractl.config["credentials"], verify=chacractl.config["ssl_verify"])
exists.raise_for_status()
logger.info("POST: %s", url)
response = requests.post(url, auth=chacractl.config["credentials"], verify=chacractl.config["ssl_verify"])
response.raise_for_status()
json = response.json()
for k, v in json.items():
logger.info("%s: %s", k, v)
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self._help
self.parser.parse_args()
recreate = self.parser.get("recreate")
update = self.parser.get("update")
if recreate:
url_part = os.path.join(recreate, "recreate")
url = os.path.join(self.base_url, url_part)
self.post(url)
elif update:
url_part = os.path.join(update, "update")
url = os.path.join(self.base_url, url_part)
self.post(url)
示例8: BaseBackend
class BaseBackend(base.BaseCommand):
options = []
parser = None
def parse_args(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self.help()
self.parser.parse_args()
self.path = util.infer_path(self.parser.unknown_commands)
self.check_dependency()
self.sign()
def sign(self):
raise NotImplemented()
示例9: Build
class Build(object):
help_menu = "build a package in Jenkins"
_help = """
Build a package in Jenkins.
"""
name = "build"
def __init__(self, argv):
self.argv = argv
self.options = []
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self.help()
self.parser.parse_args()
self._run()
def help(self):
return self._help
def _run(self):
""" Build a package in Jenkins. """
pkg_name = util.package_name()
branch_name = util.current_branch()
jenkins = util.jenkins_connection()
if branch_name.startswith("patch-queue/"):
log.error("%s a patch-queue branch" % branch_name)
msg = 'You can switch to the debian branch with "gbp pq switch"'
raise SystemExit(msg)
log.info(
"building %s branch %s at %s", pkg_name, branch_name, posixpath.join(jenkins.url, "job", "build-package")
)
job_params = {"PKG_NAME": pkg_name, "BRANCH": branch_name}
if self._has_broken_build_job():
jenkins.build_job = types.MethodType(_build_job_fixed, jenkins)
jenkins.build_job("build-package", parameters=job_params, token=jenkins.password)
def _has_broken_build_job(self):
# Ubuntu Trusty ships python-jenkins 0.2.1-0ubuntu1, and this version
# has a broken build_job() method. See
# https://bugs.launchpad.net/bugs/1177831 .
# This bug was fixed in python-jenkins v0.3.2 upstream.
v = get_distribution("python_jenkins").version
return parse_version(v) < parse_version("0.3.2")
示例10: main
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self._help
self.parser.parse_args()
self.force = self.parser.has('--force')
# handle posting binaries:
if self.parser.has('create'):
url_part = self.sanitize_url(self.parser.get('create'))
if not sys.stdin.isatty():
# read from stdin
logger.info('reading input from stdin')
for line in sys.stdin.readlines():
filename = self.sanitize_filename(line)
if not filename:
continue
url = os.path.join(self.base_url, url_part)
self.post(url, filename)
else:
filepath = self.sanitize_filename(self.argv[-1])
if not filepath:
logger.warning(
'provided path does not exist: %s', self.argv[-1]
)
return
url = os.path.join(self.base_url, url_part)
self.post(url, filepath)
elif self.parser.has('delete'):
url_part = self.sanitize_url(self.parser.get('delete'))
url = os.path.join(self.base_url, url_part)
self.delete(url)
示例11: parse_args
def parse_args(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self.help()
self.parser.parse_args()
self.path = util.infer_path(self.parser.unknown_commands)
self.check_dependency()
self.sign()
示例12: parse_args
def parse_args(self):
transport = Transport(self.argv, check_help=False)
transport.catch_help = self.__doc__
if len(self.argv) <= 1:
transport.print_help()
transport.parse_args()
for action in self.actions:
if transport.has(action):
return self.actions.get(action)()
# If nothing matches, print the help
transport.print_help()
示例13: Clone
class Clone(object):
help_menu = 'clone a package from dist-git'
_help = """
Clone a package from dist-git. Your SSH key must be set up in Gerrit.
Positional Arguments:
[package] The name of the package to clone.
"""
name = 'clone'
def __init__(self, argv):
self.argv = argv
self.options = []
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self.help()
self.parser.parse_args()
try:
pkg = self.parser.unknown_commands[0]
except IndexError:
return self.parser.print_help()
self._run(pkg)
def help(self):
return self._help
def _run(self, pkg):
""" Clone a package from dist-git. """
if os.path.exists(pkg):
raise SystemExit('%s already exists in current working directory.',
pkg)
configp = util.config()
try:
user = configp.get('rhcephpkg', 'user')
gitbaseurl = configp.get('rhcephpkg', 'gitbaseurl')
except configparser.Error as err:
raise SystemExit('Problem parsing .rhcephpkg.conf: %s',
err.message)
# TODO: SafeConfigParser might make the "user" interpolation here
# unnecessary? Need to test, particularly what it does to %(module).
pkg_url = gitbaseurl % {'user': user, 'module': pkg}
cmd = ['git', 'clone', pkg_url]
subprocess.check_call(cmd)
示例14: main
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self.help()
self.parser.parse_args()
try:
build_number = int(self.parser.unknown_commands[0])
except (IndexError, ValueError):
return self.parser.print_help()
self.watch(build_number)
示例15: main
def main(self):
self.parser = Transport(self.argv, options=self.options)
self.parser.catch_help = self.help()
self.parser.parse_args()
try:
pkg = self.parser.unknown_commands[0]
except IndexError:
return self.parser.print_help()
self._run(pkg)