Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

improved exception handling

  • Loading branch information...
commit f320527ff799d54c522855aa1ce08967ae61a487 1 parent 0dfe585
Tom Schutter authored April 10, 2012

Showing 1 changed file with 53 additions and 39 deletions. Show diff stats Hide diff stats

  1. 92  bztotj.py
92  bztotj.py
@@ -40,7 +40,7 @@
40 40
 except Exception:
41 41
     print("Unable to import pyodbc", file=sys.stderr)
42 42
     print("On Debian: sudo apt-get install python-pyodbc", file=sys.stderr)
43  
-    print("Or install from code.google.com/p/pyodbc/", file=sys.stderr)
  43
+    print("Or install from http://code.google.com/p/pyodbc/", file=sys.stderr)
44 44
     sys.exit(1)
45 45
 
46 46
 # Configuration variables
@@ -392,7 +392,7 @@ def build_open_bug_task_list(options, connection, milestone):
392 392
             dependson = row[0]
393 393
 
394 394
             if (task.is_meta):
395  
-                #print "META: %i<-%s" % (task.bug_id, str(dependson))
  395
+                #print("META: %i<-%s" % (task.bug_id, str(dependson)))
396 396
                 for blocked_task in task_list:
397 397
                     if blocked_task.bug_id == dependson:
398 398
                         task.task_list.append(blocked_task)
@@ -412,6 +412,26 @@ def write_task_list(options, task_list, filename):
412 412
             task.write(options, outfile, task_list, 0)
413 413
 
414 414
 
  415
+def export(options, milestones, connection):
  416
+    """Read from the Bugzilla database and export to the .tji file."""
  417
+    for milestone in milestones:
  418
+        # Build a task list of resolved bugs from the Bugzilla database
  419
+        task_list = build_resolved_bug_task_list(
  420
+            options,
  421
+            connection,
  422
+            milestone
  423
+        )
  424
+
  425
+        # Write the task list to the output file
  426
+        write_task_list(options, task_list, milestone + "_resolved_tasks.tji")
  427
+
  428
+        # Build a task list of open bugs from the Bugzilla database
  429
+        task_list = build_open_bug_task_list(options, connection, milestone)
  430
+
  431
+        # Write the task list to the output file
  432
+        write_task_list(options, task_list, milestone + "_open_tasks.tji")
  433
+
  434
+
415 435
 def main():
416 436
     """main"""
417 437
     option_parser = optparse.OptionParser(
@@ -449,15 +469,15 @@ def main():
449 469
         action="store",
450 470
         dest="db_driver",
451 471
         metavar="DRIVER",
452  
-        default="MySQL",
453  
-        help="Bugzilla database software (default=%default)"
  472
+        default="MySQL ODBC 5.1.6 Driver",
  473
+        help="Bugzilla database driver (default=%default)"
454 474
     )
455 475
     option_parser.add_option(
456 476
         "--db-host",
457 477
         action="store",
458 478
         dest="db_host",
459 479
         metavar="HOST",
460  
-        default="bugzilla.monticello.com",
  480
+        default="localhost",
461 481
         help="Bugzilla database hostname (default=%default)"
462 482
     )
463 483
     option_parser.add_option(
@@ -474,7 +494,7 @@ def main():
474 494
         action="store",
475 495
         dest="db_name",
476 496
         metavar="NAME",
477  
-        default="bugzilla",
  497
+        default="bugzilla3",
478 498
         help="Bugzilla database name (default=%default)"
479 499
     )
480 500
     option_parser.add_option(
@@ -482,7 +502,7 @@ def main():
482 502
         action="store",
483 503
         dest="db_user",
484 504
         metavar="NAME",
485  
-        default="bugzilla",
  505
+        default="bugzilla3",
486 506
         help="Bugzilla database user (default=%default)"
487 507
     )
488 508
     option_parser.add_option(
@@ -490,7 +510,7 @@ def main():
490 510
         action="store",
491 511
         dest="db_pass",
492 512
         metavar="PASSWORD",
493  
-        default="tjefferson",
  513
+        default=None,
494 514
         help="Bugzilla database password (default=%default)"
495 515
     )
496 516
     option_parser.add_option(
@@ -507,41 +527,35 @@ def main():
507 527
     if len(args) < 1:
508 528
         option_parser.error("No milestone specified.")
509 529
 
510  
-    # Write the flags data file
511  
-    write_flags_file()
512  
-
513  
-    # Write the project data file
514  
-    write_project_data()
515  
-
516 530
     # Connect to the Bugzilla database
517  
-    connection = pyodbc.connect(
518  
-        driver="{%s}" % options.db_driver,
519  
-        server=options.db_host,
520  
-        port=options.db_port,
521  
-        uid=options.db_user,
522  
-        pwd=options.db_pass,
523  
-        database=options.db_name
524  
-    )
525  
-
526  
-    for milestone in args:
527  
-        # Build a task list of resolved bugs from the Bugzilla database
528  
-        task_list = build_resolved_bug_task_list(
529  
-            options,
530  
-            connection,
531  
-            milestone
  531
+    try:
  532
+        connection = pyodbc.connect(
  533
+            driver="{%s}" % options.db_driver,
  534
+            server=options.db_host,
  535
+            port=options.db_port,
  536
+            uid=options.db_user,
  537
+            pwd=options.db_pass,
  538
+            database=options.db_name
532 539
         )
  540
+    except Exception as (exc):
  541
+        print(exc)
  542
+        print("driver={%s}" % options.db_driver)
  543
+        return 1
  544
+
  545
+    try:
  546
+        # Export from the database.
  547
+        export(options, args)
  548
+    finally:
  549
+        # Close the connection to the Bugzilla database
  550
+        connection.close()
  551
+
  552
+    # Write the flags data file.
  553
+    write_flags_file()
533 554
 
534  
-        # Write the task list to the output file
535  
-        write_task_list(options, task_list, milestone + "_resolved_tasks.tji")
536  
-
537  
-        # Build a task list of open bugs from the Bugzilla database
538  
-        task_list = build_open_bug_task_list(options, connection, milestone)
539  
-
540  
-        # Write the task list to the output file
541  
-        write_task_list(options, task_list, milestone + "_open_tasks.tji")
  555
+    # Write the project data file.
  556
+    write_project_data()
542 557
 
543  
-    # Close the connection to the Bugzilla database
544  
-    connection.close()
  558
+    return 0
545 559
 
546 560
 
547 561
 if __name__ == "__main__":

0 notes on commit f320527

Please sign in to comment.
Something went wrong with that request. Please try again.