<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import argparse <EOL> import json <EOL> import logging <EOL> import os <EOL> import re <EOL> import shlex <EOL> import subprocess <EOL> import sys <EOL> import time <EOL> if sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> import urllib as urllib_parse <EOL> import urllib2 as urllib_error <EOL> import urllib2 as urllib_request <EOL> else : <EOL> import urllib . error as urllib_error <EOL> import urllib . parse as urllib_parse <EOL> import urllib . request as urllib_request <EOL> sys . path . insert ( <NUM_LIT:0> , u'<STR_LIT:.>' ) <EOL> import utils . upload <EOL> class CLIHelper ( object ) : <EOL> """<STR_LIT>""" <EOL> def RunCommand ( self , command ) : <EOL> """<STR_LIT>""" <EOL> arguments = shlex . split ( command ) <EOL> process = subprocess . Popen ( <EOL> arguments , stderr = subprocess . PIPE , stdout = subprocess . PIPE ) <EOL> if not process : <EOL> logging . error ( u'<STR_LIT>' . format ( command ) ) <EOL> return <NUM_LIT:1> , None , None <EOL> output , error = process . communicate ( ) <EOL> if process . returncode != <NUM_LIT:0> : <EOL> logging . error ( u'<STR_LIT>' . format ( <EOL> command , error ) ) <EOL> return process . returncode , output , error <EOL> class CodeReviewHelper ( CLIHelper ) : <EOL> """<STR_LIT>""" <EOL> _REVIEWERS = frozenset ( [ <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' ] ) <EOL> _REVIEWERS_CC = frozenset ( [ <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' ] ) <EOL> def __init__ ( self , email_address , no_browser = False ) : <EOL> """<STR_LIT>""" <EOL> super ( CodeReviewHelper , self ) . __init__ ( ) <EOL> self . _access_token = None <EOL> self . _email_address = email_address <EOL> self . _no_browser = no_browser <EOL> self . _upload_py_path = os . path . join ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> self . _xsrf_token = None <EOL> def AddMergeMessage ( self , issue_number , message ) : <EOL> """<STR_LIT>""" <EOL> codereview_access_token = self . GetAccessToken ( ) <EOL> xsrf_token = self . GetXSRFToken ( ) <EOL> if not codereview_access_token or not xsrf_token : <EOL> return False <EOL> codereview_url = b'<STR_LIT>' . format ( <EOL> issue_number ) <EOL> post_data = urllib_parse . urlencode ( { <EOL> u'<STR_LIT>' : u'<STR_LIT:False>' , <EOL> u'<STR_LIT:message>' : message , <EOL> u'<STR_LIT>' : u'<STR_LIT:True>' , <EOL> u'<STR_LIT>' : '<STR_LIT:True>' , <EOL> u'<STR_LIT>' : '<STR_LIT:True>' , <EOL> u'<STR_LIT>' : xsrf_token } ) <EOL> request = urllib_request . Request ( codereview_url ) <EOL> request . add_header ( <EOL> u'<STR_LIT>' , u'<STR_LIT>' . format ( codereview_access_token ) ) <EOL> request . add_data ( post_data ) <EOL> try : <EOL> url_object = urllib_request . urlopen ( request ) <EOL> except urllib_error . HTTPError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> issue_number , exception ) ) <EOL> return False <EOL> if url_object . code not in ( <NUM_LIT:200> , <NUM_LIT> ) : <EOL> logging . error ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( issue_number , url_object . code ) ) <EOL> return False <EOL> return True <EOL> def CloseIssue ( self , issue_number ) : <EOL> """<STR_LIT>""" <EOL> codereview_access_token = self . GetAccessToken ( ) <EOL> xsrf_token = self . GetXSRFToken ( ) <EOL> if not codereview_access_token or not xsrf_token : <EOL> return False <EOL> codereview_url = b'<STR_LIT>' . format ( <EOL> issue_number ) <EOL> post_data = urllib_parse . urlencode ( { <EOL> u'<STR_LIT>' : xsrf_token } ) <EOL> request = urllib_request . Request ( codereview_url ) <EOL> request . add_header ( <EOL> u'<STR_LIT>' , u'<STR_LIT>' . format ( codereview_access_token ) ) <EOL> request . add_data ( post_data ) <EOL> try : <EOL> url_object = urllib_request . urlopen ( request ) <EOL> except urllib_error . HTTPError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> issue_number , exception ) ) <EOL> return False <EOL> if url_object . code != <NUM_LIT:200> : <EOL> logging . error ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( issue_number , url_object . code ) ) <EOL> return False <EOL> return True <EOL> def CreateIssue ( self , diffbase , description ) : <EOL> """<STR_LIT>""" <EOL> reviewers = list ( self . _REVIEWERS ) <EOL> reviewers_cc = list ( self . _REVIEWERS_CC ) <EOL> try : <EOL> reviewers . remove ( self . _email_address ) <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> reviewers_cc . remove ( self . _email_address ) <EOL> except ValueError : <EOL> pass <EOL> reviewers = u'<STR_LIT:U+002C>' . join ( reviewers ) <EOL> reviewers_cc = u'<STR_LIT:U+002C>' . join ( reviewers_cc ) <EOL> command = u'<STR_LIT>' . format ( <EOL> sys . executable , self . _upload_py_path ) <EOL> if self . _no_browser : <EOL> command = u'<STR_LIT>' . format ( command ) <EOL> command = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> command , reviewers , reviewers_cc , description , diffbase ) <EOL> if self . _no_browser : <EOL> print ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT:\n>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT:\n>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT:\n>' ) <EOL> print ( u'<STR_LIT>' , end = u'<STR_LIT:U+0020>' ) <EOL> sys . stdout . flush ( ) <EOL> exit_code , output , _ = self . RunCommand ( command ) <EOL> print ( output ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return <EOL> issue_url_line_start = ( <EOL> u'<STR_LIT>' ) <EOL> for line in output . split ( b'<STR_LIT:\n>' ) : <EOL> if issue_url_line_start in line : <EOL> _ , _ , issue_number = line . rpartition ( issue_url_line_start ) <EOL> try : <EOL> return int ( issue_number , <NUM_LIT:10> ) <EOL> except ValueError : <EOL> pass <EOL> def GetAccessToken ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _access_token : <EOL> self . _access_token = utils . upload . GetAccessToken ( ) <EOL> if not self . _access_token : <EOL> logging . error ( u'<STR_LIT>' ) <EOL> return self . _access_token <EOL> def GetXSRFToken ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _xsrf_token : <EOL> codereview_access_token = self . GetAccessToken ( ) <EOL> if not codereview_access_token : <EOL> return <EOL> codereview_url = b'<STR_LIT>' <EOL> request = urllib_request . Request ( codereview_url ) <EOL> request . add_header ( <EOL> u'<STR_LIT>' , u'<STR_LIT>' . format ( codereview_access_token ) ) <EOL> request . add_header ( u'<STR_LIT>' , u'<STR_LIT:1>' ) <EOL> try : <EOL> url_object = urllib_request . urlopen ( request ) <EOL> except urllib_error . HTTPError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> exception ) ) <EOL> return <EOL> if url_object . code != <NUM_LIT:200> : <EOL> logging . error ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( url_object . code ) ) <EOL> return <EOL> self . _xsrf_token = url_object . read ( ) <EOL> return self . _xsrf_token <EOL> def QueryIssue ( self , issue_number ) : <EOL> """<STR_LIT>""" <EOL> codereview_url = b'<STR_LIT>' . format ( <EOL> issue_number ) <EOL> request = urllib_request . Request ( codereview_url ) <EOL> try : <EOL> url_object = urllib_request . urlopen ( request ) <EOL> except urllib_error . HTTPError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> issue_number , exception ) ) <EOL> return <EOL> if url_object . code != <NUM_LIT:200> : <EOL> logging . error ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( issue_number , url_object . code ) ) <EOL> return <EOL> response_data = url_object . read ( ) <EOL> return json . loads ( response_data ) <EOL> def UpdateIssue ( self , issue_number , diffbase , description ) : <EOL> """<STR_LIT>""" <EOL> command = u'<STR_LIT>' . format ( <EOL> sys . executable , self . _upload_py_path ) <EOL> if self . _no_browser : <EOL> command = u'<STR_LIT>' . format ( command ) <EOL> command = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( command , issue_number , description , diffbase ) <EOL> exit_code , output , _ = self . RunCommand ( command ) <EOL> print ( output ) <EOL> return exit_code == <NUM_LIT:0> <EOL> class GitHelper ( CLIHelper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , git_repo_url ) : <EOL> """<STR_LIT>""" <EOL> super ( GitHelper , self ) . __init__ ( ) <EOL> self . _git_repo_url = git_repo_url <EOL> self . _remotes = [ ] <EOL> def _GetRemotes ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _remotes : <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code == <NUM_LIT:0> : <EOL> self . _remotes = output . split ( b'<STR_LIT:\n>' ) <EOL> return self . _remotes <EOL> def AddPath ( self , path ) : <EOL> """<STR_LIT>""" <EOL> command = u'<STR_LIT>' . format ( path ) <EOL> exit_code , _ , _ = self . RunCommand ( command ) <EOL> return exit_code == <NUM_LIT:0> <EOL> def CheckHasBranch ( self , branch ) : <EOL> """<STR_LIT>""" <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> for line in output . split ( b'<STR_LIT:\n>' ) : <EOL> if line [ <NUM_LIT:2> : ] == branch : <EOL> return True <EOL> return False <EOL> def CheckHasProjectOrigin ( self ) : <EOL> """<STR_LIT>""" <EOL> origin_git_repo_url = self . GetRemoteOrigin ( ) <EOL> return origin_git_repo_url == self . _git_repo_url <EOL> def CheckHasProjectUpstream ( self ) : <EOL> """<STR_LIT>""" <EOL> for remote in self . _GetRemotes ( ) : <EOL> if remote . startswith ( b'<STR_LIT>' . format ( self . _git_repo_url ) ) : <EOL> return True <EOL> return False <EOL> def CheckHasUncommittedChanges ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> for line in output . split ( b'<STR_LIT:\n>' ) : <EOL> if line : <EOL> return True <EOL> return False <EOL> def CheckSynchronizedWithUpstream ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , _ , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> exit_code , output , _ = self . RunCommand ( <EOL> u'<STR_LIT>' ) <EOL> return exit_code == <NUM_LIT:0> and not output <EOL> def CommitToOriginInNameOf ( <EOL> self , codereview_issue_number , author , description ) : <EOL> """<STR_LIT>""" <EOL> command = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> author , codereview_issue_number , description ) <EOL> exit_code , _ , _ = self . RunCommand ( command ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> exit_code , _ , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> return True <EOL> def DropUncommittedChanges ( self ) : <EOL> """<STR_LIT>""" <EOL> self . RunCommand ( u'<STR_LIT>' ) <EOL> self . RunCommand ( u'<STR_LIT>' ) <EOL> def GetActiveBranch ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> for line in output . split ( b'<STR_LIT:\n>' ) : <EOL> if line . startswith ( b'<STR_LIT>' ) : <EOL> return line [ <NUM_LIT:2> : ] <EOL> return <EOL> def GetChangedFiles ( self , diffbase = None ) : <EOL> """<STR_LIT>""" <EOL> if diffbase : <EOL> command = u'<STR_LIT>' . format ( diffbase ) <EOL> else : <EOL> command = u'<STR_LIT>' <EOL> exit_code , output , _ = self . RunCommand ( command ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return [ ] <EOL> return output . split ( b'<STR_LIT:\n>' ) <EOL> def GetChangedPythonFiles ( self , diffbase = None ) : <EOL> """<STR_LIT>""" <EOL> upload_path = os . path . join ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> python_files = [ ] <EOL> for changed_file in self . GetChangedFiles ( diffbase = diffbase ) : <EOL> if ( not changed_file . endswith ( u'<STR_LIT>' ) or <EOL> changed_file . endswith ( u'<STR_LIT>' ) or <EOL> not os . path . exists ( changed_file ) or <EOL> changed_file . startswith ( u'<STR_LIT>' ) or <EOL> changed_file . startswith ( u'<STR_LIT>' ) or <EOL> changed_file in ( u'<STR_LIT>' , upload_path ) ) : <EOL> continue <EOL> python_files . append ( changed_file ) <EOL> return python_files <EOL> def GetEmailAddress ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return <EOL> output_lines = output . split ( b'<STR_LIT:\n>' ) <EOL> if not output_lines : <EOL> return <EOL> return output_lines [ <NUM_LIT:0> ] <EOL> def GetLastCommitMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return <EOL> output_lines = output . split ( b'<STR_LIT:\n>' ) <EOL> if len ( output_lines ) != <NUM_LIT:6> : <EOL> return <EOL> return output_lines [ <NUM_LIT:4> ] . strip ( ) <EOL> def GetRemoteOrigin ( self ) : <EOL> """<STR_LIT>""" <EOL> for remote in self . _GetRemotes ( ) : <EOL> if remote . startswith ( b'<STR_LIT>' ) : <EOL> values = remote . split ( ) <EOL> if len ( values ) == <NUM_LIT:3> : <EOL> return values [ <NUM_LIT:1> ] <EOL> def PullFromFork ( self , git_repo_url , branch ) : <EOL> """<STR_LIT>""" <EOL> command = u'<STR_LIT>' . format ( git_repo_url , branch ) <EOL> exit_code , _ , _ = self . RunCommand ( command ) <EOL> return exit_code == <NUM_LIT:0> <EOL> def PushToOrigin ( self , branch , force = False ) : <EOL> """<STR_LIT>""" <EOL> if force : <EOL> command = u'<STR_LIT>' . format ( branch ) <EOL> else : <EOL> command = u'<STR_LIT>' . format ( branch ) <EOL> exit_code , _ , _ = self . RunCommand ( command ) <EOL> return exit_code == <NUM_LIT:0> <EOL> def RemoveFeatureBranch ( self , branch ) : <EOL> """<STR_LIT>""" <EOL> if branch == u'<STR_LIT>' : <EOL> return <EOL> self . RunCommand ( u'<STR_LIT>' . format ( branch ) ) <EOL> self . RunCommand ( u'<STR_LIT>' . format ( branch ) ) <EOL> def SynchronizeWithOrigin ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , _ , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> exit_code , _ , _ = self . RunCommand ( <EOL> u'<STR_LIT>' ) <EOL> return exit_code == <NUM_LIT:0> <EOL> def SynchronizeWithUpstream ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , _ , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> exit_code , _ , _ = self . RunCommand ( <EOL> u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> exit_code , _ , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> return exit_code == <NUM_LIT:0> <EOL> def SwitchToMasterBranch ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , _ , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> return exit_code != <NUM_LIT:0> <EOL> class GitHubHelper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , organization , project ) : <EOL> """<STR_LIT>""" <EOL> super ( GitHubHelper , self ) . __init__ ( ) <EOL> self . _organization = organization <EOL> self . _project = project <EOL> def CreatePullRequest ( <EOL> self , access_token , codereview_issue_number , origin , description ) : <EOL> """<STR_LIT>""" <EOL> title = b'<STR_LIT>' . format ( codereview_issue_number , description ) <EOL> body = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) . format ( <EOL> codereview_issue_number , description ) <EOL> post_data = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) . format ( title , body , origin ) <EOL> github_url = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> self . _organization , self . _project , access_token ) <EOL> request = urllib_request . Request ( github_url ) <EOL> request . add_data ( post_data ) <EOL> try : <EOL> url_object = urllib_request . urlopen ( request ) <EOL> except urllib_error . HTTPError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> codereview_issue_number , exception ) ) <EOL> return False <EOL> if url_object . code not in ( <NUM_LIT:200> , <NUM_LIT> ) : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> codereview_issue_number , url_object . code ) ) <EOL> return False <EOL> return True <EOL> def GetForkGitRepoUrl ( self , username ) : <EOL> """<STR_LIT>""" <EOL> return u'<STR_LIT>' . format ( username , self . _project ) <EOL> def QueryUser ( self , username ) : <EOL> """<STR_LIT>""" <EOL> github_url = b'<STR_LIT>' . format ( username ) <EOL> request = urllib_request . Request ( github_url ) <EOL> try : <EOL> url_object = urllib_request . urlopen ( request ) <EOL> except urllib_error . HTTPError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> username , exception ) ) <EOL> return <EOL> if url_object . code != <NUM_LIT:200> : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> username , url_object . code ) ) <EOL> return <EOL> response_data = url_object . read ( ) <EOL> return json . loads ( response_data ) <EOL> class ProjectHelper ( object ) : <EOL> """<STR_LIT>""" <EOL> SUPPORTED_PROJECTS = frozenset ( [ <EOL> u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' ] ) <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( ProjectHelper , self ) . __init__ ( ) <EOL> self . _project_name = None <EOL> self . _version_file_path = None <EOL> def _ReadVersionFile ( self ) : <EOL> """<STR_LIT>""" <EOL> project_name = self . GetName ( ) <EOL> if not project_name : <EOL> logging . error ( u'<STR_LIT>' ) <EOL> return <EOL> self . _version_file_path = os . path . join ( project_name , u'<STR_LIT>' ) <EOL> if not os . path . exists ( self . _version_file_path ) : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( self . _version_file_path ) ) <EOL> return <EOL> try : <EOL> with open ( self . _version_file_path , u'<STR_LIT:rb>' ) as file_object : <EOL> version_file_contents = file_object . read ( ) <EOL> except IOError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( exception ) ) <EOL> return <EOL> try : <EOL> version_file_contents = version_file_contents . decode ( u'<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( exception ) ) <EOL> return <EOL> return version_file_contents <EOL> def GetName ( self , path = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _project_name : <EOL> return self . _project_name <EOL> if not path : <EOL> path = os . path . abspath ( __file__ ) <EOL> project_name = path <EOL> project_name = os . path . dirname ( project_name ) <EOL> project_name = os . path . dirname ( project_name ) <EOL> project_name = os . path . basename ( project_name ) <EOL> for supported_project_name in self . SUPPORTED_PROJECTS : <EOL> if supported_project_name in project_name : <EOL> self . _project_name = supported_project_name <EOL> return self . _project_name <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( project_name ) ) <EOL> return <EOL> def GetVersion ( self ) : <EOL> """<STR_LIT>""" <EOL> version_file_contents = self . _ReadVersionFile ( ) <EOL> if not version_file_contents : <EOL> return <EOL> version_line_prefix = u'<STR_LIT>' <EOL> lines = version_file_contents . split ( u'<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if line . startswith ( version_line_prefix ) : <EOL> return line [ len ( version_line_prefix ) : - <NUM_LIT:1> ] <EOL> return <EOL> def UpdateDpkgChangelogFile ( self ) : <EOL> """<STR_LIT>""" <EOL> project_name = self . GetName ( ) <EOL> project_version = self . GetVersion ( ) <EOL> dpkg_changelog_path = os . path . join ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> if not os . path . exists ( dpkg_changelog_path ) : <EOL> return True <EOL> dpkg_maintainter = u'<STR_LIT>' <EOL> dpkg_date = time . strftime ( u'<STR_LIT>' ) <EOL> dpkg_changelog_content = u'<STR_LIT:\n>' . join ( [ <EOL> u'<STR_LIT>' . format ( <EOL> project_name , project_version ) , <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' . format ( dpkg_maintainter , dpkg_date ) ] ) <EOL> try : <EOL> dpkg_changelog_content = dpkg_changelog_content . encode ( u'<STR_LIT:utf-8>' ) <EOL> except UnicodeEncodeError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> exception ) ) <EOL> return False <EOL> try : <EOL> with open ( dpkg_changelog_path , u'<STR_LIT:wb>' ) as file_object : <EOL> file_object . write ( dpkg_changelog_content ) <EOL> except IOError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> exception ) ) <EOL> return False <EOL> return True <EOL> def UpdateVersionFile ( self ) : <EOL> """<STR_LIT>""" <EOL> version_file_contents = self . _ReadVersionFile ( ) <EOL> if not version_file_contents : <EOL> logging . error ( u'<STR_LIT>' ) <EOL> return False <EOL> date_version = time . strftime ( u'<STR_LIT>' ) <EOL> project_name = self . GetName ( ) <EOL> lines = version_file_contents . split ( u'<STR_LIT:\n>' ) <EOL> for line_index , line in enumerate ( lines ) : <EOL> if project_name == u'<STR_LIT>' and line . startswith ( u'<STR_LIT>' ) : <EOL> version_string = u'<STR_LIT>' . format ( date_version ) <EOL> lines [ line_index ] = version_string <EOL> elif project_name != u'<STR_LIT>' and line . startswith ( u'<STR_LIT>' ) : <EOL> version_string = u'<STR_LIT>' . format ( date_version ) <EOL> lines [ line_index ] = version_string <EOL> version_file_contents = u'<STR_LIT:\n>' . join ( lines ) <EOL> try : <EOL> version_file_contents = version_file_contents . encode ( u'<STR_LIT:utf-8>' ) <EOL> except UnicodeEncodeError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( exception ) ) <EOL> return False <EOL> try : <EOL> with open ( self . _version_file_path , u'<STR_LIT:wb>' ) as file_object : <EOL> file_object . write ( version_file_contents ) <EOL> except IOError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( exception ) ) <EOL> return False <EOL> return True <EOL> class PylintHelper ( CLIHelper ) : <EOL> """<STR_LIT>""" <EOL> _MINIMUM_VERSION_TUPLE = ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:0> ) <EOL> def CheckFiles ( self , filenames ) : <EOL> """<STR_LIT>""" <EOL> print ( u'<STR_LIT>' ) <EOL> failed_filenames = [ ] <EOL> for filename in filenames : <EOL> print ( u'<STR_LIT>' . format ( filename ) ) <EOL> command = u'<STR_LIT>' . format ( filename ) <EOL> exit_code = subprocess . call ( command , shell = True ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> failed_filenames . append ( filename ) <EOL> if failed_filenames : <EOL> print ( u'<STR_LIT>' . format ( <EOL> u'<STR_LIT:\n>' . join ( failed_filenames ) ) ) <EOL> return False <EOL> return True <EOL> def CheckUpToDateVersion ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> version_tuple = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> for line in output . split ( b'<STR_LIT:\n>' ) : <EOL> if line . startswith ( b'<STR_LIT>' ) : <EOL> _ , _ , version = line . partition ( b'<STR_LIT:U+0020>' ) <EOL> version , _ , _ = version . partition ( b'<STR_LIT:U+002C>' ) <EOL> version_tuple = tuple ( [ int ( digit ) for digit in version . split ( b'<STR_LIT:.>' ) ] ) <EOL> return version_tuple >= self . _MINIMUM_VERSION_TUPLE <EOL> class ReadTheDocsHelper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , project ) : <EOL> """<STR_LIT>""" <EOL> super ( ReadTheDocsHelper , self ) . __init__ ( ) <EOL> self . _project = project <EOL> def TriggerBuild ( self ) : <EOL> """<STR_LIT>""" <EOL> readthedocs_url = u'<STR_LIT>' . format ( <EOL> self . _project ) <EOL> request = urllib_request . Request ( readthedocs_url ) <EOL> request . add_data ( b'<STR_LIT>' ) <EOL> try : <EOL> url_object = urllib_request . urlopen ( request ) <EOL> except urllib_error . HTTPError as exception : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> exception ) ) <EOL> return False <EOL> if url_object . code != <NUM_LIT:200> : <EOL> logging . error ( <EOL> u'<STR_LIT>' . format ( <EOL> url_object . code ) ) <EOL> return False <EOL> return True <EOL> class SphinxAPIDocHelper ( CLIHelper ) : <EOL> """<STR_LIT>""" <EOL> _MINIMUM_VERSION_TUPLE = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> def __init__ ( self , project ) : <EOL> """<STR_LIT>""" <EOL> super ( SphinxAPIDocHelper , self ) . __init__ ( ) <EOL> self . _project = project <EOL> def CheckUpToDateVersion ( self ) : <EOL> """<STR_LIT>""" <EOL> exit_code , output , _ = self . RunCommand ( u'<STR_LIT>' ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> return False <EOL> version_tuple = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> for line in output . split ( b'<STR_LIT:\n>' ) : <EOL> if line . startswith ( b'<STR_LIT>' ) : <EOL> _ , _ , version = line . rpartition ( b'<STR_LIT:U+0020>' ) <EOL> version_tuple = tuple ( [ int ( digit ) for digit in version . split ( b'<STR_LIT:.>' ) ] ) <EOL> return version_tuple >= self . _MINIMUM_VERSION_TUPLE <EOL> def UpdateAPIDocs ( self ) : <EOL> """<STR_LIT>""" <EOL> command = u'<STR_LIT>' . format ( self . _project ) <EOL> exit_code , output , _ = self . RunCommand ( command ) <EOL> print ( output ) <EOL> return exit_code == <NUM_LIT:0> <EOL> class NetRCFile ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( NetRCFile , self ) . __init__ ( ) <EOL> self . _contents = None <EOL> self . _values = None <EOL> home_path = os . path . expanduser ( u'<STR_LIT>' ) <EOL> self . _path = os . path . join ( home_path , u'<STR_LIT>' ) <EOL> if not os . path . exists ( self . _path ) : <EOL> return <EOL> with open ( self . _path , '<STR_LIT:r>' ) as file_object : <EOL> self . _contents = file_object . read ( ) <EOL> def _GetGitHubValues ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _contents : <EOL> return <EOL> if not self . _values : <EOL> for line in self . _contents . split ( b'<STR_LIT:\n>' ) : <EOL> if line . startswith ( b'<STR_LIT>' ) : <EOL> self . _values = line . split ( b'<STR_LIT:U+0020>' ) <EOL> break <EOL> return self . _values [ <NUM_LIT:2> : ] <EOL> def GetGitHubAccessToken ( self ) : <EOL> """<STR_LIT>""" <EOL> values = self . _GetGitHubValues ( ) <EOL> if not values : <EOL> return <EOL> for value_index , value in enumerate ( values ) : <EOL> if value == u'<STR_LIT:password>' : <EOL> return values [ value_index + <NUM_LIT:1> ] <EOL> def GetGitHubUsername ( self ) : <EOL> """<STR_LIT>""" <EOL> values = self . _GetGitHubValues ( ) <EOL> if not values : <EOL> return <EOL> for value_index , value in enumerate ( values ) : <EOL> if value == u'<STR_LIT:username>' : <EOL> return values [ value_index + <NUM_LIT:1> ] <EOL> class ReviewFile ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , branch_name ) : <EOL> """<STR_LIT>""" <EOL> super ( ReviewFile , self ) . __init__ ( ) <EOL> self . _contents = None <EOL> self . _path = os . path . join ( u'<STR_LIT>' , branch_name ) <EOL> if not os . path . exists ( self . _path ) : <EOL> return <EOL> with open ( self . _path , '<STR_LIT:r>' ) as file_object : <EOL> self . _contents = file_object . read ( ) <EOL> def Create ( self , codereview_issue_number ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( u'<STR_LIT>' ) : <EOL> os . mkdir ( u'<STR_LIT>' ) <EOL> with open ( self . _path , '<STR_LIT:w>' ) as file_object : <EOL> file_object . write ( u'<STR_LIT>' . format ( codereview_issue_number ) ) <EOL> def GetCodeReviewIssueNumber ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _contents : <EOL> return <EOL> try : <EOL> return int ( self . _contents , <NUM_LIT:10> ) <EOL> except ValueError : <EOL> pass <EOL> def Remove ( self ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( self . _path ) : <EOL> return <EOL> os . remove ( self . _path ) <EOL> class ReviewHelper ( object ) : <EOL> """<STR_LIT>""" <EOL> _PROJECT_NAME_PREFIX_REGEX = re . compile ( <EOL> r'<STR_LIT>' . format ( u'<STR_LIT:|>' . join ( ProjectHelper . SUPPORTED_PROJECTS ) ) ) <EOL> def __init__ ( <EOL> self , command , github_origin , feature_branch , diffbase , all_files = False , <EOL> no_browser = False , no_confirm = False ) : <EOL> """<STR_LIT>""" <EOL> super ( ReviewHelper , self ) . __init__ ( ) <EOL> self . _active_branch = None <EOL> self . _all_files = all_files <EOL> self . _codereview_helper = None <EOL> self . _command = command <EOL> self . _diffbase = diffbase <EOL> self . _feature_branch = feature_branch <EOL> self . _git_helper = None <EOL> self . _git_repo_url = None <EOL> self . _github_helper = None <EOL> self . _github_origin = github_origin <EOL> self . _fork_feature_branch = None <EOL> self . _fork_username = None <EOL> self . _merge_author = None <EOL> self . _merge_description = None <EOL> self . _no_browser = no_browser <EOL> self . _no_confirm = no_confirm <EOL> self . _project_helper = None <EOL> self . _project_name = None <EOL> self . _sphinxapidoc_helper = None <EOL> def CheckLocalGitState ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _command in ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> if not self . _git_helper . CheckHasProjectUpstream ( ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> print ( u'<STR_LIT>' . format ( self . _git_repo_url ) ) <EOL> return False <EOL> elif self . _command == u'<STR_LIT>' : <EOL> if not self . _git_helper . CheckHasProjectOrigin ( ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> if self . _command not in ( <EOL> u'<STR_LIT>' , u'<STR_LIT:test>' , u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> if self . _git_helper . CheckHasUncommittedChanges ( ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> self . _active_branch = self . _git_helper . GetActiveBranch ( ) <EOL> if self . _command in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> if self . _active_branch == u'<STR_LIT>' : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> elif self . _command == u'<STR_LIT>' : <EOL> if self . _feature_branch == u'<STR_LIT>' : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> if self . _active_branch != u'<STR_LIT>' : <EOL> self . _git_helper . SwitchToMasterBranch ( ) <EOL> self . _active_branch = u'<STR_LIT>' <EOL> return True <EOL> def CheckRemoteGitState ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _command == u'<STR_LIT>' : <EOL> if not self . _git_helper . SynchronizeWithUpstream ( ) : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( self . _command . title ( ) ) ) <EOL> return False <EOL> elif self . _command in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> if not self . _git_helper . CheckSynchronizedWithUpstream ( ) : <EOL> if not self . _git_helper . SynchronizeWithUpstream ( ) : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( self . _command . title ( ) ) ) <EOL> return False <EOL> force_push = True <EOL> else : <EOL> force_push = False <EOL> if not self . _git_helper . PushToOrigin ( <EOL> self . _active_branch , force = force_push ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) , self . _active_branch ) ) <EOL> return False <EOL> elif self . _command == u'<STR_LIT>' : <EOL> self . _git_helper . CheckSynchronizedWithUpstream ( ) <EOL> elif self . _command == u'<STR_LIT>' : <EOL> if not self . _git_helper . SynchronizeWithOrigin ( ) : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( self . _command . title ( ) ) ) <EOL> return False <EOL> return True <EOL> def Close ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _git_helper . CheckHasBranch ( self . _feature_branch ) : <EOL> print ( u'<STR_LIT>' . format ( self . _feature_branch ) ) <EOL> else : <EOL> self . _git_helper . RemoveFeatureBranch ( self . _feature_branch ) <EOL> review_file = ReviewFile ( self . _feature_branch ) <EOL> codereview_issue_number = review_file . GetCodeReviewIssueNumber ( ) <EOL> review_file . Remove ( ) <EOL> if codereview_issue_number : <EOL> if not self . _codereview_helper . CloseIssue ( codereview_issue_number ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> codereview_issue_number ) ) <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( codereview_issue_number ) ) <EOL> return True <EOL> def Create ( self ) : <EOL> """<STR_LIT>""" <EOL> git_origin = self . _git_helper . GetRemoteOrigin ( ) <EOL> if not git_origin . startswith ( u'<STR_LIT>' ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) , git_origin ) ) <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> git_origin , _ , _ = git_origin [ len ( u'<STR_LIT>' ) : ] . rpartition ( u'<STR_LIT:/>' ) <EOL> netrc_file = NetRCFile ( ) <EOL> github_access_token = netrc_file . GetGitHubAccessToken ( ) <EOL> if not github_access_token : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> last_commit_message = self . _git_helper . GetLastCommitMessage ( ) <EOL> print ( u'<STR_LIT>' ) <EOL> print ( last_commit_message ) <EOL> print ( u'<STR_LIT>' ) <EOL> if self . _no_confirm : <EOL> user_input = None <EOL> else : <EOL> print ( u'<STR_LIT>' ) <EOL> print ( u'<STR_LIT>' ) <EOL> user_input = sys . stdin . readline ( ) <EOL> user_input = user_input . strip ( ) <EOL> if not user_input : <EOL> description = last_commit_message <EOL> else : <EOL> description = user_input <EOL> code_review_description = u'<STR_LIT>' . format ( <EOL> self . _project_name , description ) <EOL> codereview_issue_number = self . _codereview_helper . CreateIssue ( <EOL> self . _diffbase , code_review_description ) <EOL> if not codereview_issue_number : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> if not os . path . isdir ( u'<STR_LIT>' ) : <EOL> os . mkdir ( u'<STR_LIT>' ) <EOL> review_file = ReviewFile ( self . _active_branch ) <EOL> review_file . Create ( codereview_issue_number ) <EOL> create_github_origin = u'<STR_LIT>' . format ( <EOL> git_origin , self . _active_branch ) <EOL> if not self . _github_helper . CreatePullRequest ( <EOL> github_access_token , codereview_issue_number , create_github_origin , <EOL> description ) : <EOL> print ( u'<STR_LIT>' ) <EOL> return True <EOL> def InitializeHelpers ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _project_helper = ProjectHelper ( ) <EOL> self . _project_name = self . _project_helper . GetName ( ) <EOL> if not self . _project_name : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> self . _git_repo_url = b'<STR_LIT>' . format ( <EOL> self . _project_name ) <EOL> self . _git_helper = GitHelper ( self . _git_repo_url ) <EOL> self . _github_helper = GitHubHelper ( u'<STR_LIT>' , self . _project_name ) <EOL> if self . _command in ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> email_address = self . _git_helper . GetEmailAddress ( ) <EOL> self . _codereview_helper = CodeReviewHelper ( <EOL> email_address , no_browser = self . _no_browser ) <EOL> if self . _command == u'<STR_LIT>' : <EOL> self . _sphinxapidoc_helper = SphinxAPIDocHelper ( <EOL> self . _project_name ) <EOL> if not self . _sphinxapidoc_helper . CheckUpToDateVersion ( ) : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( self . _command . title ( ) ) ) <EOL> return False <EOL> return True <EOL> def Lint ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _project_name == u'<STR_LIT>' : <EOL> return True <EOL> if self . _command not in ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> return True <EOL> pylint_helper = PylintHelper ( ) <EOL> if not pylint_helper . CheckUpToDateVersion ( ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> if self . _command == u'<STR_LIT>' : <EOL> fork_git_repo_url = self . _github_helper . GetForkGitRepoUrl ( <EOL> self . _fork_username ) <EOL> if not self . _git_helper . PullFromFork ( <EOL> fork_git_repo_url , self . _fork_feature_branch ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> if self . _all_files : <EOL> diffbase = None <EOL> elif self . _command == u'<STR_LIT>' : <EOL> diffbase = u'<STR_LIT>' <EOL> else : <EOL> diffbase = self . _diffbase <EOL> changed_python_files = self . _git_helper . GetChangedPythonFiles ( <EOL> diffbase = diffbase ) <EOL> if not pylint_helper . CheckFiles ( changed_python_files ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> if self . _command == u'<STR_LIT>' : <EOL> self . _git_helper . DropUncommittedChanges ( ) <EOL> return False <EOL> return True <EOL> def Merge ( self , codereview_issue_number ) : <EOL> """<STR_LIT>""" <EOL> if not self . _project_helper . UpdateVersionFile ( ) : <EOL> print ( u'<STR_LIT>' ) <EOL> self . _git_helper . DropUncommittedChanges ( ) <EOL> return False <EOL> if not self . _project_helper . UpdateDpkgChangelogFile ( ) : <EOL> print ( u'<STR_LIT>' ) <EOL> self . _git_helper . DropUncommittedChanges ( ) <EOL> return False <EOL> apidoc_config_path = os . path . join ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> if os . path . exists ( apidoc_config_path ) : <EOL> self . _sphinxapidoc_helper . UpdateAPIDocs ( ) <EOL> self . _git_helper . AddPath ( u'<STR_LIT>' ) <EOL> readthedocs_helper = ReadTheDocsHelper ( self . _project_name ) <EOL> readthedocs_helper . TriggerBuild ( ) <EOL> if not self . _git_helper . CommitToOriginInNameOf ( <EOL> codereview_issue_number , self . _merge_author , self . _merge_description ) : <EOL> print ( u'<STR_LIT>' ) <EOL> self . _git_helper . DropUncommittedChanges ( ) <EOL> return False <EOL> commit_message = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> self . _fork_feature_branch ) <EOL> self . _codereview_helper . AddMergeMessage ( <EOL> codereview_issue_number , commit_message ) <EOL> return True <EOL> def Open ( self , codereview_issue_number ) : <EOL> """<STR_LIT>""" <EOL> _ = codereview_issue_number <EOL> return False <EOL> def PrepareMerge ( self , codereview_issue_number ) : <EOL> """<STR_LIT>""" <EOL> codereview_information = self . _codereview_helper . QueryIssue ( <EOL> codereview_issue_number ) <EOL> if not codereview_information : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> self . _command . title ( ) , codereview_issue_number ) ) <EOL> return False <EOL> self . _merge_description = codereview_information . get ( u'<STR_LIT>' , None ) <EOL> if not self . _merge_description : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> self . _command . title ( ) , codereview_issue_number ) ) <EOL> return False <EOL> self . _merge_description = self . _PROJECT_NAME_PREFIX_REGEX . sub ( <EOL> u'<STR_LIT>' , self . _merge_description ) <EOL> merge_email_address = codereview_information . get ( u'<STR_LIT>' , None ) <EOL> if not merge_email_address : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> self . _command . title ( ) , codereview_issue_number ) ) <EOL> return False <EOL> self . _fork_username , _ , self . _fork_feature_branch = ( <EOL> self . _github_origin . partition ( u'<STR_LIT::>' ) ) <EOL> github_user_information = self . _github_helper . QueryUser ( <EOL> self . _fork_username ) <EOL> if not github_user_information : <EOL> print ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) . format ( <EOL> self . _command . title ( ) , self . _fork_username ) ) <EOL> return False <EOL> merge_fullname = github_user_information . get ( u'<STR_LIT:name>' , None ) <EOL> if not merge_fullname : <EOL> merge_fullname = codereview_information . get ( u'<STR_LIT>' , None ) <EOL> if not merge_fullname : <EOL> merge_fullname = github_user_information . get ( u'<STR_LIT>' , None ) <EOL> if not merge_fullname : <EOL> print ( ( <EOL> u'<STR_LIT>' ) . format ( <EOL> self . _command . title ( ) ) ) <EOL> return False <EOL> self . _merge_author = u'<STR_LIT>' . format ( <EOL> merge_fullname , merge_email_address ) <EOL> return True <EOL> def Test ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _project_name == u'<STR_LIT>' : <EOL> return True <EOL> if self . _command not in ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT:test>' , u'<STR_LIT>' ) : <EOL> return True <EOL> command = u'<STR_LIT>' . format ( sys . executable ) <EOL> exit_code = subprocess . call ( command , shell = True ) <EOL> if exit_code != <NUM_LIT:0> : <EOL> print ( u'<STR_LIT>' . format ( <EOL> self . _command . title ( ) ) ) <EOL> if self . _command == u'<STR_LIT>' : <EOL> self . _git_helper . DropUncommittedChanges ( ) <EOL> return False <EOL> return True <EOL> def Update ( self ) : <EOL> """<STR_LIT>""" <EOL> review_file = ReviewFile ( self . _active_branch ) <EOL> codereview_issue_number = review_file . GetCodeReviewIssueNumber ( ) <EOL> last_commit_message = self . _git_helper . GetLastCommitMessage ( ) <EOL> print ( u'<STR_LIT>' ) <EOL> print ( last_commit_message ) <EOL> print ( u'<STR_LIT>' ) <EOL> if self . _no_confirm : <EOL> user_input = None <EOL> else : <EOL> print ( u'<STR_LIT>' ) <EOL> print ( u'<STR_LIT>' ) <EOL> user_input = sys . stdin . readline ( ) <EOL> user_input = user_input . strip ( ) <EOL> if not user_input : <EOL> description = last_commit_message <EOL> else : <EOL> description = user_input <EOL> if not self . _codereview_helper . UpdateIssue ( <EOL> codereview_issue_number , self . _diffbase , description ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> codereview_issue_number ) ) <EOL> return False <EOL> return True <EOL> def UpdateVersion ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _project_name == u'<STR_LIT>' : <EOL> return True <EOL> if not self . _project_helper . UpdateVersionFile ( ) : <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> if not self . _project_helper . UpdateDpkgChangelogFile ( ) : <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> return False <EOL> def Main ( ) : <EOL> """<STR_LIT>""" <EOL> argument_parser = argparse . ArgumentParser ( <EOL> description = u'<STR_LIT>' ) <EOL> argument_parser . add_argument ( <EOL> u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , dest = u'<STR_LIT>' , <EOL> action = u'<STR_LIT:store_true>' , default = False , help = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) ) <EOL> argument_parser . add_argument ( <EOL> u'<STR_LIT>' , dest = u'<STR_LIT>' , action = u'<STR_LIT:store>' , type = str , <EOL> metavar = u'<STR_LIT>' , default = u'<STR_LIT>' , help = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) ) <EOL> argument_parser . add_argument ( <EOL> u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , dest = u'<STR_LIT>' , <EOL> action = u'<STR_LIT:store_true>' , default = False , help = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) ) <EOL> argument_parser . add_argument ( <EOL> u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , dest = u'<STR_LIT>' , <EOL> action = u'<STR_LIT:store_true>' , default = False , help = ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) ) <EOL> commands_parser = argument_parser . add_subparsers ( dest = u'<STR_LIT>' ) <EOL> close_command_parser = commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> close_command_parser . add_argument ( <EOL> u'<STR_LIT>' , action = u'<STR_LIT:store>' , metavar = u'<STR_LIT>' , default = None , <EOL> help = ( u'<STR_LIT>' ) ) <EOL> commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> merge_command_parser = commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> merge_command_parser . add_argument ( <EOL> u'<STR_LIT>' , action = u'<STR_LIT:store>' , <EOL> metavar = u'<STR_LIT>' , default = None , <EOL> help = ( u'<STR_LIT>' ) ) <EOL> merge_command_parser . add_argument ( <EOL> u'<STR_LIT>' , action = u'<STR_LIT:store>' , <EOL> metavar = u'<STR_LIT>' , default = None , <EOL> help = ( u'<STR_LIT>' ) ) <EOL> commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> open_command_parser = commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> open_command_parser . add_argument ( <EOL> u'<STR_LIT>' , action = u'<STR_LIT:store>' , <EOL> metavar = u'<STR_LIT>' , default = None , <EOL> help = ( u'<STR_LIT>' ) ) <EOL> open_command_parser . add_argument ( <EOL> u'<STR_LIT>' , action = u'<STR_LIT:store>' , metavar = u'<STR_LIT>' , default = None , <EOL> help = ( u'<STR_LIT>' ) ) <EOL> commands_parser . add_parser ( u'<STR_LIT:test>' ) <EOL> commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> commands_parser . add_parser ( u'<STR_LIT>' ) <EOL> options = argument_parser . parse_args ( ) <EOL> codereview_issue_number = None <EOL> feature_branch = None <EOL> github_origin = None <EOL> print_help_on_error = False <EOL> if options . command in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> feature_branch = getattr ( options , u'<STR_LIT>' , None ) <EOL> if not feature_branch : <EOL> print ( u'<STR_LIT>' ) <EOL> print_help_on_error = True <EOL> if options . command in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> codereview_issue_number = getattr ( <EOL> options , u'<STR_LIT>' , None ) <EOL> if not codereview_issue_number : <EOL> print ( u'<STR_LIT>' ) <EOL> print_help_on_error = True <EOL> if options . command == u'<STR_LIT>' : <EOL> github_origin = getattr ( options , u'<STR_LIT>' , None ) <EOL> if not github_origin : <EOL> print ( u'<STR_LIT>' ) <EOL> print_help_on_error = True <EOL> if print_help_on_error : <EOL> print ( u'<STR_LIT>' ) <EOL> argument_parser . print_help ( ) <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> home_path = os . path . expanduser ( u'<STR_LIT>' ) <EOL> netrc_path = os . path . join ( home_path , u'<STR_LIT>' ) <EOL> if not os . path . exists ( netrc_path ) : <EOL> print ( u'<STR_LIT>' . format ( <EOL> options . command . title ( ) ) ) <EOL> return False <EOL> review_helper = ReviewHelper ( <EOL> options . command , github_origin , feature_branch , <EOL> options . diffbase , all_files = options . all_files , <EOL> no_browser = options . no_browser , no_confirm = options . no_confirm ) <EOL> if not review_helper . InitializeHelpers ( ) : <EOL> return False <EOL> if not review_helper . CheckLocalGitState ( ) : <EOL> return False <EOL> if not review_helper . CheckRemoteGitState ( ) : <EOL> return False <EOL> if options . command == u'<STR_LIT>' : <EOL> if not review_helper . PrepareMerge ( codereview_issue_number ) : <EOL> return False <EOL> if not review_helper . Lint ( ) : <EOL> return False <EOL> if not review_helper . Test ( ) : <EOL> return False <EOL> result = False <EOL> if options . command == u'<STR_LIT>' : <EOL> result = review_helper . Create ( ) <EOL> elif options . command == u'<STR_LIT>' : <EOL> result = review_helper . Close ( ) <EOL> elif options . command == u'<STR_LIT>' : <EOL> result = review_helper . Merge ( codereview_issue_number ) <EOL> elif options . command == u'<STR_LIT>' : <EOL> result = review_helper . Open ( codereview_issue_number ) <EOL> elif options . command == u'<STR_LIT>' : <EOL> result = review_helper . Update ( ) <EOL> elif options . command in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> result = review_helper . UpdateVersion ( ) <EOL> return result <EOL> if __name__ == u'<STR_LIT:__main__>' : <EOL> if not Main ( ) : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> sys . exit ( <NUM_LIT:0> ) </s>
