unify the slashes
parent
5667c5e2c8
commit
397d911a5d
11
client.py
11
client.py
|
@ -21,7 +21,9 @@ import websocket
|
||||||
from compare_json import compare_json
|
from compare_json import compare_json
|
||||||
from config import get_config
|
from config import get_config
|
||||||
from dir_to_json import get_json
|
from dir_to_json import get_json
|
||||||
from misc import check_network, flatten_dirs
|
from misc import check_network
|
||||||
|
from misc import flatten_dirs
|
||||||
|
from misc import path_join
|
||||||
from pystray import Icon, Menu
|
from pystray import Icon, Menu
|
||||||
from pystray import MenuItem as Item
|
from pystray import MenuItem as Item
|
||||||
from websocket import WebSocket
|
from websocket import WebSocket
|
||||||
|
@ -126,7 +128,7 @@ class MunyalClient(Icon):
|
||||||
self.stack.pop(0)
|
self.stack.pop(0)
|
||||||
continue
|
continue
|
||||||
if data["is_file"] and data["action"] == "add":
|
if data["is_file"] and data["action"] == "add":
|
||||||
full_path = os.path.join(folder, data["name"])
|
full_path = path_join(folder, data["name"])
|
||||||
data["file"] = base64.b85encode(
|
data["file"] = base64.b85encode(
|
||||||
open(full_path, "rb").read()).decode("ascii")
|
open(full_path, "rb").read()).decode("ascii")
|
||||||
self.ws.send(json.dumps(data))
|
self.ws.send(json.dumps(data))
|
||||||
|
@ -174,7 +176,7 @@ class MunyalClient(Icon):
|
||||||
def downloader(self, data):
|
def downloader(self, data):
|
||||||
name = data["name"]
|
name = data["name"]
|
||||||
self.ignored.append(name)
|
self.ignored.append(name)
|
||||||
full_path = os.path.join(self.config["folder"], name)
|
full_path = path_join(self.config["folder"], name)
|
||||||
if data["is_file"]:
|
if data["is_file"]:
|
||||||
if data["action"] == "add":
|
if data["action"] == "add":
|
||||||
directory = os.path.split(full_path)[0]
|
directory = os.path.split(full_path)[0]
|
||||||
|
@ -205,5 +207,6 @@ if __name__ == '__main__':
|
||||||
client = MunyalClient()
|
client = MunyalClient()
|
||||||
client.start()
|
client.start()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except BaseException:
|
except BaseException as e:
|
||||||
|
print(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
14
config.py
14
config.py
|
@ -11,19 +11,21 @@ from uuid import uuid4
|
||||||
|
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
|
|
||||||
from misc import alert, get_os
|
from misc import alert
|
||||||
|
from misc import get_os
|
||||||
|
from misc import path_join
|
||||||
|
|
||||||
|
|
||||||
def __get_config_folder():
|
def __get_config_folder():
|
||||||
_os = get_os()
|
_os = get_os()
|
||||||
if _os == "linux":
|
if _os == "linux":
|
||||||
folder = os.path.join(os.getenv("HOME"), ".munyal")
|
folder = path_join(os.getenv("HOME"), ".munyal")
|
||||||
else:
|
else:
|
||||||
folder = os.path.join(os.path.expandvars("%APPDATA%"), "Munyal")
|
folder = path_join(os.path.expandvars("%APPDATA%"), "Munyal")
|
||||||
return folder
|
return folder
|
||||||
|
|
||||||
def __get_files_folder():
|
def __get_files_folder():
|
||||||
folder = os.path.join(os.path.expanduser("~"), "Munyal")
|
folder = path_join(os.path.expanduser("~"), "Munyal")
|
||||||
return folder
|
return folder
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
|
@ -37,7 +39,7 @@ def get_config():
|
||||||
|
|
||||||
def __get_config():
|
def __get_config():
|
||||||
folder = __get_config_folder()
|
folder = __get_config_folder()
|
||||||
config_file = os.path.join(folder, "config")
|
config_file = path_join(folder, "config")
|
||||||
if os.path.exists(config_file):
|
if os.path.exists(config_file):
|
||||||
config_bytes = open(config_file, "rb")
|
config_bytes = open(config_file, "rb")
|
||||||
config = pickle.load(config_bytes)
|
config = pickle.load(config_bytes)
|
||||||
|
@ -66,7 +68,7 @@ def _set_config(root, user, password, folder):
|
||||||
folder_config = __get_config_folder()
|
folder_config = __get_config_folder()
|
||||||
path = pathlib.Path(folder_config)
|
path = pathlib.Path(folder_config)
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
with open(os.path.join(folder_config, "config"), "wb") as config_file:
|
with open(path_join(folder_config, "config"), "wb") as config_file:
|
||||||
config_file.write(
|
config_file.write(
|
||||||
pickle.dumps({
|
pickle.dumps({
|
||||||
"login": {
|
"login": {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
from misc import path_join
|
||||||
|
|
||||||
|
|
||||||
def md5sum(filename):
|
def md5sum(filename):
|
||||||
|
@ -24,7 +25,7 @@ def get_json(path):
|
||||||
for item in items:
|
for item in items:
|
||||||
if item[0] != "." and not item.endswith("tmp"):
|
if item[0] != "." and not item.endswith("tmp"):
|
||||||
item_json = {"name": item}
|
item_json = {"name": item}
|
||||||
route = os.path.join(path, item)
|
route = path_join(path, item)
|
||||||
if os.path.isdir(route):
|
if os.path.isdir(route):
|
||||||
item_json["is_file"] = False
|
item_json["is_file"] = False
|
||||||
item_json["content"] = get_json(route)
|
item_json["content"] = get_json(route)
|
||||||
|
|
10
misc.py
10
misc.py
|
@ -40,15 +40,19 @@ def flatten_dirs(content, path="", action=""):
|
||||||
output = []
|
output = []
|
||||||
for item in content:
|
for item in content:
|
||||||
if item["is_file"]:
|
if item["is_file"]:
|
||||||
item["name"] = os.path.join(path, item["name"])
|
item["name"] = path_join(path, item["name"])
|
||||||
output.append(item)
|
output.append(item)
|
||||||
else:
|
else:
|
||||||
if item["content"] and action == "add":
|
if item["content"] and action == "add":
|
||||||
output.extend(
|
output.extend(
|
||||||
flatten_dirs(item["content"],
|
flatten_dirs(item["content"],
|
||||||
os.path.join(path, item["name"]),
|
path_join(path, item["name"]),
|
||||||
action=action))
|
action=action))
|
||||||
else:
|
else:
|
||||||
item["name"] = os.path.join(path, item["name"])
|
item["name"] = path_join(path, item["name"])
|
||||||
output.append(item)
|
output.append(item)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
def path_join(*items):
|
||||||
|
return os.path.join(*items).replace("\\", "/")
|
||||||
|
|
Loading…
Reference in New Issue