Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data = urllib2.urlopen(r).read()
try:
self.cookie_jar.save(self.cookie_file)
except IOError, e:
debug('Failed to write cookie file: %s' % e)
return data
except urllib2.HTTPError, e:
# Re-raise so callers can interpret it.
raise e
except urllib2.URLError, e:
try:
debug(e.read())
except AttributeError:
pass
die("Unable to access %s. The host path may be invalid\n%s"
% (url, e))
def login(self, force=False):
"""
Logs in to a Review Board server, prompting the user for login
information if needed.
"""
if (options.diff_filename == '-' and
not (self.has_valid_cookie() or
(options.username and options.password))):
die('Authentication information needs to be provided on '
'the command line when using --diff-filename=-')
if self.deprecated_api:
print "==> Review Board Login Required"
print "Enter username and password for Review Board at %s" % \
self.url
if options.username:
username = options.username
elif options.submit_as:
username = options.submit_as
elif not force and self.has_valid_cookie():
# We delay the check for a valid cookie until after looking
# at args, so that it doesn't override the command line.
return
else:
% (local_path, depot_file, base_revision)).encode('utf-8')
dl[1] = ('+++ %s\t%s\n'
% (new_local_path, timestamp)).encode('utf-8')
if is_move:
dl.insert(0,
('Moved to: %s\n' % new_depot_file).encode('utf-8'))
dl.insert(0,
('Moved from: %s\n' % depot_file).encode('utf-8'))
# Not everybody has files that end in a newline (ugh). This ensures
# that the resulting diff file isn't broken.
if not dl[-1].endswith(b'\n'):
dl.append(b'\n')
else:
die('ERROR, no valid diffs: %s' % dl[0].decode('utf-8'))
return dl
dl.append(b'\n')
else:
if ignore_unmodified:
return []
else:
print('Warning: %s in your changeset is unmodified' %
local_path)
elif len(dl) > 1:
m = re.search(br'(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)', dl[1])
if m:
timestamp = m.group(1).decode('utf-8')
else:
# Thu Sep 3 11:24:48 2007
m = self.DATE_RE.search(dl[1])
if not m:
die('Unable to parse diff header: %s' % dl[1])
month_map = {
b'Jan': b'01',
b'Feb': b'02',
b'Mar': b'03',
b'Apr': b'04',
b'May': b'05',
b'Jun': b'06',
b'Jul': b'07',
b'Aug': b'08',
b'Sep': b'09',
b'Oct': b'10',
b'Nov': b'11',
b'Dec': b'12',
}
month = month_map[m.group(2)]
# here, figure out what version of git is installed and give
# the user a hint about what to do next.
version = execute([self.git, "svn", "--version"],
ignore_errors=True)
version_parts = re.search('version (\d+)\.(\d+)\.(\d+)',
version)
svn_remote = execute(
[self.git, "config", "--get", "svn-remote.svn.url"],
ignore_errors=True)
if (version_parts and svn_remote and
not is_valid_version((int(version_parts.group(1)),
int(version_parts.group(2)),
int(version_parts.group(3))),
(1, 5, 4))):
die("Your installation of git-svn must be upgraded to "
"version 1.5.4 or later")
# Okay, maybe Perforce (git-p4).
git_p4_ref = os.path.join(git_dir, 'refs', 'remotes', 'p4', 'master')
if os.path.exists(git_p4_ref):
data = execute([self.git, 'config', '--get', 'git-p4.port'],
ignore_errors=True)
m = re.search(r'(.+)', data)
if m:
port = m.group(1)
else:
port = os.getenv('P4PORT')
if port:
self.type = 'perforce'
self.upstream_branch = 'remotes/p4/master'
if options.rid:
die("Error getting review request %s: %s" % (options.rid, e))
else:
die("Error creating review request: %s" % e)
if not server.info.supports_changesets or not options.change_only:
try:
server.upload_diff(review_request, diff_content,
parent_diff_content)
except APIError, e:
sys.stderr.write('\n')
sys.stderr.write('Error uploading diff\n')
sys.stderr.write('\n')
if e.error_code == 101 and e.http_status == httplib.FORBIDDEN:
die('You do not have permissions to modify this review '
'request\n')
elif e.error_code == 219:
sys.stderr.write('The generated diff file was empty. This '
'usually means no files were\n')
sys.stderr.write('modified in this change.\n')
sys.stderr.write('\n')
sys.stderr.write('Try running with --output-diff and --debug '
'for more information.\n')
sys.stderr.write('\n')
die("Your review request still exists, but the diff is not " +
"attached.")
if options.reopen:
server.reopen(review_request)
def _get_remote_branch(self):
"""Return the remote branch assoicated with this repository.
If the remote branch is not defined, the parent branch of the
repository is returned.
"""
remote = getattr(self.options, 'tracking', None)
if not remote:
try:
remote = self._remote_path[0]
except IndexError:
remote = None
if not remote:
die('Could not determine remote branch to use for diff creation. '
'Specify --tracking-branch to continue.')
return remote
data = urllib2.urlopen(r).read()
try:
self.cookie_jar.save(self.cookie_file)
except IOError, e:
debug('Failed to write cookie file: %s' % e)
return data
except urllib2.HTTPError, e:
# Re-raise so callers can interpret it.
raise e
except urllib2.URLError, e:
try:
debug(e.read())
except AttributeError:
pass
die("Unable to access %s. The host path may be invalid\n%s"
% (url, e))
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 (httplib.UNAUTHORIZED, httplib.NOT_FOUND):
# 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 an UNAUTHORIZED from the application after you've
# done your http basic auth
die("Unable to access the root /api/ URL on the server.")
return False
# This is an older Review Board server with the old API.
self.deprecated_api = True
debug('Using the deprecated Review Board 1.0 web API')
return True
def tempt_fate(server, tool, changenum, diff_content=None,
parent_diff_content=None, 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_review_request(options.rid)
status = review_request['status']
if status == 'submitted':
die("Review request %s is marked as %s. In order to "
"update it, please reopen the request using the web "
"interface and try again." % (options.rid, status))
else:
review_request = server.new_review_request(changenum, submit_as)
if options.target_groups:
server.set_review_request_field(review_request, 'target_groups',
options.target_groups)
if options.target_people:
server.set_review_request_field(review_request, 'target_people',
options.target_people)
if options.summary:
server.set_review_request_field(review_request, 'summary',
options.summary)