Skip to content

Commit

Permalink
Add --version CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Nov 17, 2024
1 parent ea26574 commit 9e65d82
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 7 deletions.
17 changes: 17 additions & 0 deletions qubesmanager/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#
#

import argparse
import importlib.metadata
import signal
import sys
from qubesadmin import exc
from qubesadmin import utils as admin_utils

Expand All @@ -41,6 +44,19 @@
from . import resources

# pylint: disable=too-few-public-methods
def parse_args():
parser = argparse.ArgumentParser( \
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])
parser.add_argument('--version', action='version')
args = parser.parse_args()
return args


class BackupThread(QtCore.QThread):
def __init__(self, vm):
QtCore.QThread.__init__(self)
Expand Down Expand Up @@ -74,6 +90,7 @@ def run(self):

class BackupVMsWindow(ui_backupdlg.Ui_Backup, QtWidgets.QWizard):
def __init__(self, qt_app, qubes_app, dispatcher, parent=None):
self.cliargs = parse_args()
super().__init__(parent)

self.qt_app = qt_app
Expand Down
12 changes: 11 additions & 1 deletion qubesmanager/bootfromdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
#
#

import argparse
import functools
import importlib.metadata
import os.path
import subprocess
import sys
from . import utils
from . import ui_bootfromdevice # pylint: disable=no-name-in-module
from PyQt6 import QtWidgets, QtGui, QtCore # pylint: disable=import-error
Expand Down Expand Up @@ -169,7 +173,13 @@ def select_file_dialog(self):
self.pathText.setText(new_path)


parser = tools.QubesArgumentParser(vmname_nargs=1)
parser = tools.QubesArgumentParser(vmname_nargs=1, \
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])


def main(args=None):
Expand Down
10 changes: 9 additions & 1 deletion qubesmanager/clone_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#
#

import argparse
import importlib.metadata
import os
import sys
import subprocess
Expand Down Expand Up @@ -163,7 +165,13 @@ def clone_finished(self):
str(self.name.text())])


parser = qubesadmin.tools.QubesArgumentParser(vmname_nargs='?')
parser = qubesadmin.tools.QubesArgumentParser(vmname_nargs='?', \
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])


def main(args=None):
Expand Down
10 changes: 9 additions & 1 deletion qubesmanager/create_new_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#
#

import argparse
import importlib.metadata
import os
import sys
import subprocess
Expand Down Expand Up @@ -334,7 +336,13 @@ def settings_change(self):
self.install_system.setChecked(False)


parser = qubesadmin.tools.QubesArgumentParser()
parser = qubesadmin.tools.QubesArgumentParser( \
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])


def main(args=None):
Expand Down
18 changes: 18 additions & 0 deletions qubesmanager/qube_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
# with this program; if not, see <http://www.gnu.org/licenses/>.
#
#

import argparse
import importlib.metadata
import shlex
import subprocess
import sys
import threading
from datetime import datetime, timedelta
from functools import partial
Expand Down Expand Up @@ -62,6 +66,19 @@
# pylint: disable=unused-import, no-name-in-module
from . import resources

def parse_args():
parser = argparse.ArgumentParser( \
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])
parser.add_argument('--version', action='version')
args = parser.parse_args()
return args


def spawn_in_background(cmd: str | list[str]) -> None:
if isinstance(cmd, str):
cmd = shlex.split(cmd)
Expand Down Expand Up @@ -742,6 +759,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):

def __init__(self, qt_app, qubes_app, dispatcher, _parent=None):
# pylint: disable=too-many-statements
self.cliargs = parse_args()
super().__init__()
self.setupUi(self)

Expand Down
17 changes: 17 additions & 0 deletions qubesmanager/qvm_template_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
# pylint: disable=invalid-name

import abc
import argparse
import asyncio
import collections
import functools
import importlib.metadata
import subprocess
import threading
from datetime import datetime
from datetime import UTC
import json
import os
import sys
import typing
import shlex

