Changed to using argparse

pull/122/head
aristocratos 2020-09-12 14:59:04 +02:00
parent a99a57c733
commit f19d883532
1 changed files with 17 additions and 18 deletions

View File

@ -17,9 +17,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os, sys, threading, signal, re, subprocess, logging, logging.handlers import os, sys, threading, signal, re, subprocess, logging, logging.handlers, argparse
import urllib.request import urllib.request
import argparse
from time import time, sleep, strftime, localtime from time import time, sleep, strftime, localtime
from datetime import timedelta from datetime import timedelta
from _thread import interrupt_main from _thread import interrupt_main
@ -60,28 +59,33 @@ if errors:
VERSION: str = "1.0.29" VERSION: str = "1.0.29"
#? Argument parser -------------------------------------------------------------------------------> #? Argument parser ------------------------------------------------------------------------------->
args= argparse.ArgumentParser() args = argparse.ArgumentParser()
args.add_argument("-f" , "--full" ,action="store_true" ,help ="Start in full mode showing all boxes [default]") args.add_argument("-f" , "--full" ,action="store_true" ,help ="Start in full mode showing all boxes [default]")
args.add_argument("-p" , "--proc" ,action="store_true" ,help ="Start in minimal mode without memory and net boxes") args.add_argument("-p" , "--proc" ,action="store_true" ,help ="Start in minimal mode without memory and net boxes")
args.add_argument("-s" , "--stat" ,action="store_true" ,help ="Start in minimal mode without process box") args.add_argument("-s" , "--stat" ,action="store_true" ,help ="Start in minimal mode without process box")
args.add_argument("-v" , "--version" ,action="store_true" ,help ="Show version info and exit") args.add_argument("-v" , "--version" ,action="store_true" ,help ="Show version info and exit")
args.add_argument("-D" , "--debug" ,action="store_true" ,help ="Start with loglevel set to DEBUG overriding value set in config") args.add_argument("--debug" ,action="store_true" ,help ="Start with loglevel set to DEBUG overriding value set in config")
stdargs = args.parse_args() stdargs = args.parse_args()
if stdargs.version : if stdargs.version:
print(f'bpytop version: {VERSION}\n' print(f'bpytop version: {VERSION}\n'
f'psutil version: {".".join(str(x) for x in psutil.version_info)}') f'psutil version: {".".join(str(x) for x in psutil.version_info)}')
raise SystemExit(0) raise SystemExit(0)
ARG_MODE: str = "" ARG_MODE: str = ""
if stdargs.full: if stdargs.full:
ARG_MODE = "full" ARG_MODE = "full"
elif stdargs.proc: elif stdargs.proc:
ARG_MODE = "proc" ARG_MODE = "proc"
elif stdargs.stat: elif stdargs.stat:
ARG_MODE = "stat" ARG_MODE = "stat"
if stdargs.debug:
DEBUG = True
else:
DEBUG = False
#? Variables -------------------------------------------------------------------------------------> #? Variables ------------------------------------------------------------------------------------->
BANNER_SRC: List[Tuple[str, str, str]] = [ BANNER_SRC: List[Tuple[str, str, str]] = [
@ -214,11 +218,6 @@ THREADS: int = psutil.cpu_count(logical=True) or 1
THREAD_ERROR: int = 0 THREAD_ERROR: int = 0
if stdargs.debug :
DEBUG = True
else:
DEBUG = False
DEFAULT_THEME: Dict[str, str] = { DEFAULT_THEME: Dict[str, str] = {
"main_bg" : "", "main_bg" : "",
"main_fg" : "#cc", "main_fg" : "#cc",