parameters: (argv, data=None)
return_statement: return issue, patchset
docstring: The real main function.
  
    Args:
      argv: Command line arguments.
      data: Diff contents. If None (default) the diff is generated by
        the VersionControlSystem implementation returned by GuessVCS().
  
    Returns:
      A 2-tuple (issue id, patchset id).
      The patchset id is None if the base files are not uploaded by this
      script (applies only to SVN checkouts).
docstring_summary: The real main function.
docstring_tokens: The real main function .
function: def RealMain(argv, data=None):
    """The real main function.
  
    Args:
      argv: Command line arguments.
      data: Diff contents. If None (default) the diff is generated by
        the VersionControlSystem implementation returned by GuessVCS().
  
    Returns:
      A 2-tuple (issue id, patchset id).
      The patchset id is None if the base files are not uploaded by this
      script (applies only to SVN checkouts).
    """
    options, args = parser.parse_args(argv[1:])
    if options.help:
      if options.verbose < 2:
        # hide Perforce options
        parser.epilog = "Use '--help -v' to show additional Perforce options."
        parser.option_groups.remove(parser.get_option_group('--p4_port'))
      parser.print_help()
      sys.exit(0)
  
    global verbosity
    verbosity = options.verbose
    if verbosity >= 3:
      logging.getLogger().setLevel(logging.DEBUG)
    elif verbosity >= 2:
      logging.getLogger().setLevel(logging.INFO)
  
    vcs = GuessVCS(options)
  
    base = options.base_url
    if isinstance(vcs, SubversionVCS):
      # Guessing the base field is only supported for Subversion.
      # Note: Fetching base files may become deprecated in future releases.
      guessed_base = vcs.GuessBase(options.download_base)
      if base:
        if guessed_base and base != guessed_base:
          print "Using base URL \"%s\" from --base_url instead of \"%s\"" % \
              (base, guessed_base)
      else:
        base = guessed_base
  
    if not base and options.download_base:
      options.download_base = True
      logging.info("Enabled upload of base file")
    if not options.assume_yes:
      vcs.CheckForUnknownFiles()
    if data is None:
      data = vcs.GenerateDiff(args)
    data = vcs.PostProcessDiff(data)
    if options.print_diffs:
      print "Rietveld diff start:*****"
      print data
      print "Rietveld diff end:*****"
    files = vcs.GetBaseFiles(data)
    if verbosity >= 1:
      print "Upload server:", options.server, "(change with -s/--server)"
    rpc_server = GetRpcServer(options.server,
                              options.email,
                              options.host,
                              options.save_cookies,
                              options.account_type)
    form_fields = []
  
    repo_guid = vcs.GetGUID()
    if repo_guid:
      form_fields.append(("repo_guid", repo_guid))
    if base:
      b = urlparse.urlparse(base)
      username, netloc = urllib.splituser(b.netloc)
      if username:
        logging.info("Removed username from base URL")
        base = urlparse.urlunparse((b.scheme, netloc, b.path, b.params,
                                    b.query, b.fragment))
      form_fields.append(("base", base))
    if options.issue:
      form_fields.append(("issue", str(options.issue)))
    if options.email:
      form_fields.append(("user", options.email))
    if options.reviewers:
      for reviewer in options.reviewers.split(','):
        CheckReviewer(reviewer)
      form_fields.append(("reviewers", options.reviewers))
    if options.cc:
      for cc in options.cc.split(','):
        CheckReviewer(cc)
      form_fields.append(("cc", options.cc))
  
    # Process --message, --title and --file.
    message = options.message or ""
    title = options.title or ""
    if options.file:
      if options.message:
        ErrorExit("Can't specify both message and message file options")
      file = open(options.file, 'r')
      message = file.read()
      file.close()
    if options.issue:
      prompt = "Title describing this patch set: "
    else:
      prompt = "New issue subject: "
    title = (
        title or message.split('\n', 1)[0].strip() or raw_input(prompt).strip())
    if not title and not options.issue:
      ErrorExit("A non-empty title is required for a new issue")
    # For existing issues, it's fine to give a patchset an empty name. Rietveld
    # doesn't accept that so use a whitespace.
    title = title or " "
    if len(title) > 100:
      title = title[:99] + '…'
    if title and not options.issue:
      message = message or title
  
    form_fields.append(("subject", title))
    # If it's a new issue send message as description. Otherwise a new
    # message is created below on upload_complete.
    if message and not options.issue:
      form_fields.append(("description", message))
  
    # Send a hash of all the base file so the server can determine if a copy
    # already exists in an earlier patchset.
    base_hashes = ""
    for file, info in files.iteritems():
      if not info[0] is None:
        checksum = md5(info[0]).hexdigest()
        if base_hashes:
          base_hashes += "|"
        base_hashes += checksum + ":" + file
    form_fields.append(("base_hashes", base_hashes))
    if options.private:
      if options.issue:
        print "Warning: Private flag ignored when updating an existing issue."
      else:
        form_fields.append(("private", "1"))
    if options.send_patch:
      options.send_mail = True
    if not options.download_base:
      form_fields.append(("content_upload", "1"))
    if len(data) > MAX_UPLOAD_SIZE:
      print "Patch is large, so uploading file patches separately."
      uploaded_diff_file = []
      form_fields.append(("separate_patches", "1"))
    else:
      uploaded_diff_file = [("data", "data.diff", data)]
    ctype, body = EncodeMultipartFormData(form_fields, uploaded_diff_file)
    response_body = rpc_server.Send("/upload", body, content_type=ctype)
    patchset = None
    if not options.download_base or not uploaded_diff_file:
      lines = response_body.splitlines()
      if len(lines) >= 2:
        msg = lines[0]
        patchset = lines[1].strip()
        patches = [x.split(" ", 1) for x in lines[2:]]
      else:
        msg = response_body
    else:
      msg = response_body
    StatusUpdate(msg)
    if not response_body.startswith("Issue created.") and \
    not response_body.startswith("Issue updated."):
      sys.exit(0)
    issue = msg[msg.rfind("/")+1:]
  
    if not uploaded_diff_file:
      result = UploadSeparatePatches(issue, rpc_server, patchset, data, options)
      if not options.download_base:
        patches = result
  
    if not options.download_base:
      vcs.UploadBaseFiles(issue, rpc_server, patches, patchset, options, files)
  
    payload = {}  # payload for final request
    if options.send_mail:
      payload["send_mail"] = "yes"
      if options.send_patch:
        payload["attach_patch"] = "yes"
    if options.issue and message:
      payload["message"] = message
    payload = urllib.urlencode(payload)
    rpc_server.Send("/" + issue + "/upload_complete/" + (patchset or ""),
                    payload=payload)
    return issue, patchset
