예제 #1
0
    def ReadRootFile(self, filename):
        data = SCM.ReadRootFile(self, filename)
        if data:
            return data

        # Try to search on the subversion repository for the file.
        if not gcl:
            return None
        data = gcl.GetCachedFile(filename)
        logging.debug('%s:\n%s' % (filename, data))
        return data
예제 #2
0
 def testGetCodeReviewSettingFail(self):
     self.mox.StubOutWithMock(gcl, 'GetCachedFile')
     gcl.GetCachedFile(gcl.CODEREVIEW_SETTINGS_FILE).AndReturn('aaa\n'
                                                               ' c : d \n\r'
                                                               'e: f')
     self.mox.ReplayAll()
     try:
         gcl.GetCodeReviewSetting('c')
         self.fail()
     except gcl.gclient_utils.Error:
         pass
     self.assertEquals({}, gcl.CODEREVIEW_SETTINGS)
예제 #3
0
 def testGetCodeReviewSettingOk(self):
   self.mox.StubOutWithMock(gcl, 'GetCachedFile')
   gcl.GetCachedFile(gcl.CODEREVIEW_SETTINGS_FILE).AndReturn(
       'foo:bar\n'
       '# comment\n'
       ' c : d \n\r'
       'e: f')
   self.mox.ReplayAll()
   self.assertEquals('bar', gcl.GetCodeReviewSetting('foo'))
   self.assertEquals('d', gcl.GetCodeReviewSetting('c'))
   self.assertEquals('f', gcl.GetCodeReviewSetting('e'))
   self.assertEquals('', gcl.GetCodeReviewSetting('other'))
   self.assertEquals(
       {'foo': 'bar', 'c': 'd', 'e': 'f', '__just_initialized': None},
       gcl.CODEREVIEW_SETTINGS)
