# Path: appAux.py
# def outputcolum(data):
#     # Calculate terminal size
#     maxStrLength = getTerminalWidth()
#     if settings.rawOutput or stdout_redirect(): maxStrLength = 1000
# 
#     # Calculate number of fields and maxStrLengthField
#     # todo: grab max size per field to do a more intelligent distribution of available term realestate
#     num_fields = len(data[len(data)-1][1])
#     maxStrLengthField = maxStrLength / num_fields
# 
#     # Truncate fields
#     # todo: There has to be a better approach to this
#     for ii in xrange(0, len(data)):
#         tmpList = []
#         for i in xrange(0, len(data[ii][1])):
#             tmpList.append(str(data[ii][1][i])[:maxStrLengthField] + (str(data[ii][1][i])[maxStrLengthField:] and '...'))
#         t1 = []
#         t1.append(data[ii][0])
#         t1.append(tuple(tmpList))
#         data[ii] = t1
#         data[ii][1] = tuple(tmpList)
#     widths = [max(map(len,map(str, col))) for col in zip(*[x[1] for x in data])]
#     for row in data:
#         if settings.rawOutput or stdout_redirect():
#             print ("  ".join((str(val).ljust(width) for val, width in zip(row[1], widths))))
#         else: print colored("  ".join((str(val).ljust(width) for val, width in zip(row[1], widths))), row[0])
#     return data
# 
# def update_progress(progress, text="Progress", logmessage=False):
#     if not stdout_redirect():
#         oh = sys.stdout
#     else:
#         oh = sys.stderr
# 
#     barLength = 25  # Modify this to change the length of the progress bar
#     status = ""
#     if isinstance(progress, int):
#         progress = float(progress)
#     if not isinstance(progress, float):
#         progress = 0
#         status = "error: progress var must be float\r\n"
#     if progress < 0:
#         progress = 0
#         status = "Halt...\r\n"
#     if progress > 1:
#         status = "Progress out of bounds...\r\n"
#     if progress == 1:
#         progress = 1
#         oh.write('\x1b[2K\r')
#         oh.flush()
#         return ""
#     block = int(round(barLength * progress))
#     if logmessage:
#         text = "{0}: [{1}] {2}% {3}\033[K".format(text, "#" * block + "-" * (barLength - block), round(progress * 100, 2), status)
#         return text
#     else:
#         text = "\r{0}: [{1}] {2}% {3}\033[K".format(text, "#" * block + "-" * (barLength - block), round(progress * 100, 2), status)
#         oh.write(text)
#         oh.flush()
# 
# def update_spinner(text="Working "):
#     if not stdout_redirect():
#         oh = sys.stdout
#     else:
#         oh = sys.stderr
# 
#     oh.write(text + spinner.next())
#     oh.flush()
# 
#     # Clear spinner:
#     oh.write('\r')
#     oh.write(' ' * (len(text) + 3))
#     oh.write('\r')


import settings
import logging
import sqlite3
import os
import re
import sys, traceback
from appAux import outputcolum, update_progress, update_spinner
from contextlib import closing
        return (hostName)


    def GetEntryRowID(self, RowID):
        with closing(self.conn.cursor()) as c:
            data = self.Query("SELECT HostName, LastModified, LastUpdate, FilePath, FileName, Size, ExecFlag FROM \
            Entries INNER JOIN Hosts ON Entries.HostID = Hosts.HostID WHERE RowID = '%s'" % RowID)
            results = []
            return ' '.join(map(str, data[0]))


    def PrintEntryRowID(self, RowID):
        with closing(self.conn.cursor()) as c:
            data = self.Query("SELECT HostName, LastModified, LastUpdate, FilePath, FileName, Size, ExecFlag FROM \
            Entries INNER JOIN Hosts ON Entries.HostID = Hosts.HostID WHERE RowID = '%s'" % RowID)
            results = []
            for row in data:
                results.append(('white', row))
        outputcolum(results)


    def PrintEntryRowIDList(self, rowIDList):
        with closing(self.conn.cursor()) as c:
            data = self.Query("SELECT HostName, LastModified, LastUpdate, FilePath, FileName, Size, ExecFlag FROM \
            Entries INNER JOIN Hosts ON Entries.HostID = Hosts.HostID WHERE RowID IN (%s)" % ",".join(rowIDList))
            if len(data) > 0:
                results = []
                results.append(('cyan', list(data[0]._fields)))
                for row in data:
                    results.append(('white', row))

