mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
windows support + add quiet mode
This commit is contained in:
parent
565417453f
commit
85454e409a
|
@ -15,7 +15,7 @@ import locale
|
|||
import argparse
|
||||
from textwrap import dedent
|
||||
|
||||
from .__init__ import E
|
||||
from .__init__ import E, WINDOWS
|
||||
from .__version__ import S_VERSION, S_BUILD_DT
|
||||
from .svchub import SvcHub
|
||||
from .util import py_desc
|
||||
|
@ -27,12 +27,16 @@ class RiceFormatter(argparse.HelpFormatter):
|
|||
same as ArgumentDefaultsHelpFormatter(HelpFormatter)
|
||||
except the help += [...] line now has colors
|
||||
"""
|
||||
fmt = "\033[36m (default: \033[35m%(default)s\033[36m)\033[0m"
|
||||
if WINDOWS:
|
||||
fmt = " (default: %(default)s)"
|
||||
|
||||
help = action.help
|
||||
if "%(default)" not in action.help:
|
||||
if action.default is not argparse.SUPPRESS:
|
||||
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
|
||||
if action.option_strings or action.nargs in defaulting_nargs:
|
||||
help += "\033[36m (default: \033[35m%(default)s\033[36m)\033[0m"
|
||||
help += fmt
|
||||
return help
|
||||
|
||||
def _fill_text(self, text, width, indent):
|
||||
|
@ -123,6 +127,7 @@ def main():
|
|||
ap.add_argument("-j", metavar="CORES", type=int, help="max num cpu cores")
|
||||
ap.add_argument("-a", metavar="ACCT", type=str, action="append", help="add account")
|
||||
ap.add_argument("-v", metavar="VOL", type=str, action="append", help="add volume")
|
||||
ap.add_argument("-q", action="store_true", help="quiet")
|
||||
ap.add_argument("-nw", action="store_true", help="benchmark: disable writing")
|
||||
al = ap.parse_args()
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
|
||||
from .__init__ import PY2
|
||||
from .__init__ import PY2, WINDOWS
|
||||
from .util import undot, Pebkac, fsdec, fsenc
|
||||
|
||||
|
||||
|
@ -139,6 +140,11 @@ class AuthSrv(object):
|
|||
|
||||
self.warn_anonwrite = True
|
||||
|
||||
if WINDOWS:
|
||||
self.re_vol = re.compile(r'^([a-zA-Z]:[\\/][^:]*|[^:]*):([^:]*):(.*)')
|
||||
else:
|
||||
self.re_vol = re.compile(r'^([^:]*):([^:]*):(.*)')
|
||||
|
||||
self.mutex = threading.Lock()
|
||||
self.reload()
|
||||
|
||||
|
@ -220,7 +226,12 @@ class AuthSrv(object):
|
|||
if self.args.v:
|
||||
# list of src:dst:permset:permset:...
|
||||
# permset is [rwa]username
|
||||
for src, dst, perms in [x.split(":", 2) for x in self.args.v]:
|
||||
for vol_match in [self.re_vol.match(x) for x in self.args.v]:
|
||||
try:
|
||||
src, dst, perms = vol_match.groups()
|
||||
except:
|
||||
raise Exception('invalid -v argument')
|
||||
|
||||
src = fsdec(os.path.abspath(fsenc(src)))
|
||||
dst = dst.strip("/")
|
||||
mount[dst] = src
|
||||
|
|
|
@ -140,13 +140,15 @@ class BrokerMp(object):
|
|||
raise Exception("what is " + str(dest))
|
||||
|
||||
def debug_load_balancer(self):
|
||||
fmt = "\033[1m{}\033[0;36m{:4}\033[0m "
|
||||
if WINDOWS:
|
||||
fmt = "({}{:4})"
|
||||
|
||||
last = ""
|
||||
while self.procs:
|
||||
msg = ""
|
||||
for proc in self.procs:
|
||||
msg += "\033[1m{}\033[0;36m{:4}\033[0m ".format(
|
||||
len(proc.clients), proc.workload
|
||||
)
|
||||
msg += fmt.format(len(proc.clients), proc.workload)
|
||||
|
||||
if msg != last:
|
||||
last = msg
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# coding: utf-8
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import threading
|
||||
|
@ -27,9 +28,12 @@ class SvcHub(object):
|
|||
def __init__(self, args):
|
||||
self.args = args
|
||||
|
||||
self.ansi_re = re.compile("\033\\[[^m]*m")
|
||||
self.log_mutex = threading.Lock()
|
||||
self.next_day = 0
|
||||
|
||||
self.log = self._log_disabled if args.q else self._log_enabled
|
||||
|
||||
# initiate all services to manage
|
||||
self.tcpsrv = TcpSrv(self)
|
||||
self.up2k = Up2k(self)
|
||||
|
@ -61,7 +65,10 @@ class SvcHub(object):
|
|||
self.broker.shutdown()
|
||||
print("nailed it")
|
||||
|
||||
def log(self, src, msg):
|
||||
def _log_disabled(self, src, msg):
|
||||
pass
|
||||
|
||||
def _log_enabled(self, src, msg):
|
||||
"""handles logging from all components"""
|
||||
with self.log_mutex:
|
||||
now = time.time()
|
||||
|
@ -78,10 +85,20 @@ class SvcHub(object):
|
|||
self.next_day = calendar.timegm(dt.utctimetuple())
|
||||
|
||||
ts = datetime.utcfromtimestamp(now).strftime("%H:%M:%S.%f")[:-3]
|
||||
msg = "\033[36m{} \033[33m{:21} \033[0m{}".format(ts, src, msg)
|
||||
|
||||
if not WINDOWS:
|
||||
fmt = "\033[36m{} \033[33m{:21} \033[0m{}"
|
||||
else:
|
||||
fmt = "{} {:21} {}"
|
||||
if "\033" in msg:
|
||||
msg = self.ansi_re.sub("", msg)
|
||||
if "\033" in src:
|
||||
src = self.ansi_re.sub("", src)
|
||||
|
||||
msg = fmt.format(ts, src, msg)
|
||||
try:
|
||||
print(msg)
|
||||
except UnicodeEncodeError as ex:
|
||||
except UnicodeEncodeError:
|
||||
print(msg.encode("utf-8", "replace").decode())
|
||||
|
||||
def check_mp_support(self):
|
||||
|
|
Loading…
Reference in a new issue