Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions filesystem.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand All @@ -39,6 +67,7 @@ def name(self):
def get_path(self):
return dirname(self.path)


class Folder(Node):

def __init__(self, root, path):
Expand Down
13 changes: 7 additions & 6 deletions manager.py
Original file line number Diff line number Diff line change
@@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxtortime why did you remove render_template, would it work without it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used Pycharm and It works fine.
But I don't know why it works fine and Pycharm remove 'render_template'.
I'll find the reason.

from flask import redirect
from flask import request

from action import *
from filesystem import Folder, File

app = Flask(__name__)
app.config.update(
DEBUG=True,
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxtortime could you please at least leave port setting as default. I don't think it's critical to this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll change to default port setting.

97 changes: 64 additions & 33 deletions templates/folder.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,75 @@
{% extends "index.html" %}

{% block content %}
<div class="row">
<div class="span12">
<h1 class="page-header">{{ folder.name }}</h1>
<!-- New Directory Modal -->
<div id ="newDirectory" class="modal fade" role="dialog">
<div class="modal-dialog">
<!--Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4>Making new directory</h4>
</div>
<div class="modal-body">
<form action="{{ url_for('create_directory') }}" method="post" id="mdform">
<label> 디렉토리 이름을 입력하세요
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxtortime Not everybody OK with Korean :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing that thing.
I'll change that line to English soon.

<input type="text" name="new_directory_name">
</label>
<input class='btn btn-primary' type="submit" value="Create directory">
<input id="folder_path" type="hidden" value="{{folder.path}}" name="directory_root">
</form>
</div>
</div>
</div>
</div>
{% if folder.chunks %}
<ul class="breadcrumb">
{% for chunk in folder.chunks() %}
<li>
<a href="/files/{{ chunk.path }}">{{ chunk.chunk }}</a>
<span class="divider">/</span>
</li>
{% endfor %}
</ul>
{% endif %}
<div class="row">
<div class="span6">
<h3 class="page-header">Folders:</h3>
<form action="new_directory" method="post">
<input type="text" name="new_directory_name">
<input type="submit" value="Create directory">
<input type="hidden" value="{{folder.path}}" name="directory_root">
</form>

<ul class="nav nav-tabs nav-stacked">
<div>
{% if folder.chunks %}
<ul class="breadcrumb">
<a href="{{ url_for('index') }}">SetupBox</a>
{% for chunk in folder.chunks() %}
<li>
<a href="/files/{{ chunk.path }}">/ {{ chunk.chunk }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</div>

<div id="folderView" class="col-md-12 col-xs-12" style="padding:0px;">
<table class="table table-bordered table-foldersystem">
<thead>
<tr class="active">
<th>Type</th>
<th>Name</th>
<th>Size</th>
<th>Last modification time</th>
</tr>
</thead>
<tbody>
{% for folder in folder.folders %}
<li><a href="/files/{{ folder.path }}"> <img src="../static/img/folder.png" width="20" alt="icon"> {{ folder.name }}</a></li>
{% if not folder.name == ".git" %}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxtortime I'd prefer keep this explicit

<tr class="folders_row">
<td><img src="{{ url_for('static',filename='img/folder.png') }}" width="20" alt="icon"></td>
<td id="{{ folder.path }}" class="folders">
<a href="/files/{{ folder.path }}">{{ folder.name }}</a>
</td>
<td>{{ folder.size }}</td>
<td>{{ folder.date }}</td>
</tr>
{% endif %}
{% endfor %}
</ul>
</div>
<div class="span6">
<h3 class="page-header">Files:</h3>
<ul class="nav nav-tabs nav-stacked">

{% for file in folder.files %}
<li><a href="/files/{{ file.path }}"> <img src="../static/img/{{ file.extension }}.png" width="20" alt="icon"> {{ file.name }}</a></li>
<tr class="files_row">
<td>
<img src="{{ url_for('static',filename='img/'+ file.extension) }}.png" width="20" alt="icon">
</td>
<td id="{{ file.path }}" class='files'><a href="/files/{{ file.path }}">{{ file.name }}</a></td>
<td>{{ file.size }}</td>
<td>{{ file.date }}</td>
</tr>
{% endfor %}
</ul>
</div>

</tbody>
</table>
</div>
{% endblock %}