diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/autolatex/autolatex-config.py |
Initial commit
Diffstat (limited to 'support/autolatex/autolatex-config.py')
-rwxr-xr-x | support/autolatex/autolatex-config.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/support/autolatex/autolatex-config.py b/support/autolatex/autolatex-config.py new file mode 100755 index 0000000000..8afc1a3a45 --- /dev/null +++ b/support/autolatex/autolatex-config.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Include the Gtk library +import gettext +import os +import argparse +from gi.repository import Gtk + +# Only for debug +#import sys +#sys.path.append('/home/sgalland/git/autolatex/libs/gtk3') + +# AutoLaTeX shared libs +from autolatex.utils import utils +from autolatex.config import window as cli_config + +_T = gettext.gettext + +utils.init_application_configuration(__file__, 'autolatex-config') + +# Check if the AutoLaTeX is correctly installed +if not utils.AUTOLATEX_BINARY and not utils.AUTOLATEX_BACKEND_BINARY: + dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _T("The programs 'autolatex' and 'autolatex-backend'\nwere not found.\nPlease fix the configuration of the AutoLaTeX plugin.")) + answer = dialog.run() + dialog.destroy() +elif not utils.AUTOLATEX_BINARY: + dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _T("The program 'autolatex' was not found.\nPlease fix the configuration of the AutoLaTeX plugin.")) + answer = dialog.run() + dialog.destroy() +elif not utils.AUTOLATEX_BACKEND_BINARY: + dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _T("The program 'autolatex-backend' was not found.\nPlease fix the configuration of the AutoLaTeX plugin.")) + answer = dialog.run() + dialog.destroy() + +# Parsing the command line +parser = argparse.ArgumentParser() +parser.add_argument("--user", help=_T("change the user configuration"), action="store_true") +parser.add_argument("--document", help=_T("change the document configuration"), action="store_true") +parser.add_argument("--create", help=_T("create the configuration file"), action="store_true") +parser.add_argument("--directory", help=_T("directory where the TeX file is located")) +args = parser.parse_args() + +# Open the dialogs +if (args.user): + + config_file = utils.get_autolatex_user_config_file() + path = args.directory + if not path or not os.path.isdir(path): + path = os.path.expanduser("~") + if not os.path.isfile(config_file): + if (args.create): + fid = open(config_file, "a") + if fid: + fid.close() + else: + sys.stderr.write(_T("Unable to create the configuration file: %s\n") % config_file) + exit(255) + else: + sys.stderr.write(_T("Unable to find a document, file not found: %s\n") % config_file) + exit(255) + cli_config.open_configuration_dialog(None, False, path) + +else: + + path = args.directory + if not path or not os.path.isdir(path): + path = os.getcwd() + directory = utils.find_AutoLaTeX_directory(path) + if not directory: + config_file = utils.get_autolatex_document_config_file(path) + if (args.create): + fid = open(config_file, "a") + if fid: + fid.close() + else: + sys.stderr.write(_T("Unable to create the configuration file: %s\n") % config_file) + exit(255) + else: + sys.stderr.write(_T("Unable to find a document, file not found: %s\n") % config_file) + exit(255) + cli_config.open_configuration_dialog(None, True, directory) + +exit(0) |