Skip to content

Commit

Permalink
Resolve arg passing if module call
Browse files Browse the repository at this point in the history
  • Loading branch information
inus committed May 16, 2024
1 parent fa2d6fe commit 192ffac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"program": "src/fb_export.py", //"${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": [ //"test/employee.fdb", // "-e", // "-c", // "-l", //"-m 10", // "-u", "SYSDBA", "-p", "masterkey",
"args": [ "test/employee.fdb", // "-e", // "-c", // "-l", //"-m 10", // "-u", "SYSDBA", "-p", "masterkey",
// "-o" , "OutDir", // "-F", "json"
] ,
},],
Expand Down
17 changes: 9 additions & 8 deletions src/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import argparse


def get_args(*args):
if len(args) != 0:
return args
def get_args(*fbe_args):

parser = argparse.ArgumentParser(description="Firebird export")

parser.add_argument( 'path_to_db', type=str,
Expand All @@ -18,20 +17,22 @@ def get_args(*args):
parser.add_argument('-l', '--limit', action='store_true', default=False,
help="Limit tables and fields to those in limit_sql.py")
parser.add_argument('-m', '--maxrows', help="Max number of rows to export")

#fixme - numsamples to be conditional on sampledata
parser.add_argument('-s', '--sampledata', action='store_true', default=False,
help="Also show sample data records")
parser.add_argument('-n', '--numsamples', default=3, help="number of sample rows")

parser.add_argument('-c', '--combine', action='store_true', default=False,
help="Combine output into a single file")
parser.add_argument('-j', '--join', action='store_true', default=False,
help="Join output files")
format = [ 'csv', 'json',] # 'excel', 'sql', 'hdf', 'pickle', 'html' ....]?
parser.add_argument("-F", "--format", choices=format, default='csv', help="Export output format, default .CSV")
parser.add_argument("-o", "--outdir", type=str, dest='outdir', default='Export', help="Output directory")
parser.add_argument("-u", "--user", type=str, default='SYSDBA', help="Firebird DB username")
parser.add_argument("-p", "--password", type=str, default='masterkey', help="Firebird DB password")


args = parser.parse_args()
if len(fbe_args) == 0: # Command line
args = parser.parse_args()
else: # From module
args = parser.parse_args( fbe_args[0])

return args
14 changes: 6 additions & 8 deletions src/fb_export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
# Dump firebase data


# Export Firebird database contents to CSV

import fdb
from shutil import rmtree
Expand All @@ -28,13 +26,13 @@
unzip_testdb()


def main(*arg):
args = get_args()
def main(*fbe_arg):
args = get_args(fbe_arg)
if os.getenv('GITHUB_ACTIONS'):
con = fdb.connect(args.path_to_db, user=args.user, password=args.password,
fb_library_name='/opt/firebird/lib/libfbembed.so')
else:
con = fdb.connect(args.path_to_db, user=args.user, password=args.password)
con = fdb.connect(args.path_to_db)

print("Connected to ", con.database_name, ' via ', con.firebird_version, file=sys.stderr)

Expand Down Expand Up @@ -129,7 +127,7 @@ def main(*arg):
except:
print("Error converting DF to json: " + table, file=sys.stderr)

if args.combine:
if args.join:
filename = dbf_name.rstrip('.fdb') + '.' + args.format
fmode = 'a'
else:
Expand All @@ -147,4 +145,4 @@ def main(*arg):
rmtree('/tmp/firebird')

if __name__ == '__main__':
main(sys.argv)
main()

0 comments on commit 192ffac

Please sign in to comment.