# Path: ififuncs.py
# def make_desktop_logs_dir():
#     desktop_logs_dir = os.path.expanduser("~/Desktop/ifiscripts_logs")
#     if not os.path.isdir(desktop_logs_dir):
#         #I should probably ask permission here, or ask for alternative location
#         os.makedirs(desktop_logs_dir)
#     return desktop_logs_dir
# 
# def make_desktop_manifest_dir():
#     desktop_manifest_dir = os.path.expanduser("~/Desktop/moveit_manifests")
#     if not os.path.isdir(desktop_manifest_dir):
#         #I should probably ask permission here, or ask for alternative location
#         os.makedirs(desktop_manifest_dir)
#         os.makedirs(os.path.join(desktop_manifest_dir, 'old_manifests'))
#     else:
#         if not os.path.isdir(os.path.join(desktop_manifest_dir, 'old_manifests')):
#             os.makedirs(os.path.join(desktop_manifest_dir, 'old_manifests'))
#     return desktop_manifest_dir
# 
# def generate_log(log, what2log):
#     if not os.path.isfile(log):
#         with open(log, "w", encoding='utf-8') as fo:
#             fo.write(time.strftime("%Y-%m-%dT%H:%M:%S ")
#                      + getpass.getuser()
#                      + ' ' + what2log + ' \n')
#     else:
#         with open(log, "a", encoding='utf-8') as fo:
#             fo.write(time.strftime("%Y-%m-%dT%H:%M:%S ")
#                      + getpass.getuser()
#                      + ' ' + what2log + ' \n')


import sys
import subprocess
import os
import filecmp
import tempfile
import time
import argparse
import hashlib
import shutil
import unicodedata
import ififuncs
from builtins import input
from ififuncs import make_desktop_logs_dir, make_desktop_manifest_dir, generate_log
    last_percent_done = 0
    md5_object = hashlib.md5()
    total_size = os.path.getsize(filename)
    with open(str(filename), 'rb') as file_object:
        while True:
            buf = file_object.read(2**20)
            if not buf:
                break
            read_size += len(buf)
            md5_object.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 = md5_object.hexdigest()
    return md5_output + '  ' + os.path.abspath(filename) +  '\n'


def test_write_capabilities(directory, log_name_source):
    '''
    Checks if drives have write access.
    Also checks if source is a file or directory (no file support right now)
    '''
    if os.path.isdir(directory):
        temp = tempfile.mkstemp(dir=directory, suffix='.tmp')
        os.close(temp[0]) # Needed for windows.
        os.remove(temp[1])
    elif os.path.isfile(directory):
        print('\nFile transfer is not currently supported, only directories.\n')

# Path: ififuncs.py
# def make_desktop_logs_dir():
#     desktop_logs_dir = os.path.expanduser("~/Desktop/ifiscripts_logs")
#     if not os.path.isdir(desktop_logs_dir):
#         #I should probably ask permission here, or ask for alternative location
#         os.makedirs(desktop_logs_dir)
#     return desktop_logs_dir
# 
# def make_desktop_manifest_dir():
#     desktop_manifest_dir = os.path.expanduser("~/Desktop/moveit_manifests")
#     if not os.path.isdir(desktop_manifest_dir):
#         #I should probably ask permission here, or ask for alternative location
#         os.makedirs(desktop_manifest_dir)
#         os.makedirs(os.path.join(desktop_manifest_dir, 'old_manifests'))
#     else:
#         if not os.path.isdir(os.path.join(desktop_manifest_dir, 'old_manifests')):
#             os.makedirs(os.path.join(desktop_manifest_dir, 'old_manifests'))
#     return desktop_manifest_dir
# 
# def generate_log(log, what2log):
#     if not os.path.isfile(log):
#         with open(log, "w", encoding='utf-8') as fo:
#             fo.write(time.strftime("%Y-%m-%dT%H:%M:%S ")
#                      + getpass.getuser()
#                      + ' ' + what2log + ' \n')
#     else:
#         with open(log, "a", encoding='utf-8') as fo:
#             fo.write(time.strftime("%Y-%m-%dT%H:%M:%S ")
#                      + getpass.getuser()
#                      + ' ' + what2log + ' \n')


# Path: copyit.py
import sys
import subprocess
import os
import filecmp
import tempfile
import time
import argparse
import hashlib
import shutil
import unicodedata
import ififuncs
from builtins import input
from ififuncs import make_desktop_logs_dir, make_desktop_manifest_dir, generate_log

    last_percent_done = 0
    md5_object = hashlib.md5()
    total_size = os.path.getsize(filename)
    with open(str(filename), 'rb') as file_object:
        while True:
            buf = file_object.read(2**20)
            if not buf:
                break
            read_size += len(buf)
            md5_object.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 = md5_object.hexdigest()
    return md5_output + '  ' + os.path.abspath(filename) +  '\n'


def test_write_capabilities(directory, log_name_source):
    '''
    Checks if drives have write access.
    Also checks if source is a file or directory (no file support right now)
    '''
    if os.path.isdir(directory):
        temp = tempfile.mkstemp(dir=directory, suffix='.tmp')
        os.close(temp[0]) # Needed for windows.
        os.remove(temp[1])
    elif os.path.isfile(directory):
        print('\nFile transfer is not currently supported, only directories.\n')

        generate_log(