From e3d9073d02661cb62705ff27ebe5cd1ed331344a Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sun, 10 Mar 2019 09:21:57 +0100 Subject: [PATCH 1/5] Changed res2sqlite to have a main() function --- scripts/res2sqlite.py | 74 ++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/scripts/res2sqlite.py b/scripts/res2sqlite.py index c42c16a..0234a7b 100755 --- a/scripts/res2sqlite.py +++ b/scripts/res2sqlite.py @@ -350,7 +350,7 @@ CREATE VIEW IF NOT EXISTS Capacity_View """ -def mdb_get_data_text(filename, table): +def mdb_get_data_text(s3db, filename, table): print("Reading %s..." % table) try: mdb_sql = sp.Popen(['mdb-export', '-I', 'postgres', filename, table], @@ -373,7 +373,7 @@ def mdb_get_data_text(filename, table): mdb_sql.terminate() -def mdb_get_data_numeric(filename, table): +def mdb_get_data_numeric(s3db, filename, table): print("Reading %s..." % table) try: mdb_sql = sp.Popen(['mdb-export', filename, table], @@ -392,45 +392,55 @@ def mdb_get_data_numeric(filename, table): mdb_sql.terminate() -def mdb_get_data(filename, table): +def mdb_get_data(s3db, filename, table): if table in mdb_tables_text: - mdb_get_data_text(filename, table) + mdb_get_data_text(s3db, filename, table) elif table in mdb_tables_numeric: - mdb_get_data_numeric(filename, table) + mdb_get_data_numeric(s3db, filename, table) else: raise ValueError("'%s' is in neither mdb_tables_text nor mdb_tables_numeric" % table) -## Main part of the script +def convert_arbin_to_sqlite(input_file, output_file): + """Read data from an Arbin .res data file and write to a sqlite file. -parser = argparse.ArgumentParser(description="Convert Arbin .res files to sqlite3 databases using mdb-export") -parser.add_argument('input_file', type=str) # need file name to pass to sp.Popen -parser.add_argument('output_file', type=str) # need file name to pass to sqlite3.connect - -args = parser.parse_args() - -s3db = sqlite3.connect(args.output_file) - - -for table in reversed(mdb_tables + mdb_5_23_tables): - s3db.execute('DROP TABLE IF EXISTS "%s";' % table) - -for table in mdb_tables: - s3db.executescript(mdb_create_scripts[table]) - mdb_get_data(args.input_file, table) - if table in mdb_create_indices: - print("Creating indices for %s..." % table) - s3db.executescript(mdb_create_indices[table]) - -if (s3db.execute("SELECT Version_Schema_Field FROM Version_Table;").fetchone()[0] == "Results File 5.23"): - for table in mdb_5_23_tables: + Any data currently in the sqlite file will be erased! + """ + s3db = sqlite3.connect(output_file) + + + for table in reversed(mdb_tables + mdb_5_23_tables): + s3db.execute('DROP TABLE IF EXISTS "%s";' % table) + + for table in mdb_tables: s3db.executescript(mdb_create_scripts[table]) - mdb_get_data(args.input_file, table) + mdb_get_data(s3db, input_file, table) if table in mdb_create_indices: + print("Creating indices for %s..." % table) s3db.executescript(mdb_create_indices[table]) + + if (s3db.execute("SELECT Version_Schema_Field FROM Version_Table;").fetchone()[0] == "Results File 5.23"): + for table in mdb_5_23_tables: + s3db.executescript(mdb_create_scripts[table]) + mdb_get_data(input_file, table) + if table in mdb_create_indices: + s3db.executescript(mdb_create_indices[table]) + + print("Creating helper table for capacity and energy totals...") + s3db.executescript(helper_table_script) + + print("Vacuuming database...") + s3db.executescript("VACUUM; ANALYZE;") -print("Creating helper table for capacity and energy totals...") -s3db.executescript(helper_table_script) -print("Vacuuming database...") -s3db.executescript("VACUUM; ANALYZE;") +def main(argv=None): + parser = argparse.ArgumentParser(description="Convert Arbin .res files to sqlite3 databases using mdb-export") + parser.add_argument('input_file', type=str) # need file name to pass to sp.Popen + parser.add_argument('output_file', type=str) # need file name to pass to sqlite3.connect + + args = parser.parse_args(argv) + convert_arbin_to_sqlite(args.input_file, args.output_file) + + +if __name__ == '__main__': + main() From e5e75ff2f0131cf87d2e8616d9f8b3ce211236d7 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sun, 10 Mar 2019 09:28:09 +0100 Subject: [PATCH 2/5] Make res2sqlite.py an entry_point rather than a script --- {scripts => galvani}/res2sqlite.py | 0 setup.py | 5 ++++- 2 files changed, 4 insertions(+), 1 deletion(-) rename {scripts => galvani}/res2sqlite.py (100%) diff --git a/scripts/res2sqlite.py b/galvani/res2sqlite.py similarity index 100% rename from scripts/res2sqlite.py rename to galvani/res2sqlite.py diff --git a/setup.py b/setup.py index 40130ce..0d26328 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,7 @@ setup( description='Open and process battery charger log data files', url='https://github.com/chatcannon/galvani', author='Chris Kerr', + author_email='chris.kerr@mykolab.ch', license='GPLv3+', classifiers=[ 'Development Status :: 3 - Alpha', @@ -16,6 +17,8 @@ setup( 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 'Natural Language :: English'], packages=['galvani'], - scripts=['scripts/res2sqlite.py'], # TODO make this use entry_points + entry_points={'console_scripts': [ + 'res2sqlite = galvani.res2sqlite:main', + ]}, install_requires=['numpy'] ) From ef95863735d2d33e12e99322d0293e6765846901 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sun, 10 Mar 2019 09:51:34 +0100 Subject: [PATCH 3/5] Use README.md for long_description --- setup.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/setup.py b/setup.py index 0d26328..f1dd8b7 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,18 @@ # -*- coding: utf-8 -*- +import os.path + from setuptools import setup +with open(os.path.join(os.path.dirname(__file__), 'README.md')) as f: + readme = f.read() + setup( name='galvani', version='0.0.1a1', description='Open and process battery charger log data files', + long_description=readme, + long_description_content_type="text/markdown", url='https://github.com/chatcannon/galvani', author='Chris Kerr', author_email='chris.kerr@mykolab.ch', From bf24fbfa00c253a9ec5e5562229218b8ed3fb908 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sun, 10 Mar 2019 09:56:00 +0100 Subject: [PATCH 4/5] Minor formatting tweaks --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f1dd8b7..1553c7b 100644 --- a/setup.py +++ b/setup.py @@ -22,10 +22,11 @@ setup( 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', - 'Natural Language :: English'], + 'Natural Language :: English', + ], packages=['galvani'], entry_points={'console_scripts': [ 'res2sqlite = galvani.res2sqlite:main', ]}, - install_requires=['numpy'] + install_requires=['numpy'], ) From 757f56826bd273369c15c20882b4d24884de152c Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sun, 10 Mar 2019 10:41:56 +0100 Subject: [PATCH 5/5] Release version 0.0.1 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 1553c7b..8b6538b 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ with open(os.path.join(os.path.dirname(__file__), 'README.md')) as f: setup( name='galvani', - version='0.0.1a1', + version='0.0.1', description='Open and process battery charger log data files', long_description=readme, long_description_content_type="text/markdown", @@ -18,7 +18,7 @@ setup( author_email='chris.kerr@mykolab.ch', license='GPLv3+', classifiers=[ - 'Development Status :: 3 - Alpha', + 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',