Commit 48fe9f23 authored by louis-riviere-xyz's avatar louis-riviere-xyz
Browse files

init

parent 02114170
MIT License
Copyright (c) 2016 Louis RIVIERE <louis@riviere.xyz>
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.
###########
setux repl
###########
**Setux REPL**
========
Abstract
========
Rudimentary REPL for Setux
=====
Usage
=====
.. code-block:: shell
setux
============
Installation
============
see the Setux package.
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
#!/bin/bash
python3 mkcmds.py
make html
firefox _build/html/index.html
Command line and REPL
=====================
Setux's commands can be run on the command line or in the REPL.
Target
------
Commands are run on the ``Target``
The ``Target`` may be defined ...
Command line
------------
::
setux CMD
REPL
----
::
setux
.. toctree::
:maxdepth: 2
cmds
Commands
========
run
---
run shell cmd on target
infos
-----
get target infos
add
---
add modles
deploy
------
deploy module
remote
------
deploy module remotly
update
------
update packages
upgrade
-------
upgrade packages
May hang, if user input is required.
installed
---------
list installed packages
available
---------
list avaiable packages
bigs
----
list the bigest installed packages
upgradable
----------
list upgradble packages
install
-------
install package
remove
------
remove package
cleanup
-------
cleanup packages
status
------
query service status
start
-----
start service
stop
----
stop service
restart
-------
restart service
enable
------
enable service
disable
-------
disable service
download
--------
download file
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'setux'
copyright = '2020, Louis RIVIERE'
author = 'Louis RIVIERE'
# The full version, including alpha/beta/rc tags
release = 'alpha'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.intersphinx',
]
intersphinx_mapping = {
'setux': ('https://framagit.org/louis-riviere-xyz/setux/-/tree/alpha/doc ', None),
}
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
.. setux documentation master file, created by
sphinx-quickstart on Sun Jul 26 12:34:04 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Setux Repl
==========
Rudimentary Repl for Setux.
Requirements
-----------
Setux
Install
-------
see the Setux packags
Documentation
-------------
.. toctree::
:maxdepth: 2
cmd
:module: 'setux'
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
from setux.repl.helps import helps
with open('cmds.rst', 'w') as out:
def w(txt=''):
out.write(f'{txt}\n')
def t(txt, h='-'):
w(txt)
w(h*len(txt))
w()
t('Commands', '=')
for name, txt in helps.items():
t(f'{name}')
w(f'{txt}')
[metadata]
description-file = README.rst
from os.path import join, dirname, abspath
from setuptools import setup, find_namespace_packages
from setux.repl import __version__
curdir = abspath(dirname(__file__))
readme = open(join(curdir, 'README.rst')).read()
setup(
name = 'setux_repl',
version = __version__,
description = 'System deployment',
long_description = readme,
keywords = ['utility', ],
url = 'https://framagit.org/louis-riviere-xyz/setux_repl/tree/stable',
author = 'Louis RIVIERE',
author_email = 'louis@riviere.xyz',
license = 'MIT',
classifiers = [
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
"Operating System :: POSIX :: Linux",
"Environment :: Console",
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'Topic :: System :: Installation/Setup',
'Topic :: System :: Systems Administration',
'Topic :: Utilities',
],
install_requires = [
],
package_dir = {
},
packages = find_namespace_packages(include=['setux.*']),
)
__version__ = '0.1.0'
from . import commands as cmds
commands = {
name : func
for name, func in cmds.__dict__.items()
if not name.startswith('_')
}
def run(target, arg):
target(arg)
def infos(target, arg):
target.deploy('.infos')
def add(target, arg):
target.modules.add(arg)
def deploy(target, arg):
target.deploy(arg)
def remote(target, arg):
target.remote(arg)
def update(target, arg):
target.Package.update()
def upgrade(target, arg):
target.Package.upgrade()
def installed(target, arg):
pkg = list(target.Package.installed(arg))
print('\n'.join(f'{n} {v}' for n, v in pkg))
def available(target, arg):
pkg = list(target.Package.available(arg))
print('\n'.join(f'{n} {v}' for n, v in pkg))
def bigs(target, arg):
pkg = list(target.Package.bigs())
print('\n'.join(pkg))
def upgradable(target, arg):
pkg = list(target.Package.upgradable())
print('\n'.join(n for n, v in pkg))
def install(target, arg):
target.Package.install(arg)
def remove(target, arg):
target.Package.remove(arg)
def cleanup(target, arg):
target.Package.cleanup()
def status(target, arg):
target.Service.status(arg)
def start(target, arg):
target.Service.start(arg)
def stop(target, arg):
target.Service.stop(arg)
def restart(target, arg):
target.Service.restart(arg)
def enable(target, arg):
target.Service.enable(arg)
def disable(target, arg):
target.Service.disable(arg)
def download(target, arg):
url, dst = arg.split(' ') if ' ' in arg else arg, None
target.deploy('.download', url=url, dst=dst)
helps = dict(
run = '''run shell cmd on target
''',
infos = '''get target infos
''',
add = '''add modles
''',
deploy = '''deploy module
''',
remote = '''deploy module remotly
''',
update = '''update packages
''',
upgrade = '''upgrade packages
May hang, if user input is required.
''',
installed = '''list installed packages
''',
available = '''list avaiable packages
''',
bigs = '''list the bigest installed packages
''',
upgradable = '''list upgradble packages
''',
install = '''install package
''',
remove = '''remove package
''',
cleanup = '''cleanup packages
''',
status = '''query service status
''',
start = '''start service
''',
stop = '''stop service
''',
restart = '''restart service
''',
enable = '''enable service
''',
disable = '''disable service
''',
download = '''download file
''',
)
import readline
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')
from cmd import Cmd
from setux.main import banner
from .helps import helps
from . import commands
def safe(cmd, target):
def wrapper(arg):
try:
cmd(target, arg)
except Exception as x:
print(type(x).__name__, x)
return wrapper
def prompt(target):
user = 'sudo' if target.sudo else target.distro.Login.name
return f'{user}@{target.name} > '
class Repl(Cmd):
def __init__(self, target):
self.prompt = prompt(target)
for name, cmd in commands.items():
setattr(self, f'do_{name}', safe(cmd, target))
super().__init__()
def do_help(self, cmd):
def title(txt):
print(txt)
print('-'*len(txt))
if cmd:
hlp = helps.get(cmd)
if hlp:
title(cmd)
print(hlp)
else:
print(f'unkown command "{cmd}"')
else:
title('commands')
width = len(max(helps.keys(), key=len))+4
for cmd, hlp in helps.items():
first = hlp.split('\n')[0]
print(f'{cmd:>{width}} {first}')
def preloop(self):
print(banner)
self.onecmd('infos')
print()
def default(self, line):
self.onecmd(f'run {line}')
def do_EOF(self, arg):
return True
def repl(target):
Repl(target).cmdloop()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment