From 9105f50faa464977b01b47b55cd64ca8bb3858cc Mon Sep 17 00:00:00 2001 From: Jelmer van Arnhem Date: Wed, 19 May 2021 17:10:47 +0200 Subject: [PATCH] add log option to show the last command output --- .gitignore | 1 - LICENSE | 2 +- README.md | 14 +++++++++++++- carafe.py | 25 ++++++++++++++++++++----- setup.py | 2 +- 5 files changed, 35 insertions(+), 9 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 1377554..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.swp diff --git a/LICENSE b/LICENSE index 384dec9..d6b061e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018-2020 Jelmer van Arnhem +Copyright (c) 2018-2021 Jelmer van Arnhem Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index cd5daf0..8a4aaa9 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ All of them are listed in the output as shown here: ``` usage: carafe {,list} -Welcome to carafe 1.2.0 +Welcome to carafe 1.3.0 carafe is a tiny management tool for wine bottles/carafes. optional arguments: @@ -167,6 +167,7 @@ sub-commands: info all info about a carafe link link a program to the carafe shortcut generate a desktop shortcut + log show the last command output regedit run regedit winecfg run winecfg winetricks run winetricks @@ -271,6 +272,7 @@ With the keep log argument, the start command can return to the default behavior If `--keep-log` is provided, the log can be found in `~/.carafe//log`. Keep in mind that this file can be multiple gigabytes after playing for a few hours, and that it will cause a performance hit on wine to constantly write logs to disk. +You can also show the contents of the log file with the 'log' option. #### Rename @@ -495,6 +497,15 @@ these type of shortcuts are made by wine and don't need carafe to work. Shortcuts won't be automatically deleted when a carafe is deleted. +#### Log + +Example usage of log for a Steam carafe looks like this: + +`carafe steam log` + +This will show the output of the last wine, winetricks or winecfg command. +It simply reads and prints the file that is stored at `~/.carafe//log`. + #### Regedit Example usage of regedit for a Steam carafe looks like this: @@ -554,6 +565,7 @@ without introducing any magic or changing the wine prefix system. ### Logging No wine commands executed by carafe will show any output in the terminal. +You can view the latest log using the 'log' option or by reading the 'log' file inside the carafe. The commands will store the log of the latest executed command as `~/.carafe//log`. carafe does not keep a history of all the logs, only the latest one is stored. The start command will by default disable all logging, diff --git a/carafe.py b/carafe.py index 5eb60f5..69811d7 100644 --- a/carafe.py +++ b/carafe.py @@ -6,7 +6,7 @@ # See README.md for more details and usage instructions __license__ = "MIT" # See LICENSE for more details and exact terms -__version__ = "1.2.0" +__version__ = "1.3.0" # See https://github.com/jelmerro/carafe for repo and updates import argparse @@ -298,6 +298,15 @@ def shortcut(self, args): with open(output_file, "w") as f: f.write(shortcut_contents) + def log(self, _args): + self.exists() + log_file = os.path.join(self.prefix, "log") + if os.path.isfile(log_file): + with open(log_file) as f: + print(f.read()) + else: + print(f"No logs for '{self.name}' carafe yet") + def regedit(self, _args): self.exists() self.run_command(f"{self.wine} regedit") @@ -350,9 +359,10 @@ def run_command(self, command, cwd=None): env["WINEPREFIX"] = self.prefix if self.arch: env["WINEARCH"] = self.arch - with open(os.path.join(self.prefix, "log"), "wb") as log: + with open(os.path.join(self.prefix, "log"), "wb") as log_file: subprocess.run( - command, shell=True, stderr=log, stdout=log, cwd=cwd, env=env) + command, shell=True, stderr=log_file, stdout=log_file, + cwd=cwd, env=env) def try_to_sanitize_location(self, loc): loc = loc.strip() @@ -450,7 +460,7 @@ def main(): usage=usage, formatter_class=argparse.RawDescriptionHelpFormatter, description=description, - epilog=f"carafe was made by {__author__} and is MIT licensed" + epilog=f"carafe was made by {__author__} and is {__license__} licensed" "\nFor documentation and other information, see the README.md") # Sub commands parser sub = parser.add_subparsers( @@ -525,7 +535,7 @@ def main(): usage="carafe shortcut", description="Use 'shortcut' to create a .desktop shortcut to a carafe") location_help = "Location of the executable inside the carafe to " \ - "shortcut. Normally a path, but can be set to 'link' as well." + "shortcut, normally a path, but can be set to 'link' as well" sub_shortcut.add_argument( "-l", "--location", help=location_help) @@ -539,6 +549,11 @@ def main(): sub_shortcut.add_argument( "-t", "--type", choices=["carafe", "wine"], help="The type of shortcut to make") + # Log + sub.add_parser( + "log", help="show the last command output", + usage="carafe log ", + description="Use 'log' to show the output of the last command") # Regedit sub.add_parser( "regedit", help="run regedit", diff --git a/setup.py b/setup.py index 7682d97..a242359 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="carafe", - version="1.2.0", + version="1.3.0", author="Jelmer van Arnhem", description="carafe is a tiny management tool for wine bottles/carafes", license="MIT",