Make the project buildable

master
dece 4 years ago
parent 40b9a61629
commit 28f1dbb4a1

3
.gitignore vendored

@ -0,0 +1,3 @@
build/
dist/
xion.egg-info/

@ -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.

@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools >= 38.3.0", "wheel"]
build-backend = "setuptools.build_meta"

@ -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

@ -0,0 +1,2 @@
from setuptools import setup
setup()

@ -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()

@ -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()
Loading…
Cancel
Save