# Path: dgitcore/config.py
# def get_config():
#     if config is None:
#         init()
#     return config
# 
# Path: dgitcore/plugins/common.py
# def plugins_get_mgr():
#     """
#     Get the global plugin manager
#     """
#     global pluginmgr
#     return pluginmgr
# 
# Path: dgitcore/helper.py
# class bcolors:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'
# 
# def clean_str(s):
# 
#     for c in ['/', '\\','.',' ']:
#         s = s.replace(c,'_')
#     return s
# 
# class cd:
#     """Context manager for changing the current working directory"""
#     def __init__(self, newPath):
#         self.newPath = os.path.expanduser(newPath)
# 
#     def __enter__(self):
#         self.savedPath = os.getcwd()
#         os.chdir(self.newPath)
# 
#     def __exit__(self, etype, value, traceback):
#         os.chdir(self.savedPath)
# 
# def compute_sha256(filename):
#     """
#     Try the library. If it doesnt work, use the command line..
#     """
#     try:
#         h = sha256()
#         fd = open(filename, 'rb')
#         while True:
#             buf = fd.read(0x1000000)
#             if buf in [None, ""]:
#                 break
#             h.update(buf.encode('utf-8'))
#         fd.close()
#         return h.hexdigest()
#     except:
#         output = run(["sha256sum", "-b", filename])
#         return output.split(" ")[0]
# 
# def run(cmd):
#     """
#     Run a shell command
#     """
#     cmd = [pipes.quote(c) for c in cmd]
#     cmd = " ".join(cmd)
#     cmd += "; exit 0"
#     # print("Running {} in {}".format(cmd, os.getcwd()))
#     try:
#         output = subprocess.check_output(cmd,
#                                          stderr=subprocess.STDOUT,
#                                          shell=True)
#     except subprocess.CalledProcessError as e:
#             output = e.output
# 
#     output = output.decode('utf-8')
#     output = output.strip()
#     return output
# 
# def clean_name(n):
#     n = "".join([x if (x.isalnum() or x == "-") else "_" for x in n])
#     return n


import os, sys, copy, fnmatch, re, shutil
import yaml, json, tempfile
import webbrowser
import subprocess, string, random, pipes
import getpass
import mimetypes
import platform
import uuid, shutil
from collections import OrderedDict
from datetime import datetime
from hashlib import sha256
from dateutil import parser
from ..config import get_config
from ..plugins.common import plugins_get_mgr
from ..helper import bcolors, clean_str, cd, compute_sha256, run, clean_name

            #print(list(revised.keys()))
            #print(list(prefixes.keys()))

            if set(list(revised.keys())) == set(list(prefixes.keys())):
                prefixes = revised
                break
            else:
                print("Could not process edited file. Either some rows are missing or entry has YAML syntax errors")
                input("Press ENTER to continue")

    # Add the root directory back
    if "." in prefixes:
        prefixes[""] = prefixes["."]

    result = []
    ts = datetime.now().isoformat()
    for f in filenames:
        relativepath = prefixes[os.path.dirname(f)]
        if relativepath == ".":
            relativepath = os.path.basename(f)
        else:
            relativepath = os.path.join(relativepath, os.path.basename(f))

        result.append(OrderedDict([
            ('relativepath', relativepath),
            ('type', 'run-output'),
            ('actions', files[f]),
            ('mimetypes', mimetypes.guess_type(f)[0]),
            ('content', open(f).read(512)),

# Path: dgitcore/config.py
# def get_config():
#     if config is None:
#         init()
#     return config
# 
# Path: dgitcore/plugins/common.py
# def plugins_get_mgr():
#     """
#     Get the global plugin manager
#     """
#     global pluginmgr
#     return pluginmgr
# 
# Path: dgitcore/helper.py
# class bcolors:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'
# 
# def clean_str(s):
# 
#     for c in ['/', '\\','.',' ']:
#         s = s.replace(c,'_')
#     return s
# 
# class cd:
#     """Context manager for changing the current working directory"""
#     def __init__(self, newPath):
#         self.newPath = os.path.expanduser(newPath)
# 
#     def __enter__(self):
#         self.savedPath = os.getcwd()
#         os.chdir(self.newPath)
# 
#     def __exit__(self, etype, value, traceback):
#         os.chdir(self.savedPath)
# 
# def compute_sha256(filename):
#     """
#     Try the library. If it doesnt work, use the command line..
#     """
#     try:
#         h = sha256()
#         fd = open(filename, 'rb')
#         while True:
#             buf = fd.read(0x1000000)
#             if buf in [None, ""]:
#                 break
#             h.update(buf.encode('utf-8'))
#         fd.close()
#         return h.hexdigest()
#     except:
#         output = run(["sha256sum", "-b", filename])
#         return output.split(" ")[0]
# 
# def run(cmd):
#     """
#     Run a shell command
#     """
#     cmd = [pipes.quote(c) for c in cmd]
#     cmd = " ".join(cmd)
#     cmd += "; exit 0"
#     # print("Running {} in {}".format(cmd, os.getcwd()))
#     try:
#         output = subprocess.check_output(cmd,
#                                          stderr=subprocess.STDOUT,
#                                          shell=True)
#     except subprocess.CalledProcessError as e:
#             output = e.output
# 
#     output = output.decode('utf-8')
#     output = output.strip()
#     return output
# 
# def clean_name(n):
#     n = "".join([x if (x.isalnum() or x == "-") else "_" for x in n])
#     return n


# Path: dgitcore/datasets/files.py
import os, sys, copy, fnmatch, re, shutil
import yaml, json, tempfile
import webbrowser
import subprocess, string, random, pipes
import getpass
import mimetypes
import platform
import uuid, shutil
from collections import OrderedDict
from datetime import datetime
from hashlib import sha256
from dateutil import parser
from ..config import get_config
from ..plugins.common import plugins_get_mgr
from ..helper import bcolors, clean_str, cd, compute_sha256, run, clean_name


            #print(list(revised.keys()))
            #print(list(prefixes.keys()))

            if set(list(revised.keys())) == set(list(prefixes.keys())):
                prefixes = revised
                break
            else:
                print("Could not process edited file. Either some rows are missing or entry has YAML syntax errors")
                input("Press ENTER to continue")

    # Add the root directory back
    if "." in prefixes:
        prefixes[""] = prefixes["."]

    result = []
    ts = datetime.now().isoformat()
    for f in filenames:
        relativepath = prefixes[os.path.dirname(f)]
        if relativepath == ".":
            relativepath = os.path.basename(f)
        else:
            relativepath = os.path.join(relativepath, os.path.basename(f))

        result.append(OrderedDict([
            ('relativepath', relativepath),
            ('type', 'run-output'),
            ('actions', files[f]),
            ('mimetypes', mimetypes.guess_type(f)[0]),
            ('content', open(f).read(512)),

            ('sha256', compute_sha256(f)),