Skip to content

Commit

Permalink
add log option to show the last command output
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelmerro committed May 19, 2021
1 parent b39ecbf commit 9105f50
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ All of them are listed in the output as shown here:
```
usage: carafe {<carafe_name>,list} <sub_command>
Welcome to carafe 1.2.0
Welcome to carafe 1.3.0
carafe is a tiny management tool for wine bottles/carafes.
optional arguments:
Expand All @@ -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
Expand Down Expand Up @@ -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/<carafe_name>/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

Expand Down Expand Up @@ -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/<carafe_name>/log`.

#### Regedit

Example usage of regedit for a Steam carafe looks like this:
Expand Down Expand Up @@ -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/<carafe_name>/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,
Expand Down
25 changes: 20 additions & 5 deletions carafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -525,7 +535,7 @@ def main():
usage="carafe <carafe_name> 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)
Expand All @@ -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 <carafe_name> log <new_name>",
description="Use 'log' to show the output of the last command")
# Regedit
sub.add_parser(
"regedit", help="run regedit",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9105f50

Please sign in to comment.