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

reload metadata #152

Open
jonorthwash opened this issue Dec 23, 2020 · 1 comment
Open

reload metadata #152

jonorthwash opened this issue Dec 23, 2020 · 1 comment
Assignees
Labels
data formats enhancement New feature or request

Comments

@jonorthwash
Copy link
Collaborator

A little refresh button somewhere up in the "Recording" section that does the following:

  • Rescans files and updates anything in metadata as needed
  • Does not erase traces! Maybe traces and metadata should be separated into different files?
  • Updates the interface to include any new files (or remove ones that no longer exist)
@jonorthwash
Copy link
Collaborator Author

jonorthwash commented Apr 10, 2024

This will involve separating out the "scan project" code into a separate function, and having both the startup code and the "reload metadata" / "rescan project" button (I think I like the latter name) call it.

I believe the "scan project" code is approximately this section:

# we want each object to have entries for everything here
fileKeys = { '_prev', '_next', 'processed', 'offset' } # and `processed`
MIMEs = {
'audio/x-wav' : ['.wav'],
'audio/x-flac' : ['.flac'],
'audio/wav' : ['.wav'],
'audio/flac' : ['.flac'],
'application/dicom' : ['.dicom'],
'text/plain' : ['.TextGrid', 'US.txt', '.txt', '.dat'],
'application/octet-stream' : ['.ult'],
'application/x-dosexec' : ['.ult']
}
files = {}
splines = None
# now get the objects in subdirectories
for path, dirs, fs in os.walk( self.path ):
for f in fs:
# exclude some filetypes explicitly here by MIME type
filepath = os.path.join( path, f )
filename, extension = os.path.splitext( f )
# allow us to follow symlinks
real_filepath = os.path.realpath(filepath)
#make file path relative to metadata file
filepath = os.path.relpath(filepath,start=self.path)
mime_type = Magic(mime=True).from_file(real_filepath)
# name mangling for ULT directories
if mime_type == 'text/plain' and extension == '.txt' and filename.endswith('US'):
filename = filename[:-2]
extension = 'US.txt'
if extension == '.wav' and filename.endswith('_Track0'):
filename = filename[:-7]
elif extension == '.wav' and (filename.endswith('_Track1') or filename.endswith('_Track2')):
continue
elif extension == '.dat' and filename == 'SPLINES':
splines = filepath
continue
if (mime_type == 'text/plain' or mime_type == 'application/json') and extension == '.measurement':
debug('Found old measurement file {}'.format(filename))
self.importOldMeasurement(real_filepath, filename)
elif mime_type in MIMEs:
# add `good` files
if extension in MIMEs[ mime_type ]:
if filename not in files:
files[filename] = { key:None for key in fileKeys }
files[filename][extension] = filepath
elif mime_type == 'image/png' and '_dicom_to_png' in path:
# check for preprocessed dicom files
name, frame = filename.split( '_frame_' )
#debug(files)
# if len(files) > 0:
# might be able to combine the following; check
if name not in files:
files[name] = {'processed': None}
if files[name]['processed'] == None:
files[name]['processed'] = {}
files[name]['processed'][str(int(frame))] = filepath
# check that we find at least one file
if len(files) == 0:
severe( ' - ERROR: `%s` contains no supported files' % path )
exit()
# sort the files so that we can guess about left/right ... extrema get None/null
# also add in the "traces" bit here
_prev = None
for key in sorted( files.keys() ):
if _prev != None:
files[_prev]['_next'] = key
files[key]['_prev'] = _prev
_prev = key
files[key]['name'] = key
# sort files, set the geometry, and write
self.data[ 'files' ] = [ files[key] for key in sorted(files.keys()) ]
self.data[ 'geometry' ] = '1150x800+1400+480'
if splines != None:
self.importULTMeasurement(splines)
self.write()
)

The definition of MIMEs should be moved to outside of this function, as a static variable. Note also that the MIME stuff will interact with #179.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data formats enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants