Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
raise CommandError(
'Unable to verify authenticity of file downloaded '
'from %s:\n%s' % (url, errors))
finally:
os.unlink(sig_filename)
else:
logging.info('"gpg" not installed. Skipping signature validation.')
try:
sha_url = '%s.sha256sum' % url
logging.debug('Downloading %s', sha_url)
response = urlopen(sha_url)
real_sha = response.read().split(' ')[0]
except (HTTPError, URLError) as e:
raise CommandError('Error when downloading file: %s' % e)
with open(zip_filename, 'rb') as f:
our_sha = hashlib.sha256(f.read()).hexdigest()
if real_sha == our_sha:
logging.debug('Verified SHA256 hash')
else:
logging.debug('SHA256 hash does not match!')
logging.debug(' Downloaded file hash was: %s', our_sha)
logging.debug(' Expected hash was: %s', real_sha)
raise CommandError(
'Unable to verify the checksum of the downloaded copy of '
'%s.\n'
'This could be due to an invasive proxy or an attempted '
'man-in-the-middle attack.' % url)
def main(self, *args):
"""Print the diff to terminal."""
# The 'args' tuple must be made into a list for some of the
# SCM Clients code. See comment in post.
args = list(args)
if self.options.revision_range:
raise CommandError(
'The --revision-range argument has been removed. To create a '
'diff for one or more specific revisions, pass those '
'revisions as arguments. For more information, see the '
'RBTools 0.6 Release Notes.')
if self.options.svn_changelist:
raise CommandError(
'The --svn-changelist argument has been removed. To use a '
'Subversion changelist, pass the changelist name as an '
'additional argument after the command.')
repository_info, tool = self.initialize_scm_tool(
client_name=self.options.repository_type)
server_url = self.get_server_url(repository_info, tool)
api_client, api_root = self.get_api(server_url)
self.setup_tool(tool, api_root=api_root)
try:
revisions = tool.parse_revision_spec(args)
extra_args = None
except InvalidRevisionSpecError:
if not tool.supports_diff_extra_args:
raise
def no_commit_error(self):
raise CommandError('No existing commit to stamp on.')
if not self.options.diff_filename:
# If the user has requested to guess the summary or description,
# get the commit message and override the summary and description
# options.
self.check_guess_fields()
if self.options.update:
self.options.rid = guess_existing_review_request_id(
repository_info, self.options.repository_name, api_root,
api_client, self.tool, self.cmd_args, guess_summary=False,
guess_description=False,
is_fuzzy_match_func=self._ask_review_request_match)
if not self.options.rid:
raise CommandError('Could not determine the existing review '
'request to update.')
# If only certain files within a commit are being submitted for review,
# do not include the commit id. This prevents conflicts if mutliple
# files from the same commit are posted for review separately.
if self.options.include_files:
commit_id = None
request_id, review_url = self.post_request(
repository_info,
repository,
server_url,
api_root,
self.options.rid,
changenum=changenum,
diff_content=diff,
if self.options.revision_range:
raise CommandError(
'The --revision-range argument has been removed. To post a '
'diff for one or more specific revisions, pass those '
'revisions as arguments. For more information, see the '
'RBTools 0.6 Release Notes.')
if self.options.svn_changelist:
raise CommandError(
'The --svn-changelist argument has been removed. To use a '
'Subversion changelist, pass the changelist name as an '
'additional argument after the command.')
# Only one of --description and --description-file can be used
if self.options.description and self.options.description_file:
raise CommandError('The --description and --description-file '
'options are mutually exclusive.\n')
# If --description-file is used, read that file
if self.options.description_file:
if os.path.exists(self.options.description_file):
with open(self.options.description_file, 'r') as fp:
self.options.description = fp.read()
else:
raise CommandError(
'The description file %s does not exist.\n' %
self.options.description_file)
# Only one of --testing-done and --testing-done-file can be used
if self.options.testing_done and self.options.testing_file:
raise CommandError('The --testing-done and --testing-done-file '
'options are mutually exclusive.\n')
try:
review_request = guess_existing_review_request(
repository_info=repository_info,
repository_name=self.options.repository_name,
api_root=api_root,
api_client=api_client,
tool=self.tool,
revisions=get_revisions(self.tool, self.cmd_args),
guess_summary=False,
guess_description=False,
is_fuzzy_match_func=self._ask_review_request_match)
except ValueError as e:
raise CommandError(six.text_type(e))
if not review_request or not review_request.id:
raise CommandError('Could not determine the existing review '
'request URL to land.')
review_request_id = review_request.id
is_local = True
try:
review_request = api_root.get_review_request(
review_request_id=review_request_id)
except APIError as e:
raise CommandError('Error getting review request %s: %s'
% (review_request_id, e))
if self.options.is_local is not None:
is_local = self.options.is_local
if is_local:
% (source_branch, destination_branch))
else:
print('Merging branch "%s" into "%s".'
% (source_branch, destination_branch))
if not dry_run:
try:
self.tool.merge(target=source_branch,
destination=destination_branch,
message=review_commit_message,
author=author,
squash=squash,
run_editor=edit,
close_branch=delete_branch)
except MergeError as e:
raise CommandError(six.text_type(e))
else:
print('Applying patch from review request %s.' % review_request.id)
if not dry_run:
self.patch(review_request.id)
print('Review request %s has landed on "%s".' %
(review_request.id, self.options.destination_branch))
def post_process_options(self):
# -g implies --guess-summary and --guess-description
if self.options.guess_fields:
self.options.guess_fields = self.normalize_guess_value(
self.options.guess_fields, '--guess-fields')
self.options.guess_summary = self.options.guess_fields
self.options.guess_description = self.options.guess_fields
if self.options.revision_range:
raise CommandError(
'The --revision-range argument has been removed. To post a '
'diff for one or more specific revisions, pass those '
'revisions as arguments. For more information, see the '
'RBTools 0.6 Release Notes.')
if self.options.svn_changelist:
raise CommandError(
'The --svn-changelist argument has been removed. To use a '
'Subversion changelist, pass the changelist name as an '
'additional argument after the command.')
# Only one of --description and --description-file can be used
if self.options.description and self.options.description_file:
raise CommandError('The --description and --description-file '
'options are mutually exclusive.\n')
u'this review request\n')
elif e.error_code == 219:
error_msg.append(
u'The generated diff file was empty. This '
u'usually means no files were\n'
u'modified in this change.\n')
else:
error_msg.append(str(e).decode('utf-8') + u'\n')
error_msg.append(
u'Your review request still exists, but the diff is '
u'not attached.\n')
error_msg.append(u'%s\n' % review_request.absolute_url)
raise CommandError(u'\n'.join(error_msg))
try:
draft = review_request.get_draft()
except APIError as e:
raise CommandError('Error retrieving review request draft: %s' % e)
# Update the review request draft fields based on options set
# by the user, or configuration.
update_fields = {}
if self.options.target_groups:
update_fields['target_groups'] = self.options.target_groups
if self.options.target_people:
update_fields['target_people'] = self.options.target_people
"""Patch a single review request's diff using rbt patch."""
patch_command = [RB_MAIN, 'patch']
patch_command.extend(build_rbtools_cmd_argv(self.options))
if self.options.edit:
patch_command.append('-c')
else:
patch_command.append('-C')
patch_command.append(six.text_type(review_request_id))
rc, output = execute(patch_command, ignore_errors=True,
return_error_code=True)
if rc:
raise CommandError('Failed to execute "rbt patch":\n%s'
% output)