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
|
import argparse
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from .__init__ import E
|
from .__init__ import E, WINDOWS
|
||||||
from .__version__ import S_VERSION, S_BUILD_DT
|
from .__version__ import S_VERSION, S_BUILD_DT
|
||||||
from .svchub import SvcHub
|
from .svchub import SvcHub
|
||||||
from .util import py_desc
|
from .util import py_desc
|
||||||
|
@ -27,12 +27,16 @@ class RiceFormatter(argparse.HelpFormatter):
|
||||||
same as ArgumentDefaultsHelpFormatter(HelpFormatter)
|
same as ArgumentDefaultsHelpFormatter(HelpFormatter)
|
||||||
except the help += [...] line now has colors
|
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
|
help = action.help
|
||||||
if "%(default)" not in action.help:
|
if "%(default)" not in action.help:
|
||||||
if action.default is not argparse.SUPPRESS:
|
if action.default is not argparse.SUPPRESS:
|
||||||
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
|
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
|
||||||
if action.option_strings or action.nargs in defaulting_nargs:
|
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
|
return help
|
||||||
|
|
||||||
def _fill_text(self, text, width, indent):
|
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("-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("-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("-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")
|
ap.add_argument("-nw", action="store_true", help="benchmark: disable writing")
|
||||||
al = ap.parse_args()
|
al = ap.parse_args()
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from .__init__ import PY2
|
from .__init__ import PY2, WINDOWS
|
||||||
from .util import undot, Pebkac, fsdec, fsenc
|
from .util import undot, Pebkac, fsdec, fsenc
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,6 +140,11 @@ class AuthSrv(object):
|
||||||
|
|
||||||
self.warn_anonwrite = True
|
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.mutex = threading.Lock()
|
||||||
self.reload()
|
self.reload()
|
||||||
|
|
||||||
|
@ -220,7 +226,12 @@ class AuthSrv(object):
|
||||||
if self.args.v:
|
if self.args.v:
|
||||||
# list of src:dst:permset:permset:...
|
# list of src:dst:permset:permset:...
|
||||||
# permset is [rwa]username
|
# 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)))
|
src = fsdec(os.path.abspath(fsenc(src)))
|
||||||
dst = dst.strip("/")
|
dst = dst.strip("/")
|
||||||
mount[dst] = src
|
mount[dst] = src
|
||||||
|
|
|
@ -140,13 +140,15 @@ class BrokerMp(object):
|
||||||
raise Exception("what is " + str(dest))
|
raise Exception("what is " + str(dest))
|
||||||
|
|
||||||
def debug_load_balancer(self):
|
def debug_load_balancer(self):
|
||||||
|
fmt = "\033[1m{}\033[0;36m{:4}\033[0m "
|
||||||
|
if WINDOWS:
|
||||||
|
fmt = "({}{:4})"
|
||||||
|
|
||||||
last = ""
|
last = ""
|
||||||
while self.procs:
|
while self.procs:
|
||||||
msg = ""
|
msg = ""
|
||||||
for proc in self.procs:
|
for proc in self.procs:
|
||||||
msg += "\033[1m{}\033[0;36m{:4}\033[0m ".format(
|
msg += fmt.format(len(proc.clients), proc.workload)
|
||||||
len(proc.clients), proc.workload
|
|
||||||
)
|
|
||||||
|
|
||||||
if msg != last:
|
if msg != last:
|
||||||
last = msg
|
last = msg
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
@ -27,9 +28,12 @@ class SvcHub(object):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
|
self.ansi_re = re.compile("\033\\[[^m]*m")
|
||||||
self.log_mutex = threading.Lock()
|
self.log_mutex = threading.Lock()
|
||||||
self.next_day = 0
|
self.next_day = 0
|
||||||
|
|
||||||
|
self.log = self._log_disabled if args.q else self._log_enabled
|
||||||
|
|
||||||
# initiate all services to manage
|
# initiate all services to manage
|
||||||
self.tcpsrv = TcpSrv(self)
|
self.tcpsrv = TcpSrv(self)
|
||||||
self.up2k = Up2k(self)
|
self.up2k = Up2k(self)
|
||||||
|
@ -61,7 +65,10 @@ class SvcHub(object):
|
||||||
self.broker.shutdown()
|
self.broker.shutdown()
|
||||||
print("nailed it")
|
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"""
|
"""handles logging from all components"""
|
||||||
with self.log_mutex:
|
with self.log_mutex:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
@ -78,10 +85,20 @@ class SvcHub(object):
|
||||||
self.next_day = calendar.timegm(dt.utctimetuple())
|
self.next_day = calendar.timegm(dt.utctimetuple())
|
||||||
|
|
||||||
ts = datetime.utcfromtimestamp(now).strftime("%H:%M:%S.%f")[:-3]
|
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:
|
try:
|
||||||
print(msg)
|
print(msg)
|
||||||
except UnicodeEncodeError as ex:
|
except UnicodeEncodeError:
|
||||||
print(msg.encode("utf-8", "replace").decode())
|
print(msg.encode("utf-8", "replace").decode())
|
||||||
|
|
||||||
def check_mp_support(self):
|
def check_mp_support(self):
|
||||||
|
|
Loading…
Reference in a new issue