From 28f1dbb4a1d36b4f4d88ffdab08f3819b46b2428 Mon Sep 17 00:00:00 2001 From: dece Date: Sun, 27 Sep 2020 23:06:16 +0200 Subject: [PATCH] Make the project buildable --- .gitignore | 3 ++ LICENSE.txt | 21 ++++++++++++++ pyproject.toml | 3 ++ setup.cfg | 23 +++++++++++++++ setup.py | 2 ++ xion/__init__.py | 0 xion/__main__.py | 57 +++++++++++++++++++++++++++++++++++++ xfconf.py => xion/xfconf.py | 0 xion.py => xion/xion.py | 57 +------------------------------------ 9 files changed, 110 insertions(+), 56 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 xion/__init__.py create mode 100644 xion/__main__.py rename xfconf.py => xion/xfconf.py (100%) rename xion.py => xion/xion.py (65%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7ef7a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +dist/ +xion.egg-info/ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..637bf53 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools >= 38.3.0", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..c904081 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,23 @@ +[metadata] +name = xion +version = 0.0.1 +description = JSON interface to Xfconf +long_description = file: README.md +license = MIT +author = dece +author-email = shgck@pistache.land +home-page = https://github.com/Dece/Xion +classifiers = + Environment :: Console + License :: OSI Approved :: MIT License + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.7 + +[options] +packages = xion +python_requires = >= 3.7 +setup_requires = setuptools >= 38.3.0 + +[options.entry_points] +console_scripts = + xion = xion.__main__:main diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8bf1ba9 --- /dev/null +++ b/setup.py @@ -0,0 +1,2 @@ +from setuptools import setup +setup() diff --git a/xion/__init__.py b/xion/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/xion/__main__.py b/xion/__main__.py new file mode 100644 index 0000000..30cde08 --- /dev/null +++ b/xion/__main__.py @@ -0,0 +1,57 @@ +import argparse + +from xion.xion import Xion + + +def main(): + argparser = argparse.ArgumentParser() + argparser.add_argument( + "--xq-path", type=str, + help="Optional path to xion-query" + ) + argparser.add_argument( + "-e", "--export", type=str, nargs=3, + metavar=("CHANNEL", "ROOT", "OUTPUT"), + help=("Export settings in channel under this root. " + "Use '/' as root to export the whole channel.") + ) + argparser.add_argument( + "-i", "--import", dest="import_tree", type=str, + metavar=("JSON",), + help="Import a JSON settings file" + ) + argparser.add_argument( + "-r", "--replace", action="store_true", + help="Replace the root with imported settings, remove unknowns" + ) + argparser.add_argument( + "-y", "--yes", action="store_true", + help="Do not ask for confirmation" + ) + args = argparser.parse_args() + + xion = Xion(xq=args.xq_path) + if args.export: + channel, root, output = args.export + tree = xion.build_tree(channel, root) + if tree is None: + print("Failed to build config tree.") + exit(1) + success = xion.export_tree(channel, root, tree, output) + exit(0 if success else 1) + elif args.import_tree: + channel, root, tree = xion.import_tree(args.import_tree) + if channel and root and tree: + force = bool(args.yes) + replace = bool(args.replace) + success = xion.apply_tree(channel, root, tree, + confirm=not force, replace=replace) + exit(0 if success else 1) + else: + print("Import failed.") + exit(1) + exit(0) + + +if __name__ == "__main__": + main() diff --git a/xfconf.py b/xion/xfconf.py similarity index 100% rename from xfconf.py rename to xion/xfconf.py diff --git a/xion.py b/xion/xion.py similarity index 65% rename from xion.py rename to xion/xion.py index 179e6df..8f331ec 100644 --- a/xion.py +++ b/xion/xion.py @@ -1,57 +1,6 @@ -import argparse import json -from xfconf import Xfconf - - -def main(): - argparser = argparse.ArgumentParser() - argparser.add_argument( - "--xq-path", type=str, - help="Optional path to xion-query" - ) - argparser.add_argument( - "-e", "--export", type=str, nargs=3, - metavar=("CHANNEL", "ROOT", "OUTPUT"), - help=("Export settings in channel under this root. " - "Use '/' as root to export the whole channel.") - ) - argparser.add_argument( - "-i", "--import", dest="import_tree", type=str, - metavar=("JSON",), - help="Import a JSON settings file" - ) - argparser.add_argument( - "-r", "--replace", action="store_true", - help="Replace the root with imported settings, remove unknowns" - ) - argparser.add_argument( - "-y", "--yes", action="store_true", - help="Do not ask for confirmation" - ) - args = argparser.parse_args() - - xion = Xion(xq=args.xq_path) - if args.export: - channel, root, output = args.export - tree = xion.build_tree(channel, root) - if tree is None: - print("Failed to build config tree.") - exit(1) - success = xion.export_tree(channel, root, tree, output) - exit(0 if success else 1) - elif args.import_tree: - channel, root, tree = xion.import_tree(args.import_tree) - if channel and root and tree: - force = bool(args.yes) - replace = bool(args.replace) - success = xion.apply_tree(channel, root, tree, - confirm=not force, replace=replace) - exit(0 if success else 1) - else: - print("Import failed.") - exit(1) - exit(0) +from xion.xfconf import Xfconf class Xion: @@ -139,7 +88,3 @@ class Xion: prop_type = content["type"] value = content["value"] return self.xfconf.set_property(channel, name, prop_type, value) - - -if __name__ == "__main__": - main()