diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ead1d15..dc160e2 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -14,9 +14,7 @@ permissions: jobs: build: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 - name: Set up Python 3.10 @@ -26,7 +24,7 @@ jobs: cache: 'pip' - name: Install dependencies run: | - sudo apt update > /dev/null + sudo apt -qq update sudo apt-get -q update sudo apt-get -q -y install tmux vim libncurses5 python -m pip -q install -U pip virtualenv flake8 pytest build @@ -40,9 +38,6 @@ jobs: python -m pip -q install -U pip virtualenv if [ -f requirements.txt ]; then pip -q install -r requirements.txt; fi - name: Unzip sample db - run: | - src/fb_export.py -h - - name: Export test json data run: | src/fb_export.py -d test/employee.fdb -e -o test/json - name: Run tests with pytest @@ -51,10 +46,10 @@ jobs: - name: Build dist run: | python -m build - - name: Test dist - run: | - pip install dist/fb_export-0.2.0-py3-none-any.whl - fb_export test/employee.fdb +# - name: Test dist +# run: | +# pip install dist/fb_export-0.2.0-py3-none-any.whl +# fb_export test/employee.fdb - name: Setup lhotari ssh session on disaster if: ${{ failure() }} uses: lhotari/action-upterm@v1 diff --git a/.vscode/launch.json b/.vscode/launch.json index e7afb64..d5d3d7f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "console": "integratedTerminal", "justMyCode": true, "args": [ "test/employee.fdb", // "-e", // "-c", // "-l", //"-m 10", // "-u", "SYSDBA", "-p", "masterkey", - // "-o" , "OutDir", // "-F", "json" + "-o" , "OutDir", // "-F", "json" ] , },], //other launch setting diff --git a/README.md b/README.md index 736959c..76f457a 100644 --- a/README.md +++ b/README.md @@ -22,35 +22,50 @@ fb_export -d test/employee.fdb ### Run: - 1. View database table and field names and datatypes, from Firebird database alias + View database table and field names and datatypes, from Firebird database file ``` - ./fb_export -d employee + ./fb_export -d test/employee.fdb ``` -2. View brief info + + View database table and field names and datatypes, from database alias name, + assumes there is a Firebird installation on the local machine with example data. + + ``` + ./fb_export -d employee + ``` + + View brief information, table and field only, no data types ``` -./fb_export -d employee -b +./fb_export -d test/employee.fdb -b ``` -3. Export everything from database file to directory "Export" as CSV + Export from database file to directory "Export" as CSV in separate files, one per table ``` ./fb_export -d test/employee.fdb -e -o Export ``` -4. Export only files and tables listed in src/limit_sql.py to a maximum of 100 records + Test export of only the tables and fields listed in src/limit_sql.py, to a maximum of 100 records ``` ./fb_export -d test/employee.fdb -l -m 100 ``` -5. Also view a number (5) of sample records -from the employee database (without exporting) + Test export, and also view a number (5) of sample records +from the employee database (without saving) ``` ./fb_export -d test/employee.fdb -s -n 5 ``` -To recreate the test JSON file +Create a combined JSON export file ``` ./fb_export -d test/employee.fdb -F json -e -o test/json -c ``` +Capture the database summary info to file (bash) +``` +./fb_export -d test/employee.fdb -b &> tmp/fdb_info.txt +./fb_export -d test/employee.fdb &> tmp/fdb_more_info.txt +``` + + ## Usage -```src/fb_export.py -h +```src/fb_export.py -h (or ./fb_export ) usage: fb_export.py [-h] [--version] [-e] [-b] [-l] [-m MAXROWS] [-s] [-n NUMSAMPLES] [-c] [-F {csv,json}] [-o OUTDIR] [-u USER] [-p PASSWORD] -d PATH_TO_DB Firebird export @@ -81,11 +96,28 @@ options: ``` ### Build a distribution tar.gz: + +``` pip install build build -m +``` + +## Note: Firebird 2.5 and 3+ versions + +This has been written with a with Firebird 2.5 testing with database file. +However, I have also verified that the python code works with a Firebird 3, +installation. FB3 and FB2.5 has incompatible on-disk file structures for the +databases. Using the fdb python library, one could load a 2.5 or 3.0 database, by +pointing to the appropriate 2.5 or 3.0 fbclient.so library file. In this +way one could enable loading both the 2.5 and the 3.0 and up versions of +Firebird databases in the same python code for comparison and/or transfer. ### Test: - pytest - + `pytest` + +## Using Github Actions + +Firebird-export has been tested with Github Actions, +see `.github/workflows.python-app.yml` in the repo. [^1]: Firebird is a trademark of https://firebirdsql.org/ and is used under the 'fair use' case, https://firebirdsql.org/en/firebird-brand-faq diff --git a/src/args.py b/src/args.py index 2617c65..866b96d 100644 --- a/src/args.py +++ b/src/args.py @@ -33,6 +33,6 @@ def get_args(*fbe_args): if len(fbe_args) == 0: # Command line args = parser.parse_args() else: # From module - args = parser.parse_args( fbe_args[0]) + args = parser.parse_args( fbe_args) return args diff --git a/src/fb_export.py b/src/fb_export.py index abca130..7e38bb3 100755 --- a/src/fb_export.py +++ b/src/fb_export.py @@ -13,7 +13,6 @@ from args import get_args -#import .args from dftools import fix_fields from utils import mkdirs @@ -27,7 +26,7 @@ def main(*fbe_arg): - args = get_args(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') @@ -145,5 +144,5 @@ def main(*fbe_arg): rmtree('/tmp/firebird') if __name__ == '__main__': - sys.argv.pop(0) - main( ''.join(sys.argv)) + main() +