Ticket #3138 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

Check db arguments given before checking contents

Reported by: anonymous Assigned to: pacopablo
Priority: normal Component: SqliteToPgScript
Severity: minor Keywords:
Cc: Trac Release: 0.10

Description

If you don't specify a postgres uri, then the program will fail with:

Traceback (most recent call last):
  File "./sqlite2pg", line 330, in ?
    opts = doArgs()
  File "./sqlite2pg", line 305, in doArgs
    if not options.pg_uri.startswith('postgres://'):
AttributeError: 'NoneType' object has no attribute 'startswith'

The fix is to check for none before calling startswith. Patch is

Index: sqlite2pg
===================================================================
--- sqlite2pg   (revision 3795)
+++ sqlite2pg   (working copy)
@@ -302,12 +302,12 @@
             options.project = args[0]
             options.tracenv = os.path.join(options.tracbase, args[0])
 
-    if not options.pg_uri.startswith('postgres://'):
+    if not options.pg_uri or not options.pg_uri.startswith('postgres://'):
         print ("You must specify a valid URI for the PostgreSQL database.")
         print ("  eg. postgres://user:password@localhost/dbname")
         sys.exit(1)
  
-    if not options.sqlite_uri.startswith('sqlite:'):
+    if not options.sqlite_uri or not options.sqlite_uri.startswith('sqlite:'):
         print ("You must specify a valid URI for the SQLite database.")
         print ("  eg. sqlite:db/trac.db")
         sys.exit(1)

Attachments

Change History

06/12/08 07:06:58 changed by pacopablo

  • status changed from new to closed.
  • resolution set to fixed.

(In [3826])

  • Accepted patch to create a main() function that is easily callable from other python modules. Thanks to alberto Closes #3148
  • Accepted patch to check for presence of arguments before checking value. Closes #3138

Add/Change #3138 (Check db arguments given before checking contents)




Change Properties
Action