From 2aa8cdbaa045942b6e2f7255fd07677f1a2f8dd0 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 23 Mar 2020 23:55:57 -0500 Subject: [PATCH] corrected utils formatting and removed defunct utils --- src/httpapi/onionrsitesapi/__init__.py | 1 - src/utils/cachedconfig/__init__.py | 17 ---------------- src/utils/definewait.py | 28 -------------------------- src/utils/getconsolewidth.py | 23 ++++++++++----------- src/utils/gethostname.py | 15 +++++++------- src/utils/safezip.py | 7 ------- tests/runtime-result.txt | 2 +- 7 files changed, 20 insertions(+), 73 deletions(-) delete mode 100644 src/utils/cachedconfig/__init__.py delete mode 100644 src/utils/definewait.py delete mode 100644 src/utils/safezip.py diff --git a/src/httpapi/onionrsitesapi/__init__.py b/src/httpapi/onionrsitesapi/__init__.py index f369c475..0cfe0fec 100644 --- a/src/httpapi/onionrsitesapi/__init__.py +++ b/src/httpapi/onionrsitesapi/__init__.py @@ -28,7 +28,6 @@ from flask import Blueprint, Response, request, abort from onionrblocks import onionrblockapi import onionrexceptions from onionrutils import stringvalidators -from utils import safezip from onionrutils import mnemonickeys from . import sitefiles diff --git a/src/utils/cachedconfig/__init__.py b/src/utils/cachedconfig/__init__.py deleted file mode 100644 index 5a7110bc..00000000 --- a/src/utils/cachedconfig/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -from onionrutils import localcommand -import config -config.reload() -running_detected = False # if we know the api server is running -first_get = True - -def config_get(key): - ret_data = False - if running_detected or first_get: - first_get = False - ret_data = localcommand.local_command('/config/get/' + key) - if ret_data == False: - running_detected = False - ret_data = config.get(key) - else: - running_detected = False - return ret_data \ No newline at end of file diff --git a/src/utils/definewait.py b/src/utils/definewait.py deleted file mode 100644 index 0cf2eae6..00000000 --- a/src/utils/definewait.py +++ /dev/null @@ -1,28 +0,0 @@ -''' - Onionr - Private P2P Communication - - Waits for a key to become set in a dictionary, even to None, 0 or empty string -''' -''' - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -''' -import time -def define_wait(dictionary, key, delay: int = 0): - while True: - try: - return dictionary[key] - except KeyError: - pass - if delay > 0: - time.sleep(delay) \ No newline at end of file diff --git a/src/utils/getconsolewidth.py b/src/utils/getconsolewidth.py index 30fbb591..1135e057 100644 --- a/src/utils/getconsolewidth.py +++ b/src/utils/getconsolewidth.py @@ -1,9 +1,9 @@ -''' - Onionr - Private P2P Communication +"""Onionr - Private P2P Communication. - Get the width of the terminal screen -''' -''' +Get the width of the terminal screen +""" +import os +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -16,12 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' -import os -def get_console_width(): - ''' - Returns an integer, the width of the terminal/cmd window - ''' +""" + + +def get_console_width() -> int: + """Return the width of the terminal/cmd window.""" columns = 80 @@ -31,4 +30,4 @@ def get_console_width(): # if it errors, it's probably windows, so default to 80. pass - return columns \ No newline at end of file + return columns diff --git a/src/utils/gethostname.py b/src/utils/gethostname.py index 4a294218..74aee7bc 100644 --- a/src/utils/gethostname.py +++ b/src/utils/gethostname.py @@ -1,9 +1,8 @@ -''' - Onionr - Private P2P Communication +"""Onionr - Private P2P Communication. - Get the node's Tor hostname -''' -''' +Get the node's Tor hostname +""" +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -16,9 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' +""" from . import identifyhome import filepaths + + def get_hostname(): try: with open(identifyhome.identify_home() + '/hs/hostname', 'r') as hostname: @@ -26,4 +27,4 @@ def get_hostname(): except FileNotFoundError: return "Not Generated" except Exception: - return None \ No newline at end of file + return None diff --git a/src/utils/safezip.py b/src/utils/safezip.py deleted file mode 100644 index 8cc87600..00000000 --- a/src/utils/safezip.py +++ /dev/null @@ -1,7 +0,0 @@ -# safe unzip https://stackoverflow.com/a/36583849 -def safe_unzip(zip_file, extractpath='.'): - with zipfile.ZipFile(zip_file, 'r') as zf: - for member in zf.infolist(): - abspath = os.path.abspath(os.path.join(extractpath, member.filename)) - if abspath.startswith(os.path.abspath(extractpath)): - zf.extract(member, extractpath) diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt index dbc2696d..546af05e 100644 --- a/tests/runtime-result.txt +++ b/tests/runtime-result.txt @@ -1 +1 @@ -1584769913 \ No newline at end of file +1585025509 \ No newline at end of file