From 240dd52270c1baeb93867dabf9e98e44a6230e8a Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Thu, 29 Aug 2024 20:06:23 -0400 Subject: [PATCH 1/2] Make rcnd executable --- bin/rcnd | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bin/rcnd diff --git a/bin/rcnd b/bin/rcnd old mode 100644 new mode 100755 From 0518729e73bac17a4795350588292f2b25d7664c Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Thu, 29 Aug 2024 20:46:42 -0400 Subject: [PATCH 2/2] Make rcnd and rcdb commands python only --- .github/workflows/python-tests.yml | 4 ++-- bin/rcdb | 16 ++++++++++++++-- bin/rcnd | 25 +++++++++++++++++++++++-- python/rcdb/rcdb_cli/ls.py | 4 +--- python/utilites/rcnd.py | 5 ++++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index c6c1edb..8154753 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -31,6 +31,6 @@ jobs: run: | source environment.bash echo "rcnd command is running" - rcnd + rcnd --help echo "rcdb command is running" - rcdb + rcdb --help diff --git a/bin/rcdb b/bin/rcdb index f6b6f00..5c870b0 100755 --- a/bin/rcdb +++ b/bin/rcdb @@ -1,3 +1,15 @@ -#!/bin/sh +#!/usr/bin/env python3 -/usr/bin/env python3 $RCDB_HOME/python/rcdb/rcdb_cli "$@" \ No newline at end of file +import os +import sys + +# Figure out where is python directory +this_file_dir = os.path.dirname(os.path.abspath(__file__)) +python_dir = os.path.join(this_file_dir, '..', 'python') + +# Add the directory to the Python modules search path +sys.path.insert(0, python_dir) + +# Import and run rcdb +from rcdb.rcdb_cli.app import rcdb_cli +rcdb_cli(prog_name="rcdb") diff --git a/bin/rcnd b/bin/rcnd index f8cedf5..d6f9749 100755 --- a/bin/rcnd +++ b/bin/rcnd @@ -1,4 +1,25 @@ -#!/bin/sh +#!/usr/bin/env python3 -/usr/bin/env python $RCDB_HOME/python/rcdb/rcnd.py "$@" +import os +import sys +import importlib.util +# Figure out where is rcnd.py located +this_file_dir = os.path.dirname(os.path.abspath(__file__)) + +this_file_dir = os.path.dirname(os.path.abspath(__file__)) +python_dir = os.path.join(this_file_dir, '..', 'python') + +# Add the directory to the Python modules search path +sys.path.insert(0, python_dir) + +module_path = os.path.join(this_file_dir, '..', 'python', 'utilites', 'rcnd.py') +module_path = os.path.abspath(module_path) + +# Load the module from the specified file +spec = importlib.util.spec_from_file_location('rcnd', module_path) +rcnd = importlib.util.module_from_spec(spec) +spec.loader.exec_module(rcnd) + +# Now you can use functions from the module +rcnd.main() diff --git a/python/rcdb/rcdb_cli/ls.py b/python/rcdb/rcdb_cli/ls.py index 5b0efd6..21e21c3 100644 --- a/python/rcdb/rcdb_cli/ls.py +++ b/python/rcdb/rcdb_cli/ls.py @@ -11,9 +11,7 @@ def ls(context, search, is_long): """Lists conditions""" - print(context) - exit(0) - + db = context.db assert isinstance(db, RCDBProvider) cnd_types = db.get_condition_types_by_name() diff --git a/python/utilites/rcnd.py b/python/utilites/rcnd.py index a40b583..ec689ff 100644 --- a/python/utilites/rcnd.py +++ b/python/utilites/rcnd.py @@ -217,7 +217,7 @@ def new_run(db, run_number): print("Created run number {}".format(run_number)) -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser(description=help_text, epilog=examples, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-c", "--connection", help="Connection string to database", metavar='', default="") @@ -320,3 +320,6 @@ def new_run(db, run_number): log.debug("No run_number, no condition_name. Show stats") print_stats(rcdb_db) exit(0) + +if __name__ == "__main__": + main() \ No newline at end of file