unify the slashes

master
kirbylife 2020-12-08 21:37:51 -06:00
parent 5667c5e2c8
commit 397d911a5d
4 changed files with 24 additions and 14 deletions

View File

@ -21,7 +21,9 @@ import websocket
from compare_json import compare_json
from config import get_config
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 MenuItem as Item
from websocket import WebSocket
@ -126,7 +128,7 @@ class MunyalClient(Icon):
self.stack.pop(0)
continue
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(
open(full_path, "rb").read()).decode("ascii")
self.ws.send(json.dumps(data))
@ -174,7 +176,7 @@ class MunyalClient(Icon):
def downloader(self, data):
name = data["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["action"] == "add":
directory = os.path.split(full_path)[0]
@ -205,5 +207,6 @@ if __name__ == '__main__':
client = MunyalClient()
client.start()
sys.exit(0)
except BaseException:
except BaseException as e:
print(e)
sys.exit(1)

View File

@ -11,19 +11,21 @@ from uuid import uuid4
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():
_os = get_os()
if _os == "linux":
folder = os.path.join(os.getenv("HOME"), ".munyal")
folder = path_join(os.getenv("HOME"), ".munyal")
else:
folder = os.path.join(os.path.expandvars("%APPDATA%"), "Munyal")
folder = path_join(os.path.expandvars("%APPDATA%"), "Munyal")
return folder
def __get_files_folder():
folder = os.path.join(os.path.expanduser("~"), "Munyal")
folder = path_join(os.path.expanduser("~"), "Munyal")
return folder
def get_config():
@ -37,7 +39,7 @@ def get_config():
def __get_config():
folder = __get_config_folder()
config_file = os.path.join(folder, "config")
config_file = path_join(folder, "config")
if os.path.exists(config_file):
config_bytes = open(config_file, "rb")
config = pickle.load(config_bytes)
@ -66,7 +68,7 @@ def _set_config(root, user, password, folder):
folder_config = __get_config_folder()
path = pathlib.Path(folder_config)
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(
pickle.dumps({
"login": {

View File

@ -4,6 +4,7 @@
import json
import os
from hashlib import md5
from misc import path_join
def md5sum(filename):
@ -24,7 +25,7 @@ def get_json(path):
for item in items:
if item[0] != "." and not item.endswith("tmp"):
item_json = {"name": item}
route = os.path.join(path, item)
route = path_join(path, item)
if os.path.isdir(route):
item_json["is_file"] = False
item_json["content"] = get_json(route)

10
misc.py
View File

@ -40,15 +40,19 @@ def flatten_dirs(content, path="", action=""):
output = []
for item in content:
if item["is_file"]:
item["name"] = os.path.join(path, item["name"])
item["name"] = path_join(path, item["name"])
output.append(item)
else:
if item["content"] and action == "add":
output.extend(
flatten_dirs(item["content"],
os.path.join(path, item["name"]),
path_join(path, item["name"]),
action=action))
else:
item["name"] = os.path.join(path, item["name"])
item["name"] = path_join(path, item["name"])
output.append(item)
return output
def path_join(*items):
return os.path.join(*items).replace("\\", "/")