Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errore creazione file h5 in skalab_subrack.py #1

Open
simonechiarucci opened this issue Mar 24, 2023 · 0 comments
Open

Errore creazione file h5 in skalab_subrack.py #1

simonechiarucci opened this issue Mar 24, 2023 · 0 comments

Comments

@simonechiarucci
Copy link
Contributor

simonechiarucci commented Mar 24, 2023

Se la directory fname non esiste, python da' errore durante la creazione del file h5 in h5py.File(fname, 'a').

Errore:

Traceback (most recent call last):
  File "/home/aavs/simone/aavs-system/python/utilities/skalab/skalab_subrack.py", line 188, in <lambda>
    self.wg.qbutton_connect.clicked.connect(lambda: self.connect())
  File "/home/aavs/simone/aavs-system/python/utilities/skalab/skalab_subrack.py", line 508, in connect
    self.tlm_hdf = self.setup_hdf5()
  File "/home/aavs/simone/aavs-system/python/utilities/skalab/skalab_subrack.py", line 475, in setup_hdf5
    return h5py.File(fname, 'a')
  File "/opt/aavs/python/lib/python3.8/site-packages/h5py/_hl/files.py", line 533, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
  File "/opt/aavs/python/lib/python3.8/site-packages/h5py/_hl/files.py", line 252, in make_fid
    fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 126, in h5py.h5f.create
FileNotFoundError: [Errno 2] Unable to create file (unable to open file: name = '/storage/monitoring/subrack/subrack_tlm_2023-03-24_113931.h5', errno = 2, error message = 'File o directory non esistente', flags = 15, o_flags = c2)

Attuale metodo:

def setup_hdf5(self):
        if not self.profile['SubRack']['data_path'] == "":
            fname = self.profile['SubRack']['data_path']
            if not fname[-1] == "/":
                fname = fname + "/"
            fname += datetime.datetime.strftime(datetime.datetime.utcnow(), "subrack_tlm_%Y-%m-%d_%H%M%S.h5")
            return h5py.File(fname, 'a')
        else:
            msgBox = QtWidgets.QMessageBox()
            msgBox.setText("Please Select a valid path to save the Subrack data and save it into the current profile")
            msgBox.setWindowTitle("Error!")
            msgBox.setIcon(QtWidgets.QMessageBox.Critical)
            msgBox.exec_()
            return None

Possibile soluzione:

def setup_hdf5(self):
        if not self.profile['SubRack']['data_path'] == "":
            fname = self.profile['SubRack']['data_path']
            if not fname[-1] == "/":
                fname = fname + "/"
                if  os.path.exists(str(Path.home()) + fname) != True:
                    os.makedirs(str(Path.home()) + fname)
            fname += datetime.datetime.strftime(datetime.datetime.utcnow(), "subrack_tlm_%Y-%m-%d_%H%M%S.h5")
            return h5py.File(str(Path.home()) + fname, 'a')
        else:
            msgBox = QtWidgets.QMessageBox()
            msgBox.setText("Please Select a valid path to save the Subrack data and save it into the current profile")
            msgBox.setWindowTitle("Error!")
            msgBox.setIcon(QtWidgets.QMessageBox.Critical)
            msgBox.exec_()
            return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant