Changeset 3826

Show
Ignore:
Timestamp:
06/12/08 00:06:57 (3 months ago)
Author:
pacopablo
Message:
  • 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
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sqlitetopgscript/0.10/sqlite2pg

    r3707 r3826  
    1 #!/usr/bin/python 
     1#!/usr/bin/env python 
    22 
    33# -*- coding: utf-8 -*- 
     
    6666    def migrateTable(self, table): 
    6767        """ Migrate the table specified. """ 
    68         if not opts.noclean: 
     68        if not self.opts.noclean: 
    6969            self.cleanTable(table) 
    7070        m = getattr(self, ''.join(['migrate_', table.upper()]), None) 
     
    130130        pgcur = self.pgdb.cursor() 
    131131        rows = row_exists = 0 
    132         if not opts.plist: 
     132        if not self.opts.plist: 
    133133            sql_select = "SELECT * FROM permission" 
    134134        else: 
     
    164164        pgcur = self.pgdb.cursor() 
    165165        rows = row_exists = 0 
    166         if not opts.wlist: 
     166        if not self.opts.wlist: 
    167167            sql_select = "SELECT * FROM wiki" 
    168168        else: 
     
    256256    return rc 
    257257 
    258 def doArgs(): 
     258def doArgs(argv): 
    259259    """ Look if you can't guess what this function does, just give up now. """ 
    260260    global VERSION 
     
    291291                        default=False) 
    292292    
    293     (options, args) = parser.parse_args(
     293    (options, args) = parser.parse_args(argv
    294294    if not options.tracenv: 
    295295        if  not options.tracbase: 
     
    303303            options.tracenv = os.path.join(options.tracbase, args[0]) 
    304304 
    305     if not options.pg_uri.startswith('postgres://'): 
     305    if not options.pg_uri or not options.pg_uri.startswith('postgres://'): 
    306306        print ("You must specify a valid URI for the PostgreSQL database.") 
    307307        print ("  eg. postgres://user:password@localhost/dbname") 
    308308        sys.exit(1) 
    309309  
    310     if not options.sqlite_uri.startswith('sqlite:'): 
     310    if not options.sqlite_uri or not options.sqlite_uri.startswith('sqlite:'): 
    311311        print ("You must specify a valid URI for the SQLite database.") 
    312312        print ("  eg. sqlite:db/trac.db") 
     
    327327 
    328328 
     329def main(argv): 
     330    opts = doArgs(argv) 
     331    Main(opts) 
     332    return 0 
     333 
    329334if __name__ == '__main__': 
    330     opts = doArgs() 
    331     Main(opts) 
    332     sys.exit(0) 
     335    sys.exit(main(sys.argv[1:])) 
    333336