# Path: appAux.py
# def outputcolum(data):
#     # Calculate terminal size
#     maxStrLength = getTerminalWidth()
#     if settings.rawOutput or stdout_redirect(): maxStrLength = 1000
# 
#     # Calculate number of fields and maxStrLengthField
#     # todo: grab max size per field to do a more intelligent distribution of available term realestate
#     num_fields = len(data[len(data)-1][1])
#     maxStrLengthField = maxStrLength / num_fields
# 
#     # Truncate fields
#     # todo: There has to be a better approach to this
#     for ii in xrange(0, len(data)):
#         tmpList = []
#         for i in xrange(0, len(data[ii][1])):
#             tmpList.append(str(data[ii][1][i])[:maxStrLengthField] + (str(data[ii][1][i])[maxStrLengthField:] and '...'))
#         t1 = []
#         t1.append(data[ii][0])
#         t1.append(tuple(tmpList))
#         data[ii] = t1
#         data[ii][1] = tuple(tmpList)
#     widths = [max(map(len,map(str, col))) for col in zip(*[x[1] for x in data])]
#     for row in data:
#         if settings.rawOutput or stdout_redirect():
#             print ("  ".join((str(val).ljust(width) for val, width in zip(row[1], widths))))
#         else: print colored("  ".join((str(val).ljust(width) for val, width in zip(row[1], widths))), row[0])
#     return data
# 
# def update_progress(progress, text="Progress", logmessage=False):
#     if not stdout_redirect():
#         oh = sys.stdout
#     else:
#         oh = sys.stderr
# 
#     barLength = 25  # Modify this to change the length of the progress bar
#     status = ""
#     if isinstance(progress, int):
#         progress = float(progress)
#     if not isinstance(progress, float):
#         progress = 0
#         status = "error: progress var must be float\r\n"
#     if progress < 0:
#         progress = 0
#         status = "Halt...\r\n"
#     if progress > 1:
#         status = "Progress out of bounds...\r\n"
#     if progress == 1:
#         progress = 1
#         oh.write('\x1b[2K\r')
#         oh.flush()
#         return ""
#     block = int(round(barLength * progress))
#     if logmessage:
#         text = "{0}: [{1}] {2}% {3}\033[K".format(text, "#" * block + "-" * (barLength - block), round(progress * 100, 2), status)
#         return text
#     else:
#         text = "\r{0}: [{1}] {2}% {3}\033[K".format(text, "#" * block + "-" * (barLength - block), round(progress * 100, 2), status)
#         oh.write(text)
#         oh.flush()
# 
# def update_spinner(text="Working "):
#     if not stdout_redirect():
#         oh = sys.stdout
#     else:
#         oh = sys.stderr
# 
#     oh.write(text + spinner.next())
#     oh.flush()
# 
#     # Clear spinner:
#     oh.write('\r')
#     oh.write(' ' * (len(text) + 3))
#     oh.write('\r')


# Path: appDB.py
import settings
import logging
import sqlite3
import os
import re
import sys, traceback
from appAux import outputcolum, update_progress, update_spinner
from contextlib import closing

        return (hostName)


    def GetEntryRowID(self, RowID):
        with closing(self.conn.cursor()) as c:
            data = self.Query("SELECT HostName, LastModified, LastUpdate, FilePath, FileName, Size, ExecFlag FROM \
            Entries INNER JOIN Hosts ON Entries.HostID = Hosts.HostID WHERE RowID = '%s'" % RowID)
            results = []
            return ' '.join(map(str, data[0]))


    def PrintEntryRowID(self, RowID):
        with closing(self.conn.cursor()) as c:
            data = self.Query("SELECT HostName, LastModified, LastUpdate, FilePath, FileName, Size, ExecFlag FROM \
            Entries INNER JOIN Hosts ON Entries.HostID = Hosts.HostID WHERE RowID = '%s'" % RowID)
            results = []
            for row in data:
                results.append(('white', row))
        outputcolum(results)


    def PrintEntryRowIDList(self, rowIDList):
        with closing(self.conn.cursor()) as c:
            data = self.Query("SELECT HostName, LastModified, LastUpdate, FilePath, FileName, Size, ExecFlag FROM \
            Entries INNER JOIN Hosts ON Entries.HostID = Hosts.HostID WHERE RowID IN (%s)" % ",".join(rowIDList))
            if len(data) > 0:
                results = []
                results.append(('cyan', list(data[0]._fields)))
                for row in data:
                    results.append(('white', row))

                outputcolum(results)