DUNE-DAQ / minidaqapp

0 stars 1 forks source link

candidate (simpler) command-line argument capture #97

Closed bieryAtFnal closed 2 years ago

bieryAtFnal commented 2 years ago

Alessandro and Eric...

Alessandro, on this branch, I provide a simpler command-line option capture which I believe is more in the spirit of what you were looking for.

I'm sending this change to you for your consideration and any discussion that you would like to have with Eric about his version of the change.

For reference, Eric's change (which is already on the patch/2.8.2 branch) produces a file with contents like the following. I have been using this change in all of my testing this afternoon, and it has performed fine for me:

{
    "build_info": {},
    "command_line": "/home/biery/dunedaq/08Nov282/install/minidaqapp/lib64/python/minidaqapp/nanorc/mdapp_multiru_gen.py --host-ru localhost -d /home/biery/dunedaq/08Nov282/rundir/frames.bin -o . -s 10 --enable-dqm mdapp_4proc_dqm_AAA",
    "mdapp_dir": "/home/biery/dunedaq/08Nov282/install/minidaqapp/lib64/python/minidaqapp/nanorc"
}

The code on this branch produces a simpler file:

/home/biery/dunedaq/08Nov282/install/minidaqapp/lib64/python/minidaqapp/nanorc/mdapp_multiru_gen.py --host-ru localhost -d /home/biery/dunedaq/08Nov282/rundir/frames.bin -o . -s 10 --enable-dqm mdapp_4proc_dqm_MMM

In both cases, it's not obvious how to use the whole string to re-run the confgen script. the first argument always generates a complaint, for me. But, we can still make use of the rest of the arguments.

eflumerf commented 2 years ago

I think the problem is that sys.argv does not take into account how the script was originally called (python -m <script> or /usr/bin/env python <script>)

bieryAtFnal commented 2 years ago

In my original text, I should have said that the original changes from Eric are very likely desirable, but at a later time.

eflumerf commented 2 years ago

Since we always use the interpreter, would it be too hacky to write something like: f.write("python -m minidaqapp.nanorc.mdapp_multiru_gen " + ' '.join(sys.argv[1:]) + "\n")

alessandrothea commented 2 years ago

If we hacky is what we want... 😉

f.write(f"{sys.executable} -m {__name__} {' '.join(sys.argv[1:])}\n")

Maybe it's worth also adding a minimal protection against spaces in one of the arguments

import shlex # have we got shlex in our pyenv?
f.write(f"{sys.executable} -m {__name__} {' '.join((shlex.quote(a) if ' ' in a else a) for sys.argv[1:])}\n")
eflumerf commented 2 years ago

I believe this PR is obsolete, as v2.8.2 was released with the other form of the command-line capture.