# Path: reggata/user_config.py
# class UserConfig(object):
#     '''
#         This class is an interface for reggata.conf configuration file.
#     It is a singleton class.
#     '''
#     _instance = None
#     _props = None
# 
#     def __new__(cls, *args, **kwargs):
#         if not cls._instance:
#             cls._instance = super(UserConfig, cls).__new__(cls, *args, **kwargs)
# 
#             cls._props = Properties()
#             if not os.path.exists(consts.USER_CONFIG_DIR):
#                 os.makedirs(consts.USER_CONFIG_DIR)
# 
#             if not os.path.exists(consts.USER_CONFIG_FILE):
#                 with codecs.open(consts.USER_CONFIG_FILE, "w", "utf-8") as f:
#                     f.write(reggata_default_conf.reggataDefaultConf)
# 
#             with codecs.open(consts.USER_CONFIG_FILE, "r", "utf-8") as f:
#                 cls._props.load(f)
# 
#         return cls._instance
# 
#     def __init__(self):
#         pass
# 
#     def __getitem__(self, key):
#         '''
#             This is an operation []. It returns a value of parameter with given key.
#         If there is no such key, an exception is raised.
#         '''
#         return self._props[key]
# 
#     def get(self, key, default=None):
#         '''
#             Returns value of parameter with given key. If there are no such key in
#         configuration, then a default value is returned.
#         '''
#         return self._props.get(key, default)
# 
#     def store(self, key, value):
#         self._props[key] = str(value)
#         with codecs.open(consts.USER_CONFIG_FILE, 'w', "utf-8") as f:
#             self._props.store(f)
# 
#     def storeAll(self, d):
#         if type(d) != dict:
#             raise TypeError("This is not a dict instance.")
#         for key in d.keys():
#             self._props[key] = str(d[key])
#         with codecs.open(consts.USER_CONFIG_FILE, 'w', "utf-8") as f:
#             self._props.store(f)
# 
#     def refresh(self):
#         with codecs.open(consts.USER_CONFIG_FILE, 'r', "utf-8") as f:
#             self._props.load(f)
# 
# Path: reggata/data/operations.py
# class ItemOperations:
#     def addTags(session, item, tagNames, userLogin):
#     def removeTags(session, item, tagNames):
#     def removeFields(session, item, fieldNames):
#     def addOrUpdateFields(session, item, nameValuePairs, userLogin):
#     def addUntrackedFile(session, item, repoBasePath, srcAbsPath, dstRelPath, userLogin):
#     def addStoredFile(session, item, repoBasePath, dataRef):
#     def removeFile(session, item):
#     def moveFile(session, item, repoBasePath, newDstRelPath):
#     def renameFile(session, item, newFileName):
#     def addThumbnail(session, item):
#     def clearThumbnails(session, item):
# 
# Path: reggata/helpers.py
# def to_db_format(path):
#     '''
#         Converts slashes of the given path from current OS format to UNIX format.
#     Note: all paths in reggata database are stored in UNIX format.
#     '''
#     if platform.system() == "Windows":
#         return path.replace(os.sep, "/")
#     else:
#         # Linux and MacOS use UNIX format
#         return path


from sqlalchemy.orm import contains_eager, joinedload_all
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.exc import ResourceClosedError
from reggata.user_config import UserConfig
from reggata.data import operations
from reggata.helpers import to_db_format
import shutil
import datetime
import logging
import os.path
import reggata.errors as err
import reggata.helpers as hlp
import reggata.consts as consts
import reggata.data.db_schema as db
        self.path = path
        self.status = status
        self.type = objType
        self.tags = []
        self.fields = []
        self.itemIds = []

    @property
    def fileBaseName(self):
        return os.path.basename(self.path)

    def __str__(self):
        return self.fileBaseName()

    def isDir(self):
        return self.type == FileInfo.DIR


# TODO: Write a test for this command
class GetFileInfoCommand(AbstractCommand):
    def __init__(self, relPath):
        self.__relPath = relPath

    def _execute(self, uow):
        self._session = uow.session
        return self.__getFileInfo(self.__relPath)

    def __getFileInfo(self, path):
        try:
            data_ref = self._session.query(db.DataRef)\

