Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release candidate for FR #1100 (unclear user-callback location) #1295

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Upcoming Release
* Translation update: French (#1077)
* Testing: fix a test fail when dealing with an empty crontab (#1181)
* Testing: numerous fixes and extensions to testing (#1115, #1213, #1279, #1280, #1281, #1285, #1288, #1290, #1293)
* Add feature: New argument "--diagnostics" to show helpful info for better issue support (#1100)

Version 1.3.2 (2022-03-12)
* Fix bug: Tests no longer work with Python 3.10 (https://github.com/bit-team/backintime/issues/1175)
Expand Down
45 changes: 42 additions & 3 deletions common/backintime.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import subprocess
from datetime import datetime
from time import sleep
import json

import config
import logger
Expand Down Expand Up @@ -206,6 +207,10 @@ def createParsers(app_name = 'backintime'):
action = printLicense,
nargs = 0,
help = "show %(prog)s's license.")
parser.add_argument('--diagnostics',
action = printDiagnostics,
nargs = 0,
help = "show helpful info for better support in case of issues (in JSON format)")

#######################
### define commands ###
Expand Down Expand Up @@ -595,9 +600,10 @@ def printHeader():
Print application name, version and legal notes.
"""
version = config.Config.VERSION
ref, hashid = tools.gitRevisionAndHash()
if ref:
version += " git branch '{}' hash '{}'".format(ref, hashid)
# Git info is now only shown via --diagnostics
# ref, hashid = tools.gitRevisionAndHash()
# if ref:
# version += " git branch '{}' hash '{}'".format(ref, hashid)
print('')
print('Back In Time')
print('Version: ' + version)
Expand Down Expand Up @@ -720,6 +726,39 @@ def __call__(self, *args, **kwargs):
print(cfg.license())
sys.exit(RETURN_OK)

class printDiagnostics(argparse.Action):
"""
Print information that is helpful for the support team
to narrow down problems and bugs.
The info is printed using the machine- and human-readable JSON format
"""

def __init__(self, *args, **kwargs):
super(printDiagnostics, self).__init__(*args, **kwargs)

def __call__(self, *args, **kwargs):
cfg = config.Config()

# TODO Refactor into a separate functions in a new diagnostics.py when more info is added
ref, hashid = tools.gitRevisionAndHash()
git_branch = "Unknown"
git_commit = "Unknown"
if ref:
git_branch = ref
git_commit = hashid

diagnostics = dict(
app_name=config.Config.APP_NAME,
app_version=config.Config.VERSION,
app_git_branch=git_branch,
app_git_commit=git_commit,
user_callback=cfg.takeSnapshotUserCallback()
)

print(json.dumps(diagnostics, indent=4))

sys.exit(RETURN_OK)

def backup(args, force = True):
"""
Command for force taking a new snapshot.
Expand Down
16 changes: 16 additions & 0 deletions common/test/test_backintime.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import subprocess
import sys
from test import generic
import json

import config



sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

Expand Down Expand Up @@ -168,3 +173,14 @@ def test_local_snapshot_is_successful(self):
"-r",
"/tmp/test",
"/tmp/restored"])

def test_diagnostics_arg(self):

# Workaround: Without this line the next "subprocess.getoutput()" call fails on TravisCI for unknown reasons!
subprocess.check_output(["./backintime", "--diagnostics"])

output = subprocess.getoutput("./backintime --diagnostics")

diagnostics = json.loads(output)
self.assertEqual(diagnostics["app_name"], config.Config.APP_NAME)
self.assertEqual(diagnostics["app_version"], config.Config.VERSION)