Execution abstraction layer for high-level system scripts.
xal is a Python library which provides
an high-level API to interact with system resources (files, commands, …)
and low-level execution via third-parties (stdlib, Fabric, Salt, …).
The concept is you open a session in system, then you run commands within the session:
“xal” is the acronym of “eXecution Abstraction Layer”.
Let’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() False
We 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!'").stdout
Of 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>
xal ideas are:
xal is 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,
xal may improve or be
xal’s author, I would like the following things to happen:
xal’s proof of concept tries to mimic pathlib, there could be a PEP related to every resource. Sh commands (a.k.a. replacement for subprocess) are an epic example.
xal’s author, I can’t do it alone. If you’d like to help:
xal? What do you dislike in
xal? Your feedback matters!