Пример #1
0
    def GetPathID(self, path):
        myDB = Storage()

        if myDB.DB_is_new(path) is True:
            return False
        else:
            return myDB.DB_GetPathID(path)
Пример #2
0
    def AddPath(self, path):
        myDB = Storage()

        if os.path.exists(path) is True:
            if myDB.DB_is_new(path) is True:
                myDB.DB_AddNewPath(path)
                return True
            else:
                return False
        else:
            return False
Пример #3
0
def remove_all(yes):
    """Remove all data stored in DB"""
    myDB = Storage()
    if yes is True:
        myDB.DB_RemoveAllPath()
        print("done")
    else:
        message = "Are you sure you want to remove everything? [Y/N]"
        answer = input(message)
        if answer.upper() == "Y":
            myDB.DB_RemoveAllPath()
            print("done")
        else:
            print("Ok, nothing had been removed")
Пример #4
0
def list_all_paths():
    """Print a list for all saved paths in DB"""
    myDB = Storage()
    myPath = Path()
    results = myDB.DB_GetAllPaths()

    table = PrettyTable()
    table.field_names = ["#", "Path"]

    table.align["Path"] = "l"

    for row in results:
        table.add_row([myPath.GetPathID(row['path']), row['path']])

    print(table)
Пример #5
0
    def GetSizes(self, path, count=1, reverse=False):
        result_list = []
        myDB = Storage()

        results = myDB.DB_GetSize(self.GetPathID(path), count, reverse)

        for row in results:
            dt = datetime.datetime.fromtimestamp(row['time_stamp'])

            presentable_time = "{0:02d}-{1:02d}-{2}".format(
               dt.day, dt.month, dt.year
            )

            result_list.append({'time_stamp': presentable_time,
                                'size': row['size']})

        return result_list
Пример #6
0
def remove_path(path, yes):
    """Remove specific Path form DB"""
    myPath = Path()
    myDB = Storage()

    if myDB.DB_is_new(path) is True:
        print("This {0} \nis wrong, it's not available on the DB".format(path))
    else:
        if yes is True:
            myPath.RemovePath(path)
            print("done")
        else:
            message = "Are you sure you want to remove \"" + path + "\"? [Y/N]"
            answer = input(message)
            if answer.upper() == "Y":
                myPath.RemovePath(path)
                print("Done!!!")
            else:
                print("Ok, nothing had been removed")
Пример #7
0
def get_report(path, count):
    """Show a saved information about specific path"""
    myPath = Path()
    myUnit = UniConv()
    myDB = Storage()

    if myDB.DB_is_new(path) is False:
        table = PrettyTable()

        table.field_names = ["#", "Time", "Size", "Path"]

        for count, result in enumerate(myPath.GetSizes(path, count), start=1):
            table.add_row([
                count, result['time_stamp'],
                myUnit.beauty_size(result['size']), path
            ])

        print(table)
    else:
        print("Sorry, The path is not exist !!")
Пример #8
0
 def __init__(self):
     self.myMD = MarkDown()
     self.myDB = Storage()
     self.myUnit = UniConv()
Пример #9
0
class Report:
    def __init__(self):
        self.myMD = MarkDown()
        self.myDB = Storage()
        self.myUnit = UniConv()

    def RP_InsertIndex(self):
        self.myMD.MD_header(1, 'Index')
        self.myMD.MD_text('[toc]', True)
        self.myMD.MD_horizontal_rule()

    def RP_InsertSharedPaths(self):
        self.myMD.MD_header(1, 'Shared Paths')
        rows = self.myDB.DB_GetAllPaths()

        table = []

        for row in rows:
            table.append(self.__RP_MainTable(row['path']))

        self.myMD.MD_table(table)
        self.myMD.MD_horizontal_rule()

    def RP_InsertMoreInormation(self):
        self.myMD.MD_header(1, "More Information for each Path")
        paths = self.myDB.DB_GetAllPaths()

        for path in paths:
            filename = self.__RP_DrawFig(path['path'])
            self.myMD.MD_header(2, path['path'])
            self.myMD.MD_image('', filename, newline=True)

    def __RP_MainTable(self, path):
        myPath = Path()
        sizes = myPath.GetSizes(path, 2, True)

        row = {'ID': myPath.GetPathID(path), 'Path': path}

        for size in sizes:
            row[str(size['time_stamp'])] = self.myUnit.beauty_size(
                size['size'])

        if len(sizes) > 1:
            row['State'] = self.__RP_CompareSizes(sizes[1]['size'],
                                                  sizes[0]['size'])
        else:
            row['State'] = "=="

        return row

    def __RP_CompareSizes(self, old, new):
        if old > new:
            return "Decrease"
        elif old < new:
            return "Increase"
        elif old == new:
            return "The same"

    def __RP_DrawFig(self, path):
        myPath = Path()

        unit = self.myUnit.max_unit(myPath.GetMaxSize(path))

        timeStamp = []
        sizeList = []
        for size in myPath.GetSizes(path, 0):
            timeStamp.append(size['time_stamp'])
            sizeList.append(
                round(self.myUnit.select_size(size['size'], unit), 2))

        plt.title(path)

        plt.plot(timeStamp,
                 sizeList,
                 marker='o',
                 markerfacecolor='blue',
                 markersize=12,
                 color='skyblue',
                 linewidth=4)

        plt.xlabel("Date")
        plt.ylabel("Size " + self.myUnit.get_unit_name(unit))

        plt.grid(True)

        filename = self.myMD.MD_getFoldername() + "_" + str(
            round(time() + random.random() * 10000)) + ".png"
        plt.savefig(os.path.join(self.myMD.MD_getReportpath(), filename),
                    format="png",
                    dpi=300)
        plt.close()

        return filename

    def RP_Commit(self):
        self.myMD.MD_commit()
Пример #10
0
 def GetMaxSize(self, path):
     myDB = Storage()
     return myDB.DB_GetMaxSize(self.GetPathID(path))
Пример #11
0
 def RemovePath(self, path):
     myDB = Storage()
     myDB.DB_RemovePath(self.GetPathID(path))
Пример #12
0
 def __Commit(self, path, totalsize, calculationTime):
     myDB = Storage()
     myDB.DB_AddSize(self.GetPathID(path),
                     round(time.time()),
                     totalsize,
                     calculationTime)