Пример #1
0
    def initialize_scm_tool(self, client_name=None,
                            require_repository_info=True):
        """Initialize the SCM tool for the current working directory.

        Args:
            client_name (unicode, optional):
                A specific client name, which can come from the configuration.
                This can be used to disambiguate if there are nested
                repositories, or to speed up detection.

            require_repository_info (bool, optional):
                Whether information on a repository is required. This is the
                default. If disabled, this will return ``None`` for the
                repository information if a matching repository could not be
                found.

        Returns:
            tuple:
            A 2-tuple, containing the repository info structure and the tool
            instance.
        """
        repository_info, tool = scan_usable_client(
            self.config,
            self.options,
            client_name=client_name,
            require_repository_info=require_repository_info)

        try:
            tool.check_options()
        except OptionsCheckError as e:
            raise CommandError(six.text_type(e))

        return repository_info, tool
Пример #2
0
def get_review_info(ticket):
    u'''
    対象チケット情報から review board の review request 情報をとってきて返す
    大体 rbtools.postreview.main から取ってきてる
    '''

    home = os.environ['HOME']

    cookie = os.path.join(home, '.post-review-cookies.txt')
    user_config, configs = filesystem.load_config_files(home)

    postreview.parse_options([])
    options = postreview.options

    repository_info, tool = clients.scan_usable_client(options)

    tool.user_config = user_config
    tool.configs = configs

    tool.check_options()

    server_url = tool.scan_for_server(repository_info)

    server = postreview.ReviewBoardServer(server_url, repository_info, cookie)

    server.login()

    results = server.api_get('/api/review-requests/')

    ticket = unicode(ticket)

    requests = [rq for rq in results['review_requests'] if ticket in rq['bugs_closed']]

    return requests
Пример #3
0
 def initialize_scm_tool(self):
     """Initialize the SCM tool for the current working directory."""
     repository_info, tool = scan_usable_client(self.options)
     tool.user_config = self.config
     tool.configs = [self.config]
     tool.check_options()
     return repository_info, tool
Пример #4
0
    def test_scanning_nested_repos_2(self):
        """Testing scan_for_usable_client with nested repositories (svn inside
        git)
        """
        git_dir = os.path.join(self.testdata_dir, 'git-repo')
        svn_dir = os.path.join(self.testdata_dir, 'svn-repo')

        # Check out git first
        clone_dir = self.chdir_tmp()
        git_clone_dir = os.path.join(clone_dir, 'git-repo')
        os.mkdir(git_clone_dir)
        execute(['git', 'clone', git_dir, git_clone_dir],
                env=None, ignore_errors=False, extra_ignore_errors=())

        # Now check out svn.
        svn_clone_dir = os.path.join(git_clone_dir, 'svn-repo')
        os.chdir(git_clone_dir)
        execute(['svn', 'co', 'file://%s' % svn_dir, 'svn-repo'],
                env=None, ignore_errors=False, extra_ignore_errors=())

        os.chdir(svn_clone_dir)

        repository_info, tool = scan_usable_client({}, self.options)

        self.assertEqual(repository_info.local_path,
                         os.path.realpath(svn_clone_dir))
        self.assertEqual(type(tool), SVNClient)
Пример #5
0
    def test_scanning_nested_repos_2(self):
        """Testing scan_for_usable_client with nested repositories (svn inside
        git)
        """
        git_dir = os.path.join(self.testdata_dir, 'git-repo')
        svn_dir = os.path.join(self.testdata_dir, 'svn-repo')

        # Check out git first
        clone_dir = self.chdir_tmp()
        git_clone_dir = os.path.join(clone_dir, 'git-repo')
        os.mkdir(git_clone_dir)
        execute(['git', 'clone', git_dir, git_clone_dir],
                env=None,
                ignore_errors=False,
                extra_ignore_errors=())

        # Now check out svn.
        svn_clone_dir = os.path.join(git_clone_dir, 'svn-repo')
        os.chdir(git_clone_dir)
        execute(['svn', 'co', 'file://%s' % svn_dir, 'svn-repo'],
                env=None,
                ignore_errors=False,
                extra_ignore_errors=())

        os.chdir(svn_clone_dir)

        repository_info, tool = scan_usable_client({}, self.options)

        self.assertEqual(repository_info.local_path,
                         os.path.realpath(svn_clone_dir))
        self.assertEqual(type(tool), SVNClient)
Пример #6
0
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"]
    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)
Пример #7
0
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)
Пример #8
0
    def initialize_scm_tool(self, client_name=None):
        """Initialize the SCM tool for the current working directory."""
        repository_info, tool = scan_usable_client(self.options, client_name=client_name)
        tool.user_config = self.config
        tool.configs = [self.config]

        try:
            tool.check_options()
        except OptionsCheckError, e:
            sys.stderr.write("%s\n" % e)
            sys.exit(1)
Пример #9
0
    def initialize_scm_tool(self, client_name=None):
        """Initialize the SCM tool for the current working directory."""
        repository_info, tool = scan_usable_client(self.config,
                                                   self.options,
                                                   client_name=client_name)

        try:
            tool.check_options()
        except OptionsCheckError as e:
            raise CommandError('%s\n' % e)

        return repository_info, tool
Пример #10
0
    def initialize_scm_tool(self, client_name=None):
        """Initialize the SCM tool for the current working directory."""
        repository_info, tool = scan_usable_client(self.options,
                                                   client_name=client_name)
        tool.user_config = self.config
        tool.configs = [self.config]

        try:
            tool.check_options()
        except OptionsCheckError, e:
            sys.stderr.write('%s\n' % e)
            sys.exit(1)
Пример #11
0
    def initialize_scm_tool(self, client_name=None):
        """Initialize the SCM tool for the current working directory."""
        repository_info, tool = scan_usable_client(self.config,
                                                   self.options,
                                                   client_name=client_name)

        try:
            tool.check_options()
        except OptionsCheckError as e:
            raise CommandError('%s\n' % e)

        return repository_info, tool
Пример #12
0
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"]
    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('Home = %s' % homepath)

    repository_info, tool = scan_usable_client(options)
    tool.user_config = user_config
    tool.configs = configs

    # Verify that options specific to an SCM Client have not been mis-used.
    tool.check_options()

    # Try to find a valid Review Board server to use.
    if options.server:
        server_url = options.server
    else:
        server_url = tool.scan_for_server(repository_info)

    if not server_url:
        print "Unable to find a Review Board server for this source code tree."
        sys.exit(1)

    server = ReviewBoardServer(server_url, repository_info, cookie_file)

    # Handle the case where /api/ requires authorization (RBCommons).
    if not server.check_api_version():
        die("Unable to log in with the supplied username and password.")

    # Let's begin.
    server.login()

    tempt_fate(server)
Пример #13
0
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"]
    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('Home = %s' % homepath)

    repository_info, tool = scan_usable_client(options)
    tool.user_config = user_config
    tool.configs = configs

    # Verify that options specific to an SCM Client have not been mis-used.
    tool.check_options()

    # Try to find a valid Review Board server to use.
    if options.server:
        server_url = options.server
    else:
        server_url = tool.scan_for_server(repository_info)

    if not server_url:
        print "Unable to find a Review Board server for this source code tree."
        sys.exit(1)

    server = ReviewBoardServer(server_url, repository_info, cookie_file)

    # Handle the case where /api/ requires authorization (RBCommons).
    if not server.check_api_version():
        die("Unable to log in with the supplied username and password.")

    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)