# 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
   with open(str(filename), 'rb') as f:
       while True:
           buf = f.read(2**20)
           if not buf:
               break
           read_size += len(buf)
           m.update(buf)
           percent_done = 100 * read_size / total_size
           if percent_done > last_percent_done:
               sys.stdout.write('[%d%%]\r' % percent_done)
               sys.stdout.flush()


               last_percent_done = percent_done
   md5_output = m.hexdigest()
   return md5_output

def add_value(value, element):
    element.text = value


def write_premis(doc, premisxml):
    with open(premisxml,'w') as outFile:
        doc.write(outFile,pretty_print=True)


def create_unit(index,parent, unitname):
    premis_namespace = "http://www.loc.gov/premis/v3"
    unitname = ET.Element("{%s}%s" % (premis_namespace, unitname))
    parent.insert(index,unitname)

# 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

   with open(str(filename), 'rb') as f:
       while True:
           buf = f.read(2**20)
           if not buf:
               break
           read_size += len(buf)
           m.update(buf)
           percent_done = 100 * read_size / total_size
           if percent_done > last_percent_done:
               sys.stdout.write('[%d%%]\r' % percent_done)
               sys.stdout.flush()


               last_percent_done = percent_done
   md5_output = m.hexdigest()
   return md5_output

def add_value(value, element):
    element.text = value


def write_premis(doc, premisxml):
    with open(premisxml,'w') as outFile:
        doc.write(outFile,pretty_print=True)


def create_unit(index,parent, unitname):
    premis_namespace = "http://www.loc.gov/premis/v3"
    unitname = ET.Element("{%s}%s" % (premis_namespace, unitname))
    parent.insert(index,unitname)

    return unitname