# 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
    return video_files


def make_premis(source_file, items, premis, premis_namespace, premisxml,representation_uuid,sequence):
    # the sequence argument determines if a sequence counter is launched
    xml_info = create_object(source_file, items, premis, premis_namespace, premisxml, representation_uuid, sequence)
    return xml_info


def make_agent(premis,linkingEventIdentifier_values, agentId ):
    csv_file = os.path.expanduser("~/ifigit/ifiscripts/premis_agents.csv")
    if os.path.isfile(csv_file):
        read_object = open(csv_file)
        reader = csv.reader(read_object)
        csv_list = list(reader)
        read_object.close()
    for lists in csv_list:
        for item in lists:
            if item == agentId:
                agent_info = lists
    agentIdType_value,agentIdValue_value,agentName_value,agentType_value, agentVersion_value,agentNote_value,agentRole = agent_info

    if agentVersion_value == 'ffmpeg_autoextract':
        agentVersion_value = subprocess.check_output(['ffmpeg','-version','-v','0']).splitlines()[0]
    premis_namespace            = "http://www.loc.gov/premis/v3"
    agent                       = ET.SubElement(premis, "{%s}agent" % (premis_namespace))
    premis.insert(-1, agent)
    agentIdentifier             = create_unit(1,agent,'agentIdentifier')
    agentIdType                 = create_unit(2,agentIdentifier,'agentIdentifierType')
    agentIdValue                = create_unit(2,agentIdentifier,'agentIdentifierValue')

# 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

    return video_files


def make_premis(source_file, items, premis, premis_namespace, premisxml,representation_uuid,sequence):
    # the sequence argument determines if a sequence counter is launched
    xml_info = create_object(source_file, items, premis, premis_namespace, premisxml, representation_uuid, sequence)
    return xml_info


def make_agent(premis,linkingEventIdentifier_values, agentId ):
    csv_file = os.path.expanduser("~/ifigit/ifiscripts/premis_agents.csv")
    if os.path.isfile(csv_file):
        read_object = open(csv_file)
        reader = csv.reader(read_object)
        csv_list = list(reader)
        read_object.close()
    for lists in csv_list:
        for item in lists:
            if item == agentId:
                agent_info = lists
    agentIdType_value,agentIdValue_value,agentName_value,agentType_value, agentVersion_value,agentNote_value,agentRole = agent_info

    if agentVersion_value == 'ffmpeg_autoextract':
        agentVersion_value = subprocess.check_output(['ffmpeg','-version','-v','0']).splitlines()[0]
    premis_namespace            = "http://www.loc.gov/premis/v3"
    agent                       = ET.SubElement(premis, "{%s}agent" % (premis_namespace))
    premis.insert(-1, agent)
    agentIdentifier             = create_unit(1,agent,'agentIdentifier')
    agentIdType                 = create_unit(2,agentIdentifier,'agentIdentifierType')
    agentIdValue                = create_unit(2,agentIdentifier,'agentIdentifierValue')

    agentName                   = create_unit(2,agent,'agentName')