diff --git a/filesystem.py b/filesystem.py index fba69dd..2b921ac 100644 --- a/filesystem.py +++ b/filesystem.py @@ -1,16 +1,43 @@ # -*- coding: utf-8 -*- from genericpath import isfile import os -from os.path import join, basename, splitext, isdir, dirname +from os.path import join, basename, splitext, isdir, dirname, getmtime, getsize, sep from action import View import string +import time +def size_conversion(size): + K = 1000 + + if size > K: + KB = str(size / K) + "KB" + return KB + + elif size > pow(K,2): + MB = str(size / pow(K,2)) + "MB" + return MB + + elif size > pow(K,3): + GB = str(size / pow(K,3)) + "GB" + return GB + + elif size > pow(K,4): + TB = str(size / pow(K,4)) + "TB" + return TB + + elif size < K: + return str(size) + "B" + else: + return "Too Large" + class Node(object): def __init__(self, root, path): - splitetPath = string.split(path,"/") - self.path = os.path.sep.join(splitetPath) + splitedPath = string.split(path,"/") + self.path = sep.join(splitedPath) self.root = root + self.size = size_conversion(getsize(os.path.join(root, path))) + self.date = time.ctime(getmtime(os.path.join(root, path))) self._basename = basename(self.path) def __unicode__(self): @@ -23,6 +50,7 @@ def apply_action(self, action_class): action = action_class(self) return action.apply() + class File(Node): avaliable_actions = [View, ] def __unicode__(self): @@ -39,6 +67,7 @@ def name(self): def get_path(self): return dirname(self.path) + class Folder(Node): def __init__(self, root, path): diff --git a/manager.py b/manager.py index 48e7fdc..3d82439 100644 --- a/manager.py +++ b/manager.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- -import os -from flask import Flask, render_template, redirect, request -from filesystem import Folder, File -from action import * -from flask import request from os import error +from flask import redirect +from flask import request + +from action import * +from filesystem import Folder, File + app = Flask(__name__) app.config.update( DEBUG=True, @@ -48,4 +49,4 @@ def create_directory(path = "/"): if __name__ == '__main__': - app.run(host="0.0.0.0") + app.run(host="127.0.0.1", port=8080) # for local testing diff --git a/templates/folder.html b/templates/folder.html index 6f0583d..f15cd5c 100644 --- a/templates/folder.html +++ b/templates/folder.html @@ -1,44 +1,75 @@ {% extends "index.html" %} - {% block content %} -