Skip to content

Commit

Permalink
merge back changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
inus committed May 16, 2024
2 parents 775c6fa + 5a34ce3 commit f2b2d5c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 28 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 44 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 3 additions & 4 deletions src/fb_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


from args import get_args
#import .args
from dftools import fix_fields
from utils import mkdirs

Expand All @@ -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')
Expand Down Expand Up @@ -145,5 +144,5 @@ def main(*fbe_arg):
rmtree('/tmp/firebird')

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

0 comments on commit f2b2d5c

Please sign in to comment.