Expand Down Expand Up @@ -79,6 +82,19 @@
""")


def parse_args():
parser = argparse.ArgumentParser( \
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])
parser.add_argument('--version', action='version')
args = parser.parse_args()
return args


class TreeItem(abc.ABC):
COL_NAMES = [
'Name',
Expand Down Expand Up @@ -631,6 +647,7 @@ class QvmTemplateWindow(
ui_qvmtemplate.Ui_MainWindow,
PyQt6.QtWidgets.QMainWindow):
def __init__(self, qt_app, qubes_app, dispatcher, _parent=None):
self.cliargs = parse_args()
super().__init__()
self.setupUi(self)
self.template_tree.header().setSectionResizeMode(
Expand Down
15 changes: 12 additions & 3 deletions qubesmanager/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#

import argparse
import importlib.metadata
from PyQt6 import QtCore, QtWidgets, QtGui # pylint: disable=import-error
import os
import os.path
import sys
import logging
import logging.handlers

Expand All @@ -43,12 +45,19 @@

# pylint: disable=too-few-public-methods
def parse_args():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser( \
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'--log', action='store', default='INFO',
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
help='Provide logging level. Values: DEBUG, INFO, '
'INFO (default), ERROR, CRITICAL')
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])
parser.add_argument('--version', action='version')
args = parser.parse_args()
return args

Expand Down Expand Up @@ -85,7 +94,7 @@ def run(self):

class RestoreVMsWindow(ui_restoredlg.Ui_Restore, QtWidgets.QWizard):
def __init__(self, qt_app, qubes_app, parent=None):
cliargs = parse_args()
self.cliargs = parse_args()
super().__init__(parent)

self.qt_app = qt_app
Expand All @@ -104,7 +113,7 @@ def __init__(self, qt_app, qubes_app, parent=None):
handler = logging.handlers.QueueHandler(self.feedback_queue)
logger = logging.getLogger('qubesadmin.backup')
logger.addHandler(handler)
logger.setLevel(cliargs.log)
logger.setLevel(self.cliargs.log)

self.backup_restore = None
self.target_appvm = None
Expand Down
11 changes: 10 additions & 1 deletion qubesmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
#
#

import argparse
import collections
import functools
import importlib.metadata
import re
import subprocess
import os
import sys
import traceback
from qubesadmin.tools import QubesArgumentParser
Expand Down Expand Up @@ -1551,7 +1554,13 @@ def delete_rule_button_pressed(self):
self.fw_model.remove_child(i)


parser = QubesArgumentParser(vmname_nargs=1)
parser = QubesArgumentParser(vmname_nargs=1,
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])

parser.add_argument('--tab', metavar='TAB',
action='store',
Expand Down
19 changes: 19 additions & 0 deletions qubesmanager/template_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#
#

import argparse
import importlib.metadata
import sys
import os

from qubesadmin import exc

from PyQt6 import QtWidgets, QtGui, QtCore # pylint: disable=import-error
Expand All @@ -35,11 +40,25 @@
column_names = ['State', 'Qube', 'Current template', 'New template']


def parse_args():
parser = argparse.ArgumentParser( \
formatter_class=argparse.RawDescriptionHelpFormatter)
_metadata_ = importlib.metadata.metadata('qubesmanager')
parser.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \
_metadata_['summary'], _metadata_['version'])
parser.version += '\nCopyright (C) {}'.format(_metadata_['author'])
parser.version += '\nLicense: {}'.format(_metadata_['license'])
parser.add_argument('--version', action='version')
args = parser.parse_args()
return args


class TemplateManagerWindow(
ui_templatemanager.Ui_MainWindow, QtWidgets.QMainWindow):

def __init__(self, qt_app, qubes_app, dispatcher, parent=None):
# pylint: disable=unused-argument
self.cliargs = parse_args()
super().__init__(parent)
self.setupUi(self)

Expand Down

0 comments on commit 9e65d82

Please sign in to comment.