1266 """The real main function.
1267
1268 Args:
1269 argv: Command line arguments.
1270 data: Diff contents. If None (default) the diff is generated by
1271 the VersionControlSystem implementation returned by
GuessVCS().
1272
1273 Returns:
1274 A 2-tuple (issue id, patchset id).
1275 The patchset id is None if the base files are not uploaded by this
1276 script (applies only to SVN checkouts).
1277 """
1278 logging.basicConfig(format=("%(asctime).19s %(levelname)s %(filename)s:"
1279 "%(lineno)s %(message)s "))
1280 os.environ['LC_ALL'] = 'C'
1281 options, args = parser.parse_args(argv[1:])
1282 global verbosity
1283 verbosity = options.verbose
1284 if verbosity >= 3:
1285 logging.getLogger().setLevel(logging.DEBUG)
1286 elif verbosity >= 2:
1287 logging.getLogger().setLevel(logging.INFO)
1289 if isinstance(vcs, SubversionVCS):
1290
1291
1292 base = vcs.GuessBase(options.download_base)
1293 else:
1294 base = None
1295 if not base and options.download_base:
1296 options.download_base = True
1297 logging.info("Enabled upload of base file")
1298 if not options.assume_yes:
1299 vcs.CheckForUnknownFiles()
1300 if data is None:
1301 data = vcs.GenerateDiff(args)
1302 files = vcs.GetBaseFiles(data)
1303 if verbosity >= 1:
1304 print "Upload server:", options.server, "(change with -s/--server)"
1305 if options.issue:
1306 prompt = "Message describing this patch set: "
1307 else:
1308 prompt = "New issue subject: "
1309 message = options.message or raw_input(prompt).strip()
1310 if not message:
1311 ErrorExit(
"A non-empty message is required")
1313 form_fields = [("subject", message)]
1314 if base:
1315 form_fields.append(("base", base))
1316 if options.issue:
1317 form_fields.append(("issue", str(options.issue)))
1318 if options.email:
1319 form_fields.append(("user", options.email))
1320 if options.reviewers:
1321 for reviewer in options.reviewers.split(','):
1322 if "@" in reviewer
and not reviewer.split(
"@")[1].
count(
".") == 1:
1323 ErrorExit(
"Invalid email address: %s" % reviewer)
1324 form_fields.append(("reviewers", options.reviewers))
1325 if options.cc:
1326 for cc in options.cc.split(','):
1327 if "@" in cc
and not cc.split(
"@")[1].
count(
".") == 1:
1328 ErrorExit(
"Invalid email address: %s" % cc)
1329 form_fields.append(("cc", options.cc))
1330 description = options.description
1331 if options.description_file:
1332 if options.description:
1333 ErrorExit(
"Can't specify description and description_file")
1334 file = open(options.description_file, 'r')
1335 description = file.read()
1336 file.close()
1337 if description:
1338 form_fields.append(("description", description))
1339
1340
1341 base_hashes = ""
1342 for file, info in files.iteritems():
1343 if not info[0] is None:
1344 checksum = md5.new(info[0]).hexdigest()
1345 if base_hashes:
1346 base_hashes += "|"
1347 base_hashes += checksum + ":" + file
1348 form_fields.append(("base_hashes", base_hashes))
1349
1350
1351 if options.send_mail and options.download_base:
1352 form_fields.append(("send_mail", "1"))
1353 if not options.download_base:
1354 form_fields.append(("content_upload", "1"))
1355 if len(data) > MAX_UPLOAD_SIZE:
1356 print "Patch is large, so uploading file patches separately."
1357 uploaded_diff_file = []
1358 form_fields.append(("separate_patches", "1"))
1359 else:
1360 uploaded_diff_file = [("data", "data.diff", data)]
1362 response_body = rpc_server.Send("/upload", body, content_type=ctype)
1363 patchset = None
1364 if not options.download_base or not uploaded_diff_file:
1365 lines = response_body.splitlines()
1366 if len(lines) >= 2:
1367 msg = lines[0]
1368 patchset = lines[1].strip()
1369 patches = [x.split(" ", 1) for x in lines[2:]]
1370 else:
1371 msg = response_body
1372 else:
1373 msg = response_body
1375 if not response_body.startswith("Issue created.") and \
1376 not response_body.startswith("Issue updated."):
1377 sys.exit(0)
1378 issue = msg[msg.rfind("/")+1:]
1379
1380 if not uploaded_diff_file:
1382 if not options.download_base:
1383 patches = result
1384
1385 if not options.download_base:
1386 vcs.UploadBaseFiles(issue, rpc_server, patches, patchset, options, files)
1387 if options.send_mail:
1388 rpc_server.Send("/" + issue + "/mail", payload="")
1389 return issue, patchset
1390
1391
def UploadSeparatePatches(issue, rpc_server, patchset, data, options)