예제 #4
0
def TryChange(argv, file_list, swallow_exception, prog=None):
    """
  Args:
    argv: Arguments and options.
    file_list: Default value to pass to --file.
    swallow_exception: Whether we raise or swallow exceptions.
  """
    default_settings = GetTryServerSettings()
    transport_functions = {'http': _SendChangeHTTP, 'svn': _SendChangeSVN}
    default_transport = transport_functions.get(
        default_settings.get('default_transport'))

    # Parse argv
    parser = optparse.OptionParser(usage=USAGE, version=__version__, prog=prog)

    group = optparse.OptionGroup(parser, "Result and status")
    group.add_option("-u",
                     "--user",
                     default=getpass.getuser(),
                     help="Owner user name [default: %default]")
    group.add_option(
        "-e",
        "--email",
        default=os.environ.get('TRYBOT_RESULTS_EMAIL_ADDRESS',
                               os.environ.get('EMAIL_ADDRESS')),
        help="Email address where to send the results. Use either "
        "the TRYBOT_RESULTS_EMAIL_ADDRESS environment "
        "variable or EMAIL_ADDRESS to set the email address "
        "the try bots report results to [default: %default]")
    group.add_option("-n", "--name", help="Descriptive name of the try job")
    group.add_option("--issue",
                     type='int',
                     help="Update rietveld issue try job status")
    group.add_option("--patchset",
                     type='int',
                     help="Update rietveld issue try job status")
    parser.add_option_group(group)

    group = optparse.OptionGroup(parser, "Try job options")
    group.add_option(
        "-b",
        "--bot",
        action="append",
        help="Only use specifics build slaves, ex: '--bot win' to "
        "run the try job only on the 'win' slave; see the try "
        "server waterfall for the slave's name")
    group.add_option("-r",
                     "--revision",
                     help="Revision to use for the try job; default: the "
                     "revision will be determined by the try server; see "
                     "its waterfall for more info")
    group.add_option("-c",
                     "--clobber",
                     action="store_true",
                     help="Force a clobber before building; e.g. don't do an "
                     "incremental build")
    # TODO(maruel): help="Select a specific configuration, usually 'debug' or "
    #                    "'release'"
    group.add_option("--target", help=optparse.SUPPRESS_HELP)

    # TODO(bradnelson): help="Override which project to use"
    group.add_option("--project",
                     help=optparse.SUPPRESS_HELP,
                     default=default_settings['default_project'])

    # Override the list of tests to run, use multiple times to list many tests
    # (or comma separated)
    group.add_option("-t",
                     "--tests",
                     action="append",
                     help=optparse.SUPPRESS_HELP)
    parser.add_option_group(group)

    group = optparse.OptionGroup(parser, "Patch to run")
    group.add_option("-f",
                     "--file",
                     default=file_list,
                     dest="files",
                     metavar="FILE",
                     action="append",
                     help="Use many times to list the files to include in the "
                     "try, relative to the repository root")
    group.add_option("--diff", help="File containing the diff to try")
    group.add_option("--url", help="Url where to grab a patch")
    group.add_option("--root",
                     help="Root to use for the patch; base subdirectory for "
                     "patch created in a subdirectory",
                     default=default_settings["default_root"])
    group.add_option("--patchlevel",
                     type='int',
                     metavar="LEVEL",
                     help="Used as -pN parameter to patch",
                     default=default_settings["default_patchlevel"])
    parser.add_option_group(group)

    group = optparse.OptionGroup(parser, "Access the try server by HTTP")
    group.add_option("--use_http",
                     action="store_const",
                     const=_SendChangeHTTP,
                     dest="send_patch",
                     default=default_transport,
                     help="Use HTTP to talk to the try server [default]")
    group.add_option("--host",
                     default=default_settings['http_host'],
                     help="Host address")
    group.add_option("--port",
                     default=default_settings['http_port'],
                     help="HTTP port")
    group.add_option("--proxy", help="HTTP proxy")
    parser.add_option_group(group)

    group = optparse.OptionGroup(parser, "Access the try server with SVN")
    group.add_option("--use_svn",
                     action="store_const",
                     const=_SendChangeSVN,
                     dest="send_patch",
                     help="Use SVN to talk to the try server")
    group.add_option(
        "--svn_repo",
        metavar="SVN_URL",
        default=default_settings['svn_repo'],
        help="SVN url to use to write the changes in; --use_svn is "
        "implied when using --svn_repo")
    parser.add_option_group(group)

    options, args = parser.parse_args(argv)

    # Switch the default accordingly if there was no default send_patch.
    if not options.send_patch:
        if options.port and options.host:
            options.send_patch = _SendChangeHTTP
        elif options.svn_repo:
            options.send_patch = _SendChangeSVN
        else:
            parser.error('Please specify an access method.')

    if len(args) == 1 and args[0] == 'help':
        parser.print_help()
    if (not options.files and (not options.issue and options.patchset)
            and not options.diff and not options.url):
        # TODO(maruel): It should just try the modified files showing up in a
        # svn status.
        parser.error('Nothing to try, changelist is empty.')

    try:
        # Convert options.diff into the content of the diff.
        if options.url:
            options.diff = urllib.urlopen(options.url).read()
        elif options.diff:
            options.diff = gcl.ReadFile(options.diff)
        # Process the VCS in any case at least to retrieve the email address.
        try:
            options.scm = GuessVCS(options)
            options.scm.ProcessOptions()
        except NoTryServerAccess, e:
            # If we got the diff, we don't care.
            if not options.diff:
                # TODO(maruel): Raise what?
                raise

        # Get try slaves from PRESUBMIT.py files if not specified.
        if not options.bot:
            if options.url:
                parser.error('You need to specify which bots to use.')
            root_presubmit = gcl.GetCachedFile('PRESUBMIT.py', use_root=True)
            options.bot = presubmit_support.DoGetTrySlaves(
                options.scm.GetFileNames(), options.scm.GetLocalRoot(),
                root_presubmit, False, sys.stdout)

        if options.name is None:
            if options.issue:
                options.name = 'Issue %s' % options.issue
            else:
                options.name = 'Unnamed'
                print('Note: use --name NAME to change the try job name.')
        if not options.email:
            print(
                'Warning: TRYBOT_RESULTS_EMAIL_ADDRESS is not set. Try server '
                'results might\ngo to: %[email protected].\n' % options.user)
        else:
            print('Results will be emailed to: ' + options.email)

        # Send the patch.
        options.send_patch(options)
        print 'Patch \'%s\' sent to try server: %s' % (options.name, ', '.join(
            options.bot))