# Path: reggata/user_config.py
# class UserConfig(object):
#     '''
#         This class is an interface for reggata.conf configuration file.
#     It is a singleton class.
#     '''
#     _instance = None
#     _props = None
# 
#     def __new__(cls, *args, **kwargs):
#         if not cls._instance:
#             cls._instance = super(UserConfig, cls).__new__(cls, *args, **kwargs)
# 
#             cls._props = Properties()
#             if not os.path.exists(consts.USER_CONFIG_DIR):
#                 os.makedirs(consts.USER_CONFIG_DIR)
# 
#             if not os.path.exists(consts.USER_CONFIG_FILE):
#                 with codecs.open(consts.USER_CONFIG_FILE, "w", "utf-8") as f:
#                     f.write(reggata_default_conf.reggataDefaultConf)
# 
#             with codecs.open(consts.USER_CONFIG_FILE, "r", "utf-8") as f:
#                 cls._props.load(f)
# 
#         return cls._instance
# 
#     def __init__(self):
#         pass
# 
#     def __getitem__(self, key):
#         '''
#             This is an operation []. It returns a value of parameter with given key.
#         If there is no such key, an exception is raised.
#         '''
#         return self._props[key]
# 
#     def get(self, key, default=None):
#         '''
#             Returns value of parameter with given key. If there are no such key in
#         configuration, then a default value is returned.
#         '''
#         return self._props.get(key, default)
# 
#     def store(self, key, value):
#         self._props[key] = str(value)
#         with codecs.open(consts.USER_CONFIG_FILE, 'w', "utf-8") as f:
#             self._props.store(f)
# 
#     def storeAll(self, d):
#         if type(d) != dict:
#             raise TypeError("This is not a dict instance.")
#         for key in d.keys():
#             self._props[key] = str(d[key])
#         with codecs.open(consts.USER_CONFIG_FILE, 'w', "utf-8") as f:
#             self._props.store(f)
# 
#     def refresh(self):
#         with codecs.open(consts.USER_CONFIG_FILE, 'r', "utf-8") as f:
#             self._props.load(f)
# 
# Path: reggata/data/operations.py
# class ItemOperations:
#     def addTags(session, item, tagNames, userLogin):
#     def removeTags(session, item, tagNames):
#     def removeFields(session, item, fieldNames):
#     def addOrUpdateFields(session, item, nameValuePairs, userLogin):
#     def addUntrackedFile(session, item, repoBasePath, srcAbsPath, dstRelPath, userLogin):
#     def addStoredFile(session, item, repoBasePath, dataRef):
#     def removeFile(session, item):
#     def moveFile(session, item, repoBasePath, newDstRelPath):
#     def renameFile(session, item, newFileName):
#     def addThumbnail(session, item):
#     def clearThumbnails(session, item):
# 
# Path: reggata/helpers.py
# def to_db_format(path):
#     '''
#         Converts slashes of the given path from current OS format to UNIX format.
#     Note: all paths in reggata database are stored in UNIX format.
#     '''
#     if platform.system() == "Windows":
#         return path.replace(os.sep, "/")
#     else:
#         # Linux and MacOS use UNIX format
#         return path


# Path: reggata/data/commands.py
from sqlalchemy.orm import contains_eager, joinedload_all
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.exc import ResourceClosedError
from reggata.user_config import UserConfig
from reggata.data import operations
from reggata.helpers import to_db_format
import shutil
import datetime
import logging
import os.path
import reggata.errors as err
import reggata.helpers as hlp
import reggata.consts as consts
import reggata.data.db_schema as db

        self.path = path
        self.status = status
        self.type = objType
        self.tags = []
        self.fields = []
        self.itemIds = []

    @property
    def fileBaseName(self):
        return os.path.basename(self.path)

    def __str__(self):
        return self.fileBaseName()

    def isDir(self):
        return self.type == FileInfo.DIR


# TODO: Write a test for this command
class GetFileInfoCommand(AbstractCommand):
    def __init__(self, relPath):
        self.__relPath = relPath

    def _execute(self, uow):
        self._session = uow.session
        return self.__getFileInfo(self.__relPath)

    def __getFileInfo(self, path):
        try:
            data_ref = self._session.query(db.DataRef)\

                .filter(db.DataRef.url_raw==hlp.to_db_format(path))\