[chronojump] Adds new command line option in the chronojump_importer.py to import into a session.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Adds new command line option in the chronojump_importer.py to import into a session.
- Date: Tue, 25 Oct 2016 16:55:43 +0000 (UTC)
commit 5f2bec1dc1ae6a4e12a8bb59f2bd35ba68174d5c
Author: Carles Pina i Estany <carles pina cat>
Date: Tue Oct 25 18:52:19 2016 +0200
Adds new command line option in the chronojump_importer.py to import into a session.
Until now the sesssions were always imported as new sessions. Now, if
--destination-session exists it imports the data from a session into an
existing session (reusing persons and other things).
Chronojump C# code doesn't use it yet.
It also adds an integration test for this.
src/chronojump-importer/chronojump_importer.py | 19 +++++++++-
.../chronojump_importer_test.py | 36 ++++++++++++++------
.../tests/yoyo-expected-session-4-to-5.sqlite | Bin 0 -> 1503232 bytes
3 files changed, 42 insertions(+), 13 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index d5cd1e9..486a678 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -386,10 +386,17 @@ class ImportSession:
self.persons77 = None
+ def import_into_session(self, source_session, destination_session):
+ self.source_session = source_session
+ self.new_session_id = destination_session
+ self.import_data()
+
def import_as_new_session(self, source_session):
self.source_session = source_session
self.new_session_id = self._import_session()
+ self.import_data()
+ def import_data(self):
self.persons77 = self._import_persons77()
self._import_person_session77()
@@ -683,7 +690,11 @@ def process_command_line():
parser.add_argument("--destination", type=str, required=False,
help="chronojump.sqlite that we import to")
parser.add_argument("--source_session", type=int, required=False,
- help="Session from source that will be imported to a new session in destination")
+ help="Session from source that will be imported to the session specified by
--destination-session\n"
+ "or to a new session if no --destination-session is specified")
+ parser.add_argument("--destination-session", type=int, required=False,
+ help="Imports the [source_session] into the [destination_session]. If not specified
imports as\n"
+ "new session.")
parser.add_argument("--json_information", required=False, action='store_true',
help="Shows information of the source database")
args = parser.parse_args()
@@ -698,7 +709,11 @@ def process_command_line():
source_base_directory = os.path.join(args.source, "../..")
importer = ImportSession(args.source, args.destination, source_base_directory)
- importer.import_as_new_session(args.source_session)
+
+ if args.destination_session is None:
+ importer.import_as_new_session(args.source_session)
+ else:
+ importer.import_into_session(args.source_session, args.destination_session)
else:
print("if --information not used --source, --destination and --source_session parameters are
required")
diff --git a/src/chronojump-importer/chronojump_importer_test.py
b/src/chronojump-importer/chronojump_importer_test.py
index 92f38ad..b5b8d45 100755
--- a/src/chronojump-importer/chronojump_importer_test.py
+++ b/src/chronojump-importer/chronojump_importer_test.py
@@ -19,10 +19,19 @@ class TestImporter(unittest.TestCase):
pass
@staticmethod
- def _prepare_database_to_import(base_filename):
+ def _prepare_database_to_import(base_filename, source_session=None, destination_session=None):
+
+ if destination_session is None:
+ expected_file_name = base_filename.format('expected')
+ else:
+ expected_file_name = base_filename.format('expected-session-{}-to-{}'.format(source_session,
destination_session))
+
+ return TestImporter._prepare_database_to_import_do(base_filename, expected_file_name)
+
+ @staticmethod
+ def _prepare_database_to_import_do(base_filename, expected_file_name):
source_file_name = base_filename.format('source')
destination_file_name = base_filename.format('destination')
- expected_file_name = base_filename.format('expected')
original_destination_file_path = base_filename.format('original-destination')
temporary_directory_path = tempfile.mkdtemp(
@@ -39,12 +48,13 @@ class TestImporter(unittest.TestCase):
# lists the names. {} will expand to source/destination/expected.
@ddt.data(
- {'base_filename': 'generic-{}-a.sqlite', 'session': 1},
- {'base_filename': 'generic-{}-b.sqlite', 'session': 1},
- {'base_filename': 'generic-{}-c.sqlite', 'session': 1},
- {'base_filename': 'padu-{}.sqlite', 'session': 1},
- {'base_filename': 'yoyo-{}.sqlite', 'session': 1},
- {'base_filename': 'user-jump-{}.sqlite', 'session': 1}
+ {'base_filename': 'generic-{}-a.sqlite', 'source_session': 1},
+ {'base_filename': 'generic-{}-b.sqlite', 'source_session': 1},
+ {'base_filename': 'generic-{}-c.sqlite', 'source_session': 1},
+ {'base_filename': 'padu-{}.sqlite', 'source_session': 1},
+ {'base_filename': 'yoyo-{}.sqlite', 'source_session': 1},
+ {'base_filename': 'user-jump-{}.sqlite', 'source_session': 1},
+ {'base_filename': 'yoyo-{}.sqlite', 'source_session': 4, 'destination_session': 5}
)
def test_importer_generic(self, data):
re_creates_test = False # During development change it to True
@@ -52,10 +62,14 @@ class TestImporter(unittest.TestCase):
# result as expected test
(source_file_path, destination_file_path, expected_file_name, temporary_directory_path) = \
- self._prepare_database_to_import(data["base_filename"])
+ self._prepare_database_to_import(data["base_filename"], data.get("source_session"),
data.get("destination_session", None))
importer = chronojump_importer.ImportSession(source_file_path, destination_file_path, None)
- importer.import_as_new_session(data["session"])
+
+ if 'destination_session' in data:
+ importer.import_into_session(data["source_session"], data["destination_session"])
+ else:
+ importer.import_as_new_session(data["source_session"])
os.system(
"echo .dump | sqlite3 {} > {}/destination.sql".format(destination_file_path,
temporary_directory_path))
@@ -105,7 +119,7 @@ class TestImporter(unittest.TestCase):
importer.import_as_new_session(7)
self.assertTrue(copy_function.called)
- self.assertEqual(copy_function.call_count, 11) # 11 encoding for session number 7
+ self.assertEqual(copy_function.call_count, 11) # 11 encodings for session number 7
def test_encoder_filename(self):
new_filename = chronojump_importer.ImportSession._encoder_filename(10, "19-test.txt")
diff --git a/src/chronojump-importer/tests/yoyo-expected-session-4-to-5.sqlite
b/src/chronojump-importer/tests/yoyo-expected-session-4-to-5.sqlite
new file mode 100644
index 0000000..e470dbc
Binary files /dev/null and b/src/chronojump-importer/tests/yoyo-expected-session-4-to-5.sqlite differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]