function_tokens: def RealMain ( argv , data = None ) : options , args = parser . parse_args ( argv [ 1 : ] ) if options . help : if options . verbose < 2 : # hide Perforce options parser . epilog = "Use '--help -v' to show additional Perforce options." parser . option_groups . remove ( parser . get_option_group ( '--p4_port' ) ) parser . print_help ( ) sys . exit ( 0 ) global verbosity verbosity = options . verbose if verbosity >= 3 : logging . getLogger ( ) . setLevel ( logging . DEBUG ) elif verbosity >= 2 : logging . getLogger ( ) . setLevel ( logging . INFO ) vcs = GuessVCS ( options ) base = options . base_url if isinstance ( vcs , SubversionVCS ) : # Guessing the base field is only supported for Subversion. # Note: Fetching base files may become deprecated in future releases. guessed_base = vcs . GuessBase ( options . download_base ) if base : if guessed_base and base != guessed_base : print "Using base URL \"%s\" from --base_url instead of \"%s\"" % ( base , guessed_base ) else : base = guessed_base if not base and options . download_base : options . download_base = True logging . info ( "Enabled upload of base file" ) if not options . assume_yes : vcs . CheckForUnknownFiles ( ) if data is None : data = vcs . GenerateDiff ( args ) data = vcs . PostProcessDiff ( data ) if options . print_diffs : print "Rietveld diff start:*****" print data print "Rietveld diff end:*****" files = vcs . GetBaseFiles ( data ) if verbosity >= 1 : print "Upload server:" , options . server , "(change with -s/--server)" rpc_server = GetRpcServer ( options . server , options . email , options . host , options . save_cookies , options . account_type ) form_fields = [ ] repo_guid = vcs . GetGUID ( ) if repo_guid : form_fields . append ( ( "repo_guid" , repo_guid ) ) if base : b = urlparse . urlparse ( base ) username , netloc = urllib . splituser ( b . netloc ) if username : logging . info ( "Removed username from base URL" ) base = urlparse . urlunparse ( ( b . scheme , netloc , b . path , b . params , b . query , b . fragment ) ) form_fields . append ( ( "base" , base ) ) if options . issue : form_fields . append ( ( "issue" , str ( options . issue ) ) ) if options . email : form_fields . append ( ( "user" , options . email ) ) if options . reviewers : for reviewer in options . reviewers . split ( ',' ) : CheckReviewer ( reviewer ) form_fields . append ( ( "reviewers" , options . reviewers ) ) if options . cc : for cc in options . cc . split ( ',' ) : CheckReviewer ( cc ) form_fields . append ( ( "cc" , options . cc ) ) # Process --message, --title and --file. message = options . message or "" title = options . title or "" if options . file : if options . message : ErrorExit ( "Can't specify both message and message file options" ) file = open ( options . file , 'r' ) message = file . read ( ) file . close ( ) if options . issue : prompt = "Title describing this patch set: " else : prompt = "New issue subject: " title = ( title or message . split ( '\n' , 1 ) [ 0 ] . strip ( ) or raw_input ( prompt ) . strip ( ) ) if not title and not options . issue : ErrorExit ( "A non-empty title is required for a new issue" ) # For existing issues, it's fine to give a patchset an empty name. Rietveld # doesn't accept that so use a whitespace. title = title or " " if len ( title ) > 100 : title = title [ : 99 ] + '…' if title and not options . issue : message = message or title form_fields . append ( ( "subject" , title ) ) # If it's a new issue send message as description. Otherwise a new # message is created below on upload_complete. if message and not options . issue : form_fields . append ( ( "description" , message ) ) # Send a hash of all the base file so the server can determine if a copy # already exists in an earlier patchset. base_hashes = "" for file , info in files . iteritems ( ) : if not info [ 0 ] is None : checksum = md5 ( info [ 0 ] ) . hexdigest ( ) if base_hashes : base_hashes += "|" base_hashes += checksum + ":" + file form_fields . append ( ( "base_hashes" , base_hashes ) ) if options . private : if options . issue : print "Warning: Private flag ignored when updating an existing issue." else : form_fields . append ( ( "private" , "1" ) ) if options . send_patch : options . send_mail = True if not options . download_base : form_fields . append ( ( "content_upload" , "1" ) ) if len ( data ) > MAX_UPLOAD_SIZE : print "Patch is large, so uploading file patches separately." uploaded_diff_file = [ ] form_fields . append ( ( "separate_patches" , "1" ) ) else : uploaded_diff_file = [ ( "data" , "data.diff" , data ) ] ctype , body = EncodeMultipartFormData ( form_fields , uploaded_diff_file ) response_body = rpc_server . Send ( "/upload" , body , content_type = ctype ) patchset = None if not options . download_base or not uploaded_diff_file : lines = response_body . splitlines ( ) if len ( lines ) >= 2 : msg = lines [ 0 ] patchset = lines [ 1 ] . strip ( ) patches = [ x . split ( " " , 1 ) for x in lines [ 2 : ] ] else : msg = response_body else : msg = response_body StatusUpdate ( msg ) if not response_body . startswith ( "Issue created." ) and not response_body . startswith ( "Issue updated." ) : sys . exit ( 0 ) issue = msg [ msg . rfind ( "/" ) + 1 : ] if not uploaded_diff_file : result = UploadSeparatePatches ( issue , rpc_server , patchset , data , options ) if not options . download_base : patches = result if not options . download_base : vcs . UploadBaseFiles ( issue , rpc_server , patches , patchset , options , files ) payload = { } # payload for final request if options . send_mail : payload [ "send_mail" ] = "yes" if options . send_patch : payload [ "attach_patch" ] = "yes" if options . issue and message : payload [ "message" ] = message payload = urllib . urlencode ( payload ) rpc_server . Send ( "/" + issue + "/upload_complete/" + ( patchset or "" ) , payload = payload ) return issue , patchset