date, fieldstr = mtr.info_from_tarfile(localizer) except: logging.error('Error pulling info from {}'.format(localizer)) logging.error('skipping {}'.format(sub)) continue arda_dirname = mtr.make_dirname(date, visitstr, fieldstr + 'T') print arda_dirname ardadir = mtr.os.path.join(arda, subid, arda_dirname) exists, _ = mtr.glob_file(ardadir) if exists: logging.warn('{} exists, skipping'.format(ardadir)) continue os.makedirs(ardadir) for scan in scans: newfile = mtr.fname_presuffix(scan, prefix = subid, newpath = ardadir) mtr.copy_file_withdate(scan, newfile) logging.info('copy: {}'.format(newfile)) scannotes = glob(os.path.join(sub, '*scan*notes*.txt' )) try: mtr.copy_file_withdate(scannotes[0], ardadir) logging.info('{} copy scannotes'.format(ardadir)) except: logging.info('{} missing scan notes'.format(sub)) ## get files ## make outdir ## rename and move files
# has multiple visits in raw, fix logging.error('%s multiple visits, %s skipping'%(raw, dates)) continue #dates and fields are all good else: dirname = mtr.make_dirname(date, visit_number, field) ardadir = mtr.os.path.join(arda, subid, dirname) exists, _ = mtr.glob_file(ardadir) if not exists: os.makedirs(ardadir) # tar zip individual scans to destdir for renamed in newnames: cmd = mtr.renamed_archive_copy(renamed, ardadir) os.system(cmd) logging.info('copied raw and converted to %s'%(ardadir)) mtr.copy_file_withdate(raw, ardadir) mtr.clean_tmpdir(tmpdir) #deal with scan notes # scan notes notes_exist, sync_notes = mtr.get_scannotes_fromsync(raw, visit_number) if notes_exist: _, notes_name = os.path.split(sync_notes) arda_notes = os.path.join(ardadir, notes_name) arda_notes_exist, _ = mtr.glob_file(arda_notes) if arda_notes_exist: same = mtr.compare_filedates(sync_notes, arda_notes) if not same: mtr.copy_file_withdate(sync_notes,ardadir) logging.info('updated %s'%(arda_notes))