# Path: ififuncs.py
# def append_csv(csv_file, *args):
#     f = open(csv_file, 'a', newline='')
#     try:
#         writer = csv.writer(f)
#         writer.writerow(*args)
#     finally:
#         f.close()
# 
# Path: ififuncs.py
# def create_csv(csv_file, *args):
#     f = open(csv_file, 'w', newline='')
#     try:
#         writer = csv.writer(f)
#         writer.writerow(*args)
#     finally:
#         f.close()


import lxml.etree as ET
import lxml.builder as builder
import uuid
import time
import sys
import subprocess
import os
import hashlib
import csv
from glob import glob
from collections import OrderedDict
from ififuncs import append_csv
from ififuncs import create_csv
    rep_counter = 0
    print 'Generating PREMIS metadata about each file object - this may take some time if on a network and/or working with an image sequence'
    for image in video_files:
        object_parent                                           = create_unit(-1,premis, 'object')
        object_identifier_uuid                                  = create_unit(1,object_parent, 'objectIdentifier')
        object_identifier_uuid_type                             = create_unit(1,object_identifier_uuid, 'objectIdentifierType')
        object_identifier_uuid_type.text                        = 'UUID'
        object_identifier_uuid_value                            = create_unit(2,object_identifier_uuid, 'objectIdentifierValue')
        file_uuid                                               = str(uuid.uuid4())
        image_uuids.append(file_uuid)
        object_identifier_uuid_value.text                       = file_uuid
        objectCategory                                          = ET.Element("{%s}objectCategory" % (premis_namespace))
        object_parent.insert(5,objectCategory)
        objectCategory.text                                     = 'file'

        if rep_counter == 0:
            root_uuid = file_uuid

        rep_counter +=1
        format_ = ET.Element("{%s}format" % (premis_namespace))
        objectCharacteristics                                   = create_unit(10,object_parent, 'objectCharacteristics')
        objectCharacteristics.insert(2,format_)

        mediainfo                       = subprocess.check_output(['mediainfo', '-f', '--language=raw', '--Output=XML', image])
        parser                          = ET.XMLParser(remove_blank_text=True)
        mediainfo_xml                   = ET.fromstring((mediainfo),parser=parser)
        fixity                          = create_unit(0,objectCharacteristics,'fixity')
        size                            = create_unit(1,objectCharacteristics,'size')
        size.text                       = str(os.path.getsize(image))
        formatDesignation               = create_unit(0,format_,'formatDesignation')

# Path: ififuncs.py
# def append_csv(csv_file, *args):
#     f = open(csv_file, 'a', newline='')
#     try:
#         writer = csv.writer(f)
#         writer.writerow(*args)
#     finally:
#         f.close()
# 
# Path: ififuncs.py
# def create_csv(csv_file, *args):
#     f = open(csv_file, 'w', newline='')
#     try:
#         writer = csv.writer(f)
#         writer.writerow(*args)
#     finally:
#         f.close()


# Path: premis.py
import lxml.etree as ET
import lxml.builder as builder
import uuid
import time
import sys
import subprocess
import os
import hashlib
import csv
from glob import glob
from collections import OrderedDict
from ififuncs import append_csv
from ififuncs import create_csv

    rep_counter = 0
    print 'Generating PREMIS metadata about each file object - this may take some time if on a network and/or working with an image sequence'
    for image in video_files:
        object_parent                                           = create_unit(-1,premis, 'object')
        object_identifier_uuid                                  = create_unit(1,object_parent, 'objectIdentifier')
        object_identifier_uuid_type                             = create_unit(1,object_identifier_uuid, 'objectIdentifierType')
        object_identifier_uuid_type.text                        = 'UUID'
        object_identifier_uuid_value                            = create_unit(2,object_identifier_uuid, 'objectIdentifierValue')
        file_uuid                                               = str(uuid.uuid4())
        image_uuids.append(file_uuid)
        object_identifier_uuid_value.text                       = file_uuid
        objectCategory                                          = ET.Element("{%s}objectCategory" % (premis_namespace))
        object_parent.insert(5,objectCategory)
        objectCategory.text                                     = 'file'

        if rep_counter == 0:
            root_uuid = file_uuid

        rep_counter +=1
        format_ = ET.Element("{%s}format" % (premis_namespace))
        objectCharacteristics                                   = create_unit(10,object_parent, 'objectCharacteristics')
        objectCharacteristics.insert(2,format_)

        mediainfo                       = subprocess.check_output(['mediainfo', '-f', '--language=raw', '--Output=XML', image])
        parser                          = ET.XMLParser(remove_blank_text=True)
        mediainfo_xml                   = ET.fromstring((mediainfo),parser=parser)
        fixity                          = create_unit(0,objectCharacteristics,'fixity')
        size                            = create_unit(1,objectCharacteristics,'size')
        size.text                       = str(os.path.getsize(image))
        formatDesignation               = create_unit(0,format_,'formatDesignation')

        formatName                      = create_unit(1,formatDesignation,'formatName')