munyal-client/misc.py

55 lines
1.4 KiB
Python
Raw Normal View History

2019-08-10 01:44:09 +00:00
import base64
import os
import pickle
import sys
from tkinter import Button, Label, Toplevel
2020-12-08 20:45:42 +00:00
from requests import get
from requests.exceptions import ConnectionError
2019-08-10 01:44:09 +00:00
from tcping import Ping
def check_network(ip, port):
2020-12-08 20:45:42 +00:00
try:
req = get(f"{ip}").status_code
return req in range(200, 300)
except ConnectionError:
return False
# ping = Ping(ip, port, 20)
# ping.ping(1)
# return ping.result.rows[0].successed == 1
2019-08-10 01:44:09 +00:00
def get_os():
if sys.platform in ["linux", "windows"]:
return sys.platform
raise Exception("OS not supported")
def alert(window, message, title="Munyal"):
child = Toplevel(window)
child.title(title)
label = Label(child, text=message)
button = Button(child, text="Aceptar", command=child.destroy)
label.pack()
button.pack()
2020-12-08 20:45:42 +00:00
def flatten_dirs(content, path="", action=""):
output = []
for item in content:
if item["is_file"]:
item["name"] = os.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"]),
action=action))
else:
item["name"] = os.path.join(path, item["name"])
output.append(item)
return output