本文整理汇总了Python中rbtools.utils.process.die函数的典型用法代码示例。如果您正苦于以下问题:Python die函数的具体用法?Python die怎么用?Python die使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了die函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_repository_info
def get_repository_info(self):
if not self.p4.is_supported():
return None
p4_info = self.p4.info()
# For the repository path, we first prefer p4 brokers, then the
# upstream p4 server. If neither of those are found, just return None.
repository_path = p4_info.get('Broker address', None)
if repository_path is None:
repository_path = p4_info.get('Server address', None)
if repository_path is None:
return None
try:
parts = repository_path.split(':')
hostname = None
if len(parts) == 3 and parts[0] == 'ssl':
hostname = parts[1]
port = parts[2]
elif len(parts) == 2:
hostname, port = parts
if not hostname:
die('Path %s is not a valid Perforce P4PORT' % repository_path)
info = socket.gethostbyaddr(hostname)
# If aliases exist for hostname, create a list of alias:port
# strings for repository_path.
if info[1]:
servers = [info[0]] + info[1]
repository_path = ["%s:%s" % (server, port)
for server in servers]
else:
repository_path = "%s:%s" % (info[0], port)
except (socket.gaierror, socket.herror):
pass
server_version = p4_info.get('Server version', None)
if not server_version:
return None
m = re.search(r'[^ ]*/([0-9]+)\.([0-9]+)/[0-9]+ .*$',
server_version, re.M)
if m:
self.p4d_version = int(m.group(1)), int(m.group(2))
else:
# Gracefully bail if we don't get a match
return None
# Now that we know it's Perforce, make sure we have GNU diff
# installed, and error out if we don't.
check_gnu_diff()
return RepositoryInfo(path=repository_path, supports_changesets=True)
开发者ID:phoenixmy,项目名称:rbtools,代码行数:60,代码来源:perforce.py
示例2: check_gnu_patch
def check_gnu_patch():
"""Checks if GNU patch is installed, and informs the user if it's not."""
has_gnu_patch = False
try:
result = execute(['patch', '--version'], ignore_errors=True)
has_gnu_patch = 'Free Software Foundation' in result
except OSError:
pass
try:
# SunOS has gpatch
result = execute(['gpatch', '--version'], ignore_errors=True)
has_gnu_patch = 'Free Software Foundation' in result
except OSError:
pass
if not has_gnu_patch:
sys.stderr.write('\n')
sys.stderr.write('GNU patch is required to post this review.'
'Make sure it is installed and in the path.\n')
sys.stderr.write('\n')
if os.name == 'nt':
sys.stderr.write('On Windows, you can install this from:\n')
sys.stderr.write(GNU_PATCH_WIN32_URL)
sys.stderr.write('\n')
die()
开发者ID:bcelary,项目名称:rbtools,代码行数:29,代码来源:checks.py
示例3: main
def main(self, *args):
"""Create and update review requests."""
self.post_process_options()
origcwd = os.path.abspath(os.getcwd())
repository_info, tool = self.initialize_scm_tool()
server_url = self.get_server_url(repository_info, tool)
api_root = self.get_root(server_url)
self.setup_tool(tool, api_root=api_root)
if self.options.revision_range:
diff, parent_diff = tool.diff_between_revisions(
self.options.revision_range,
args,
repository_info)
elif self.options.svn_changelist:
diff, parent_diff = tool.diff_changelist(
self.options.svn_changelist)
elif self.options.diff_filename:
parent_diff = None
if self.options.diff_filename == '-':
diff = sys.stdin.read()
else:
try:
diff_path = os.path.join(origcwd,
self.options.diff_filename)
fp = open(diff_path, 'r')
diff = fp.read()
fp.close()
except IOError, e:
die("Unable to open diff filename: %s" % e)
开发者ID:booyah,项目名称:rbtools,代码行数:31,代码来源:post.py
示例4: credentials_prompt
def credentials_prompt(self, realm, uri, username=None, password=None,
*args, **kwargs):
"""Prompt the user for credentials using the command line.
This will prompt the user, and then return the provided
username and password. This is used as a callback in the
API when the user requires authorization.
"""
if username is None or password is None:
if getattr(self.options, 'diff_filename', None) == '-':
die('HTTP authentication is required, but cannot be '
'used with --diff-filename=-')
print()
print('Please log in to the Review Board server at %s.' %
urlparse(uri)[1])
# getpass will write its prompt to stderr but input
# writes to stdout. See bug 2831.
if username is None:
sys.stderr.write('Username: ')
username = input()
if password is None:
password = getpass.getpass(b'Password: ')
return username, password
开发者ID:halvorlu,项目名称:rbtools,代码行数:27,代码来源:__init__.py
示例5: otp_token_prompt
def otp_token_prompt(self, uri, token_method, *args, **kwargs):
"""Prompt the user for a one-time password token.
Their account is configured with two-factor authentication. The
server will have sent a token to their configured mobile device
or application. The user will be prompted for this token.
"""
if getattr(self.options, 'diff_filename', None) == '-':
die('A two-factor authentication token is required, but cannot '
'be used with --diff-filename=-')
print()
print('Please enter your two-factor authentication token for Review '
'Board.')
if token_method == 'sms':
print('You should be getting a text message with '
'an authentication token.')
print('Enter the token below.')
elif token_method == 'call':
print('You should be getting an automated phone call with '
'an authentication token.')
print('Enter the token below.')
elif token_method == 'generator':
print('Enter the token shown on your token generator app below.')
print()
return getpass.getpass(b'Token: ')
开发者ID:halvorlu,项目名称:rbtools,代码行数:29,代码来源:__init__.py
示例6: _die
def _die(self, msg, e):
"""Remove the connection to the database and print an error message."""
self.db = None # So that _write_db doesn't cause an exception
logging.error('%s: %s. Try running "rbt clear-cache" to manually '
'clear the HTTP cache for the API.',
msg, e)
die()
开发者ID:elatt,项目名称:rbtools,代码行数:7,代码来源:cache.py
示例7: get_review_request
def get_review_request(self, request_id):
"""Return the review request resource for the given ID."""
try:
request = \
self.root_resource.get_review_requests().get_item(request_id)
except APIError, e:
die("Error getting review request: %s" % e)
开发者ID:booyah,项目名称:rbtools,代码行数:7,代码来源:publish.py
示例8: _run_p4
def _run_p4(self, command):
"""Execute a perforce command using the python marshal API.
- command: A list of strings of the command to execute.
The return type depends on the command being run.
"""
command = ['p4', '-G'] + command
p = subprocess.Popen(command, stdout=subprocess.PIPE)
result = []
has_error = False
while 1:
try:
data = marshal.load(p.stdout)
except EOFError:
break
else:
result.append(data)
if data.get('code', None) == 'error':
has_error = True
rc = p.wait()
if rc or has_error:
for record in result:
if 'data' in record:
print record['data']
die('Failed to execute command: %s\n' % (command,))
return result
开发者ID:flowblok,项目名称:rbtools,代码行数:31,代码来源:perforce.py
示例9: get_repository_info
def get_repository_info(self):
if not check_install('cm version'):
return None
# Get the repository that the current directory is from. If there
# is more than one repository mounted in the current directory,
# bail out for now (in future, should probably enter a review
# request per each repository.)
split = execute(["cm", "ls", "--format={8}"], split_lines=True,
ignore_errors=True)
m = re.search(r'^rep:(.+)$', split[0], re.M)
if not m:
return None
# Make sure the repository list contains only one unique entry
if len(split) != split.count(split[0]):
# Not unique!
die('Directory contains more than one mounted repository')
path = m.group(1)
# Get the workspace directory, so we can strip it from the diff output
self.workspacedir = execute(["cm", "gwp", ".", "--format={1}"],
split_lines=False,
ignore_errors=True).strip()
logging.debug("Workspace is %s" % self.workspacedir)
return RepositoryInfo(path,
supports_changesets=True,
supports_parent_diffs=False)
开发者ID:NurKaynar,项目名称:hacklab,代码行数:32,代码来源:plastic.py
示例10: check_api_version
def check_api_version(self):
"""Checks the API version on the server to determine which to use."""
try:
root_resource = self.api_get('api/')
rsp = self.api_get(root_resource['links']['info']['href'])
self.rb_version = rsp['info']['product']['package_version']
if parse_version(self.rb_version) >= parse_version('1.5.2'):
self.deprecated_api = False
self.root_resource = root_resource
debug('Using the new web API')
return True
except APIError, e:
if e.http_status not in (401, 404):
# We shouldn't reach this. If there's a permission denied
# from lack of logging in, then the basic auth handler
# should have hit it.
#
# However in some versions it wants you to be logged in
# and returns a 401 from the application after you've
# done your http basic auth
die("Unable to access the root /api/ URL on the server.")
return False
开发者ID:dcestari,项目名称:rbtools,代码行数:25,代码来源:postreview.py
示例11: check_gnu_diff
def check_gnu_diff():
"""Checks if GNU diff is installed, and informs the user if it's not."""
has_gnu_diff = False
try:
if hasattr(os, 'uname') and os.uname()[0] == 'SunOS':
diff_cmd = 'gdiff'
else:
diff_cmd = 'diff'
result = execute([diff_cmd, '--version'], ignore_errors=True)
has_gnu_diff = 'GNU diffutils' in result
except OSError:
pass
if not has_gnu_diff:
sys.stderr.write('\n')
sys.stderr.write('GNU diff is required in order to generate diffs. '
'Make sure it is installed\n')
sys.stderr.write('and in the path.\n')
sys.stderr.write('\n')
if os.name == 'nt':
sys.stderr.write('On Windows, you can install this from:\n')
sys.stderr.write(GNU_DIFF_WIN32_URL)
sys.stderr.write('\n')
die()
开发者ID:acres-com-au,项目名称:rbtools,代码行数:28,代码来源:checks.py
示例12: diff_between_revisions
def diff_between_revisions(self, revision_range, args, repository_info):
"""
This doesn't make much sense in Plastic SCM 4.
We'll only implement revisions for changests and branches
"""
die("This option is not supported. Only reviews of a changeset or "
"branch are supported")
开发者ID:mhahn,项目名称:rbtools,代码行数:7,代码来源:plastic.py
示例13: credentials_prompt
def credentials_prompt(self, realm, uri, username=None, password=None, *args, **kwargs):
"""Prompt the user for credentials using the command line.
This will prompt the user, and then return the provided
username and password. This is used as a callback in the
API when the user requires authorization.
"""
if getattr(self.options, "diff_filename", None) == "-":
die("HTTP authentication is required, but cannot be " "used with --diff-filename=-")
if username is None or password is None:
print
print "==> HTTP Authentication Required"
print 'Enter authorization information for "%s" at %s' % (realm, urlparse(uri)[1])
# getpass will write its prompt to stderr but raw_input
# writes to stdout. See bug 2831.
if username is None:
sys.stderr.write("Username: ")
username = raw_input()
if password is None:
password = getpass.getpass("Password: ")
return username, password
开发者ID:pyrogenic,项目名称:rbtools,代码行数:25,代码来源:__init__.py
示例14: tempt_fate
def tempt_fate(server, submit_as=None, retries=3):
"""
Attempts to create a review request on a Review Board server and upload
a diff. On success, the review request path is displayed.
"""
try:
if options.rid:
# review_request = server.get_ship_it_reviewers(options.rid)
review_request = server.get_comment_user(options.rid)
else:
die("Please give a review id")
except APIError, e:
if e.error_code == 103: # Not logged in
retries = retries - 1
# We had an odd issue where the server ended up a couple of
# years in the future. Login succeeds but the cookie date was
# "odd" so use of the cookie appeared to fail and eventually
# ended up at max recursion depth :-(. Check for a maximum
# number of retries.
if retries >= 0:
server.login(force=True)
return tempt_fate(server, submit_as, retries=retries)
if options.rid:
die("Error getting review request %s: %s" % (options.rid, e))
开发者ID:turlutux,项目名称:rb-vim,代码行数:27,代码来源:reviewboard.py
示例15: otp_token_prompt
def otp_token_prompt(self, uri, token_method, *args, **kwargs):
"""Prompt the user for a one-time password token.
Their account is configured with two-factor authentication. The
server will have sent a token to their configured mobile device
or application. The user will be prompted for this token.
"""
if getattr(self.options, "diff_filename", None) == "-":
die("A two-factor authentication token is required, but cannot " "be used with --diff-filename=-")
print
print "==> Two-factor authentication token required"
if token_method == "sms":
print ("You should be getting a text message with " "an authentication token.")
print "Enter the token below."
elif token_method == "call":
print ("You should be getting an automated phone call with " "an authentication token.")
print "Enter the token below."
elif token_method == "generator":
print "Enter the token shown on your token generator app below."
print
return getpass.getpass("Token: ")
开发者ID:pyrogenic,项目名称:rbtools,代码行数:25,代码来源:__init__.py
示例16: main
def main():
origcwd = os.path.abspath(os.getcwd())
if 'APPDATA' in os.environ:
homepath = os.environ['APPDATA']
elif 'HOME' in os.environ:
#homepath = os.environ["HOME"]
homepath = '/usr/local/bin/perforce'
else:
homepath = ''
# If we end up creating a cookie file, make sure it's only readable by the
# user.
os.umask(0077)
# Load the config and cookie files
cookie_file = os.path.join(homepath, ".post-review-cookies.txt")
user_config, globals()['configs'] = load_config_files(homepath)
args = parse_options(sys.argv[1:])
debug('RBTools %s' % get_version_string())
debug('Python %s' % sys.version)
debug('Running on %s' % (platform.platform()))
debug('Home = %s' % homepath)
debug('Current Directory = %s' % os.getcwd())
debug('Checking the repository type. Errors shown below are mostly harmless.')
repository_info, tool = scan_usable_client(options)
debug('Finished checking the repository type.')
tool.user_config = user_config
tool.configs = configs
# Verify that options specific to an SCM Client have not been mis-used.
tool.check_options()
if repository_info.supports_changesets:
changenum = tool.get_changenum(args)
else:
changenum = None
if options.revision_range:
diff, parent_diff = tool.diff_between_revisions(options.revision_range, args,
repository_info)
elif options.svn_changelist:
diff, parent_diff = tool.diff_changelist(options.svn_changelist)
elif options.diff_filename:
parent_diff = None
if options.diff_filename == '-':
diff = sys.stdin.read()
else:
try:
fp = open(os.path.join(origcwd, options.diff_filename), 'r')
diff = fp.read()
fp.close()
except IOError, e:
die("Unable to open diff filename: %s" % e)
开发者ID:psusloparov,项目名称:ReviewBoard,代码行数:59,代码来源:postreview.py
示例17: diff_list_resource
def diff_list_resource(server):
if options.rid:
url = 'api/review-requests/%s/diffs/' % (options.rid)
return server.api_get(url)
else:
die('You must provide a review id (-r #id) to get review comments')
开发者ID:turlutux,项目名称:rb-vim,代码行数:8,代码来源:reviewboard.py
示例18: main
def main(self, *args):
"""Print the diff to terminal."""
diff = self.get_diff(*args)
if not diff:
die("There don't seem to be any diffs!")
print diff
开发者ID:booyah,项目名称:rbtools,代码行数:8,代码来源:diff.py
示例19: check_valid_type
def check_valid_type(self, close_type):
"""Check if the user specificed a proper type.
Type must either be 'discarded' or 'submitted'. If the type
is wrong, the command will stop and alert the user.
"""
if close_type not in (SUBMITTED, DISCARDED):
die("%s is not valid type. Try '%s' or '%s'" %
(self.options.close_type, SUBMITTED, DISCARDED))
开发者ID:booyah,项目名称:rbtools,代码行数:9,代码来源:close.py
示例20: get_review_request
def get_review_request(self, request_id):
"""Returns the review request resource for the given ID."""
try:
request = \
self.root_resource.get_review_requests().get_item(request_id)
except APIError:
die('The specified review request does not exist.')
return request
开发者ID:booyah,项目名称:rbtools,代码行数:9,代码来源:attach.py
注:本文中的rbtools.utils.process.die函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论