Package: xal
xalis a Python library which provides
anhigh-level API to interact with system resources(files, commands, …)
andlow-level executionvia third-parties (stdlib, Fabric, Salt, …).The concept is you open a session in system, then you run commands within the
session:session is specific, it holds the execution context, it knows the low-level
implementation.commands use a generic API. You could run the same commands in another
session.Tip“xal” is the acronym of “eXecution Abstraction Layer”.ExampleLet’s initialize a session on local system:>>> import xal
>>> local_session = xal.LocalSession()In this session, we can manage files:>>> path = local_session.path('hello-xal.txt')
>>> path.exists()
False
>>> written = path.open('w').write(u'Hello world!')
>>> path.exists()
True
>>> print path.open().read()
Hello world!
>>> path.unlink()
>>> path.exists()
FalseWe can also execute sh commands:>>> result = local_session.sh.run(u"echo 'Goodbye!'")
>>> print result.stdout
Goodbye!
<BLANKLINE>Now let’s make a function that does the same. It takes the session as input
argument:>>> def hello(session):
...     path = session.path('hello-xal.txt')
...     path.open('w').write(u"Hello world!")
...     print path.open().read()
...     path.unlink()
...     print session.sh.run(u"echo 'Goodbye!'").stdoutOf course, we can run it in local session:>>> hello(local_session)
Hello world!
Goodbye!
<BLANKLINE>What’s nice is that we can reuse the same function in another session. Let’s
create a remote SSH session using Fabric…>>> remote_session = xal.FabricSession(host='localhost')… then just run the same function with this remote session:>>> hello(remote_session)
Hello world!
Goodbye!
<BLANKLINE>Motivationsxalideas are:Python users (including sysadmins and devops) have a consistent and unified
API to write scripts that perform operations on system.such scripts are portable, i.e. they can be executed in various environments.
Whatever the operating system, whatever the protocol to connect to and
communicate with the system…Python community can share libraries that are compatible with tools such as
Fabric, zc.buildout, Salt, Ansible…it is easier to switch from one tool to another: reconfigure the session,
don’t change the scripts. Develop scripts locally, test them remotely via
Fabric, distribute them using Salt… or vice-versa.Project’s statusToday:xalis a proof-of-concept. It focuses on sample implementation of
basic features such as managing files and directories, or executing sh
commands. The idea is that, as a Python user, you can give it a try and, if you
like it, use it for simple tasks.Tomorrow, depending on feedback from community,xalmay improve or be
deprecated. Asxal’s author, I would like the following things to happen:increased stability and performances for current features.more execution contexts (i.e. sessions): Salt, Fabric as sudoer, …more resources: users, system packages, …better API, preferrably built as PEPs. Just asxal’s proof of concept tries
to mimicpathlib, there could be a PEP related to every resource. Sh
commands (a.k.a. replacement for subprocess) are an epic example.Asxal’s author, I can’t do it alone. If you’d like to help:provide feedback. Do you likexal? What do you dislike inxal? Your
feedback matters!join the project on Github.RessourcesDocumentation:https://xal.readthedocs.orgPyPI:https://pypi.python.org/pypi/xalCode repository:https://github.com/benoitbryon/xalBugtracker:https://github.com/benoitbryon/xal/issuesContinuous integration:https://travis-ci.org/benoitbryon/xal