Skip to content
This repository has been archived by the owner on Apr 8, 2021. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
segunlee committed Apr 25, 2020
1 parent 7fa505a commit 99c4ede
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
files/*
__pycache__
build
dist/
114 changes: 114 additions & 0 deletions .vscode/.ropeproject/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# The default ``config.py``
# flake8: noqa


def set_prefs(prefs):
"""This function is called before opening the project"""

# Specify which files and folders to ignore in the project.
# Changes to ignored resources are not added to the history and
# VCSs. Also they are not returned in `Project.get_files()`.
# Note that ``?`` and ``*`` match all characters but slashes.
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
# '.svn': matches 'pkg/.svn' and all of its children
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject',
'.hg', '.svn', '_svn', '.git', '.tox']

# Specifies which files should be considered python files. It is
# useful when you have scripts inside your project. Only files
# ending with ``.py`` are considered to be python files by
# default.
# prefs['python_files'] = ['*.py']

# Custom source folders: By default rope searches the project
# for finding source folders (folders that should be searched
# for finding modules). You can add paths to that list. Note
# that rope guesses project source folders correctly most of the
# time; use this if you have any problems.
# The folders should be relative to project root and use '/' for
# separating folders regardless of the platform rope is running on.
# 'src/my_source_folder' for instance.
# prefs.add('source_folders', 'src')

# You can extend python path for looking up modules
# prefs.add('python_path', '~/python/')

# Should rope save object information or not.
prefs['save_objectdb'] = True
prefs['compress_objectdb'] = False

# If `True`, rope analyzes each module when it is being saved.
prefs['automatic_soa'] = True
# The depth of calls to follow in static object analysis
prefs['soa_followed_calls'] = 0

# If `False` when running modules or unit tests "dynamic object
# analysis" is turned off. This makes them much faster.
prefs['perform_doa'] = True

# Rope can check the validity of its object DB when running.
prefs['validate_objectdb'] = True

# How many undos to hold?
prefs['max_history_items'] = 32

# Shows whether to save history across sessions.
prefs['save_history'] = True
prefs['compress_history'] = False

# Set the number spaces used for indenting. According to
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
# unit-tests use 4 spaces it is more reliable, too.
prefs['indent_size'] = 4

# Builtin and c-extension modules that are allowed to be imported
# and inspected by rope.
prefs['extension_modules'] = []

# Add all standard c-extensions to extension_modules list.
prefs['import_dynload_stdmods'] = True

# If `True` modules with syntax errors are considered to be empty.
# The default value is `False`; When `False` syntax errors raise
# `rope.base.exceptions.ModuleSyntaxError` exception.
prefs['ignore_syntax_errors'] = False

# If `True`, rope ignores unresolvable imports. Otherwise, they
# appear in the importing namespace.
prefs['ignore_bad_imports'] = False

# If `True`, rope will insert new module imports as
# `from <package> import <module>` by default.
prefs['prefer_module_from_imports'] = False

# If `True`, rope will transform a comma list of imports into
# multiple separate import statements when organizing
# imports.
prefs['split_imports'] = False

# If `True`, rope will remove all top-level import statements and
# reinsert them at the top of the module when making changes.
prefs['pull_imports_to_top'] = True

# If `True`, rope will sort imports alphabetically by module name instead
# of alphabetically by import statement, with from imports after normal
# imports.
prefs['sort_imports_alphabetically'] = False

# Location of implementation of
# rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general
# case, you don't have to change this value, unless you're an rope expert.
# Change this value to inject you own implementations of interfaces
# listed in module rope.base.oi.type_hinting.providers.interfaces
# For example, you can add you own providers for Django Models, or disable
# the search type-hinting in a class hierarchy, etc.
prefs['type_hinting_factory'] = (
'rope.base.oi.type_hinting.factory.default_type_hinting_factory')


def project_opened(project):
"""This function is called after opening the project"""
# Do whatever you like here!
Binary file added icon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions lightcomics.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ROOT": "/home/ubuntu/apps/LightProvider/files",
"PORT": 8909,
"ROOT": "C:\\Users\\LEESEGUN\\Documents\\LightProvider\\dist",
"PORT": 12370,
"HOST": "0.0.0.0",
"PASSWORD": ""
}
109 changes: 82 additions & 27 deletions lightcomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
from io import StringIO
from urllib.parse import *
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import threading
from urllib.request import urlopen
import re
import socket



__version__ = (1, 0, 0)
Expand All @@ -41,25 +45,30 @@


CONF_ROOT_PATH = ""
CONF_SERVER_PORT = 8906
CONF_SERVER_PORT = 12370
CONF_PASSWORD = ""

if os.name == 'nt':
# Windows
CONF_ROOT_PATH = "c:\\"
CONF_SERVER_PORT = 8906
CONF_SERVER_PORT = 12370
CONF_PASSWORD = ""
else:
# Linux Base OS
CONF = json.loads(open('./lightcomics.json', 'r').read())
CONF_SERVER_PORT = CONF['ROOT']
CONF_PASSWORD = CONF['PASSWORD']
if not os.path.exists(CONF_ROOT_PATH):
raise Exception("No Root Directory!!!!")



# 앱 선언
app = flask.Flask(__name__)

# 권한 체크
def check_auth(username, password):
return username == 'LightComics' and password == CONF['PASSWORD']
app.logger.info("check auth, recevie password: " + password + " / save password: " + CONF_PASSWORD)
return username == 'LightComics' and password == CONF_PASSWORD

# 권한 오류 반환
def authenticate():
Expand Down Expand Up @@ -330,7 +339,7 @@ def getSizeOf(path):
def root():
"""
리스팅
localhost:8909/
localhost:12370/
"""
app.logger.info("@app.route('/')")

Expand All @@ -342,7 +351,7 @@ def root():
def listing(req_path):
"""
리스팅
localhost:8909/dir/
localhost:12370/dir/
"""
app.logger.info("@app.route('/<path:req_path>/')")

Expand All @@ -363,7 +372,7 @@ def listing(req_path):
def load_image_model(archive, archive_ext):
"""
압축파일 내부 이미지 정보
localhost:8909/sample.zip/
localhost:12370/sample.zip/
"""
app.logger.info("@app.route('/<string:archive>.<string:archive_ext>/')")

Expand All @@ -375,7 +384,7 @@ def load_image_model(archive, archive_ext):
def load_image_model2(req_path, archive, archive_ext):
"""
압축파일 내부 이미지 정보
localhost:8909/dir/sglee/sample.zip/
localhost:12370/dir/sglee/sample.zip/
"""
app.logger.info("@app.route('/<path:req_path>/<string:archive>.<string:archive_ext>/')")

Expand Down Expand Up @@ -412,8 +421,8 @@ def load_image_model2(req_path, archive, archive_ext):
def load_image_data(archive, archive_ext, img_path):
"""
압축파일 내부 이미지 데이터 반환
localhost:8909/sample.zip/img1.jpg
localhost:8909/sample.zip/test/img1.jpg
localhost:12370/sample.zip/img1.jpg
localhost:12370/sample.zip/test/img1.jpg
"""
app.logger.info("@app.route('/<string:archive>.<string:archive_ext>/<path:img_path>')")

Expand All @@ -424,8 +433,8 @@ def load_image_data(archive, archive_ext, img_path):
def load_image_data2(req_path, archive, archive_ext, img_path):
"""
압축파일 내부 이미지 데이터 반환
localhost:8909/dir/sglee/sample.zip/img1.jpg
localhost:8909/dir/sglee/sample.zip/test/img1.jpg
localhost:12370/dir/sglee/sample.zip/img1.jpg
localhost:12370/dir/sglee/sample.zip/test/img1.jpg
"""
app.logger.info("@app.route('/<path:req_path>/<string:archive>.<string:archive_ext>/<path:img_path>')")

Expand Down Expand Up @@ -457,7 +466,7 @@ def load_image_data2(req_path, archive, archive_ext, img_path):
def get_identifier(req_path):
"""
해당하는 경로의 파일 identifier를 반환한다.
localhost:8909/dir/hello.zip
localhost:12370/dir/hello.zip
"""
app.logger.info("@app.route('/id/<path:req_path>')")

Expand All @@ -478,27 +487,30 @@ def get_identifier(req_path):

# UI 구현

def okClick():
def onClickServerState():
global server_run
global server_state_label
global server_on_off_button
global server_threading

if server_run == True:
tk.messagebox.showinfo("알림", "서버 정지는 정상적으로 동작되지 않습니다.\n프로그램 종료후 재시작 해야 합니다.")
return
shutdown_server()
server_state_label['text'] = "Server: Stopped"
server_on_off_button['text'] = " Start "
server_state_label['text'] = "서버: 정지됨"
server_on_off_button['text'] = " 가동 "
else:
updateServerPort()
updatePassword()
server_threading.start()
server_state_label['text'] = "Server: Started"
server_on_off_button['text'] = " Stop "
server_state_label['text'] = "서버: 가동중"
server_on_off_button['text'] = " 정지 "

server_run = not server_run

def start_server():
app.logger.info("Server Start: " + str(CONF_SERVER_PORT))
app.run(host="0.0.0.0", port=CONF_SERVER_PORT)
app.run(host=local_ip.get(), port=CONF_SERVER_PORT)

def shutdown_server():
# TODO: 서버 어떻게 멈추냐.. 안되네
Expand All @@ -516,27 +528,56 @@ def getPublicIp():

def updateServerIP():
app.logger.info(getPublicIp())
local_ip.set(socket.gethostbyname(socket.gethostname()))
public_ip.set(getPublicIp())

def updateServerPort():
global CONF_SERVER_PORT
CONF_SERVER_PORT = int(server_port.get())
app.logger.info(CONF_SERVER_PORT)

def updatePassword():
global CONF_PASSWORD
CONF_PASSWORD = password_var.get()
app.logger.info(CONF_PASSWORD)

def updateRootPath():
global CONF_ROOT_PATH
folder_selected = filedialog.askdirectory()
CONF_ROOT_PATH = folder_selected
root_path_var.set(CONF_ROOT_PATH)
app.logger.info(CONF_ROOT_PATH)

def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)

server_run = False
server_threading = threading.Thread(target=start_server)


window = tk.Tk()
server_state_label = tk.Label(window, text="Server: Stopped", width=15, anchor="w", padx=10, pady=5)
server_on_off_button = tk.Button(window, text=" Start ", command=okClick, width=20)
server_state_label = tk.Label(window, text="서버: 중지됨", width=15, anchor="w", padx=10, pady=5)
server_on_off_button = tk.Button(window, text=" 가동 ", command=onClickServerState, width=20)
change_root_path_button = tk.Button(window, text=" 변경 ", command=updateRootPath, width=20)

public_ip = tk.StringVar()
local_ip = tk.StringVar()
server_port = tk.StringVar()
server_port.set(CONF_SERVER_PORT)
password_var = tk.StringVar()
password_var.set(CONF_PASSWORD)
root_path_var = tk.StringVar()
root_path_var.set(CONF_ROOT_PATH)

local_ip_textbox = tk.Entry(window, width=20, textvariable=local_ip, state='readonly')
public_ip_textbox = tk.Entry(window, width=20, textvariable=public_ip, state='readonly')
server_port_textbox = tk.Entry(window, width=20, textvariable=server_port)

password_textbox = tk.Entry(window, width=20, textvariable=password_var)
root_path_textbox = tk.Entry(window, width=20, textvariable=root_path_var, state='readonly')

def applicationUI():
global window
Expand All @@ -547,22 +588,36 @@ def applicationUI():
window.geometry("300x200")
window.title("Light Provider")
window.resizable(False, False)

window.iconbitmap(default=resource_path('icon.ico'))
reuse_label = tk.Label(window, text=" ", width=15, anchor="w")
reuse_label.grid(row=0, column=0)

server_state_label.grid(row=1, column=0)
server_on_off_button.grid(row=1, column=1)

reuse_label = tk.Label(window, text="Server IP", width=15, anchor="w")
reuse_label = tk.Label(window, text="Local IP", width=15, anchor="w")
reuse_label.grid(row=2, column=0)
public_ip_textbox.grid(row=2, column=1)
local_ip_textbox.grid(row=2, column=1)

reuse_label = tk.Label(window, text="Server Port", width=15, anchor="w")
reuse_label = tk.Label(window, text="Remote IP", width=15, anchor="w")
reuse_label.grid(row=3, column=0)
server_port_textbox.grid(row=3, column=1)
public_ip_textbox.grid(row=3, column=1)

reuse_label = tk.Label(window, text="서버 Port", width=15, anchor="w")
reuse_label.grid(row=4, column=0)
server_port_textbox.grid(row=4, column=1)

reuse_label = tk.Label(window, text="비밀번호", width=15, anchor="w")
reuse_label.grid(row=5, column=0)
password_textbox.grid(row=5, column=1)

reuse_label = tk.Label(window, text="공유 폴더", width=15, anchor="w")
reuse_label.grid(row=6, column=0)
root_path_textbox.grid(row=6, column=1)

reuse_label = tk.Label(window, text="폴더 변경", width=15, anchor="w")
reuse_label.grid(row=7, column=0)
change_root_path_button.grid(row=7, column=1)


updateServerIP()
Expand Down
Loading

0 comments on commit 99c4ede

Please sign in to comment.