Last active
January 30, 2019 15:41
-
-
Save kieranjol/aa8e9a87fff0f25820b1edb9e89c69b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #usr/bin/env python | |
| ''' | |
| Loop/iterate through all files within subfolders: | |
| find the SIP log file | |
| how to process each line in a textfile | |
| find the line in the log file that contains the reference number | |
| extract just the value | |
| print a list of values | |
| maybe find some way to insert into the OE register | |
| ''' | |
| import os | |
| import sys | |
| import ififuncs | |
| source_dir = sys.argv[1] | |
| for root, dirnames, filenames in sorted(os.walk(source_dir)): | |
| for filename in filenames: | |
| if filename.endswith('_sip_log.log'): | |
| full_path = os.path.join(root, filename) | |
| with open(full_path) as logfile: | |
| for line in logfile: | |
| if 'Input =' in line: | |
| base, ext = os.path.splitext(line.rstrip().split()[-1]) | |
| original_oe = base | |
| if 'eventIdentifierType=UUID' in line: | |
| uuid = line.split('value=')[-1].rstrip().split(',')[0] | |
| if 'has source' in line: | |
| source_tape = line.split('has source=')[-1].rstrip() | |
| if 'eventIdentifierType=object entry' in line: | |
| new_oe = line.split('value=')[-1].rstrip() | |
| if 'eventIdentifierType=Filmographic reference number' in line: | |
| ref_no = line.split('value=')[-1].rstrip() | |
| if 'eventIdentifierType=accession number' in line: | |
| accession_number = line.split('value=')[-1].rstrip() | |
| location = os.path.dirname(os.path.dirname(os.path.dirname(full_path))) | |
| print '%s,%s,%s,%s,%s,%s,%s ' % (original_oe, uuid, source_tape, new_oe, ref_no, accession_number, location) | |
| '''' | |
| if 'eventIdentifierType=Filmographic reference number' in line: | |
| print('Representation of ' + line.split('value=')[-1].rstrip() +'|') | |
| ''' | |
| ''' | |
| if 'Input =' in line: | |
| base, ext = os.path.splitext(line.rstrip().split()[-1]) | |
| #print base, ext | |
| old_oe_filename = os.path.join(root.replace('logs', 'objects'), os.path.splitext(line.rstrip().split()[-1])[0]) + '%s' % ext | |
| print old_oe_filename | |
| objects = os.path.dirname(old_oe_filename) | |
| uuid_filename = os.path.join(objects, os.listdir(objects)[0]) | |
| print uuid_filename | |
| os.rename(uuid_filename, old_oe_filename) | |
| ''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment