Modify

Opened 6 years ago

Closed 6 years ago

#3138 closed defect (fixed)

Check db arguments given before checking contents

Reported by: anonymous Owned by: 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 (0)

Change History (1)

comment:1 Changed 6 years ago by pacopablo

  • Resolution set to fixed
  • Status changed from new to closed

(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 Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from pacopablo. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.