Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Regebro committed Jul 23, 2024
1 parent b3cd59f commit 196233d
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions src/unoserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def _connect(self, proxy, retries=5, sleep=10):
f"Server runs {info['unoserver']}"
)
return info
except ConnectionError:
except ConnectionError as e:
logger.debug(f"Error {e.strerror}, waiting...")
retries -= 1
if retries > 0:
time.sleep(sleep)
logger.debug("Retrying...")
else:
raise

Expand Down Expand Up @@ -117,6 +119,8 @@ def convert(
raise ValueError("The outpath can not be a directory")

with ServerProxy(f"http://{self.server}:{self.port}", allow_none=True) as proxy:
logger.info("Connecting.")
logger.debug(f"Host: {self.server} Port: {self.port}")
info = self._connect(proxy)

if infiltername and infiltername not in info["import_filters"]:
Expand All @@ -133,6 +137,7 @@ def convert(
)
raise RuntimeError("Invalid parameter")

logger.info("Converting.")
result = proxy.convert(
inpath,
indata,
Expand All @@ -146,11 +151,15 @@ def convert(
if result is not None:
# We got the file back over xmlrpc:
if outpath:
logger.info(f"Writing to {outpath}.")
with open(outpath, "wb") as outfile:
outfile.write(result.data)
else:
# Return the result as a blob
logger.info(f"Returning {len(result.data)} bytes.")
return result.data
else:
logger.info(f"Saved to {outpath}.")

def compare(
self,
Expand Down Expand Up @@ -213,8 +222,11 @@ def compare(
newpath = os.path.abspath(newpath)

with ServerProxy(f"http://{self.server}:{self.port}", allow_none=True) as proxy:
logger.info("Connecting.")
logger.debug(f"Host: {self.server} Port: {self.port}")
self._connect(proxy)

logger.info("Comparing.")
result = proxy.compare(
oldpath,
olddata,
Expand All @@ -226,16 +238,19 @@ def compare(
if result is not None:
# We got the file back over xmlrpc:
if outpath:
logger.info(f"Writing to {outpath}.")
with open(outpath, "wb") as outfile:
outfile.write(result.data)
else:
# Return the result as a blob
logger.info(f"Returning {len(result.data)} bytes.")
return result.data
else:
logger.info(f"Saved to {outpath}.")


def converter_main():
logging.basicConfig()
logger.setLevel(logging.DEBUG)

parser = argparse.ArgumentParser("unoconvert")
parser.add_argument(
Expand Down Expand Up @@ -299,7 +314,29 @@ def converter_main():
"Default is auto, and it will send the file as a path if the host is 127.0.0.1 or "
"localhost, and binary data for other hosts.",
)
parser.add_argument(
"--verbose",
action="store_true",
dest="verbose",
help="Increase informational output to stderr.",
)
parser.add_argument(
"--quiet",
action="store_true",
dest="quiet",
help="Decrease informational output to stderr.",
)
args = parser.parse_args()

if args.verbose:
logger.setLevel(logging.DEBUG)
elif args.quiet:
logger.setLevel(logging.CRITICAL)
else:
logger.setLevel(logging.INFO)
if args.verbose and args.quiet:
logger.debug("Make up your mind, yo!")

client = UnoClient(args.host, args.port, args.host_location)

if args.outfile == "-":
Expand Down Expand Up @@ -331,7 +368,7 @@ def converter_main():

def comparer_main():
logging.basicConfig()
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.INFO)

parser = argparse.ArgumentParser("unocompare")
parser.add_argument(
Expand Down Expand Up @@ -371,8 +408,29 @@ def comparer_main():
"Default is auto, and it will send the file as a path if the host is 127.0.0.1 or "
"localhost, and binary data for other hosts.",
)
parser.add_argument(
"--verbose",
action="store_true",
dest="verbose",
help="Increase informational output to stderr.",
)
parser.add_argument(
"--quiet",
action="store_true",
dest="quiet",
help="Decrease informational output to stderr.",
)
args = parser.parse_args()

if args.verbose:
logger.setLevel(logging.DEBUG)
elif args.quiet:
logger.setLevel(logging.CRITICAL)
else:
logger.setLevel(logging.INFO)
if args.verbose and args.quiet:
logger.debug("Make up your mind, yo!")

client = UnoClient(args.host, args.port, args.host_location)

if args.outfile == "-":
Expand Down

0 comments on commit 196233d

Please sign in to comment.