Skip to content

Commit 9558a4d

Browse files
committed
Initial release (0.1, alpha)
0 parents  commit 9558a4d

21 files changed

+1084
-0
lines changed

.coveragerc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
source = linux_utils
3+
omit = linux_utils/tests.py

.travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: python
2+
python:
3+
- "2.6"
4+
- "2.7"
5+
- "3.4"
6+
- "3.5"
7+
- "3.6"
8+
- "pypy"
9+
install:
10+
- scripts/install-on-travis.sh
11+
script:
12+
- make check
13+
- make test
14+
after_success:
15+
- coveralls
16+
branches:
17+
except:
18+
- /^[0-9]/

LICENSE.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2017 Peter Odding
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.rst
2+
include *.txt

Makefile

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Makefile for the `linux-utils' package.
2+
#
3+
# Author: Peter Odding <[email protected]>
4+
# Last Change: June 21, 2017
5+
# URL: https://linux-utils.readthedocs.io
6+
7+
PACKAGE_NAME = linux-utils
8+
WORKON_HOME ?= $(HOME)/.virtualenvs
9+
VIRTUAL_ENV ?= $(WORKON_HOME)/$(PACKAGE_NAME)
10+
PATH := $(VIRTUAL_ENV)/bin:$(PATH)
11+
MAKE := $(MAKE) --no-print-directory
12+
SHELL = bash
13+
14+
default:
15+
@echo "Makefile for $(PACKAGE_NAME)"
16+
@echo
17+
@echo 'Usage:'
18+
@echo
19+
@echo ' make install install the package in a virtual environment'
20+
@echo ' make reset recreate the virtual environment'
21+
@echo ' make check check coding style (PEP-8, PEP-257)'
22+
@echo ' make test run the test suite, report coverage'
23+
@echo ' make tox run the tests on all Python versions'
24+
@echo ' make docs update documentation using Sphinx'
25+
@echo ' make publish publish changes to GitHub/PyPI'
26+
@echo ' make clean cleanup all temporary files'
27+
@echo
28+
29+
install:
30+
@test -d "$(VIRTUAL_ENV)" || mkdir -p "$(VIRTUAL_ENV)"
31+
@test -x "$(VIRTUAL_ENV)/bin/python" || virtualenv --quiet "$(VIRTUAL_ENV)"
32+
@test -x "$(VIRTUAL_ENV)/bin/pip" || easy_install pip
33+
@test -x "$(VIRTUAL_ENV)/bin/pip-accel" || pip install --quiet pip-accel
34+
@pip-accel install --quiet --requirement=requirements.txt
35+
@pip uninstall --yes $(PACKAGE_NAME) &>/dev/null || true
36+
@pip install --quiet --no-deps --ignore-installed .
37+
38+
reset:
39+
$(MAKE) clean
40+
rm -Rf "$(VIRTUAL_ENV)"
41+
$(MAKE) install
42+
43+
check: install
44+
@scripts/check-code-style.sh
45+
46+
test: install
47+
@pip-accel install --quiet --requirement=requirements-tests.txt
48+
@py.test --cov
49+
@coverage html
50+
@coverage report --fail-under=90 &>/dev/null
51+
52+
tox: install
53+
@pip-accel install --quiet tox && tox
54+
55+
docs:
56+
@pip-accel install --quiet sphinx
57+
@cd docs && sphinx-build -nb html -d build/doctrees . build/html
58+
59+
publish: install
60+
git push origin && git push --tags origin
61+
$(MAKE) clean
62+
pip-accel install --quiet twine wheel
63+
python setup.py sdist bdist_wheel
64+
twine upload dist/*
65+
$(MAKE) clean
66+
67+
clean:
68+
@rm -Rf *.egg .cache .coverage .tox build dist docs/build htmlcov
69+
@find -depth -type d -name __pycache__ -exec rm -Rf {} \;
70+
@find -type f -name '*.pyc' -delete
71+
72+
.PHONY: default install reset check test tox docs publish clean

README.rst

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
linux-utils: Linux system administration tools for Python
2+
=========================================================
3+
4+
.. image:: https://travis-ci.org/xolox/python-linux-utils.svg?branch=master
5+
:target: https://travis-ci.org/xolox/python-linux-utils
6+
7+
.. image:: https://coveralls.io/repos/xolox/python-linux-utils/badge.svg?branch=master
8+
:target: https://coveralls.io/r/xolox/python-linux-utils?branch=master
9+
10+
The Python package `linux-utils` provides utility functions that make it easy
11+
to script system administration tasks on Linux_ systems in Python. At the
12+
moment only parsing of the ``/etc/fstab`` and ``/etc/crypttab`` configuration
13+
files is implemented, but more functionality will soon be released. The package
14+
is currently tested on cPython 2.6, 2.7, 3.4, 3.5, 3.6 and PyPy (2.7).
15+
16+
.. contents::
17+
:local:
18+
19+
Installation
20+
------------
21+
22+
The `linux-utils` package is available on PyPI_ which means installation should
23+
be as simple as:
24+
25+
.. code-block:: sh
26+
27+
$ pip install linux-utils
28+
29+
There's actually a multitude of ways to install Python packages (e.g. the `per
30+
user site-packages directory`_, `virtual environments`_ or just installing
31+
system wide) and I have no intention of getting into that discussion here, so
32+
if this intimidates you then read up on your options before returning to these
33+
instructions ;-).
34+
35+
Usage
36+
-----
37+
38+
Please refer to the API documentation available on `Read the Docs`_.
39+
40+
History
41+
-------
42+
43+
Back in 2015 I wrote some Python code to parse the Linux configuration files
44+
``/etc/fstab`` and ``/etc/crypttab`` for use in crypto-drive-manager_. Fast
45+
forward to 2017 and I found myself wanting to use the same functionality
46+
in rsync-system-backup_. Three options presented themselves to me:
47+
48+
1. **Copy/paste the relevant code.** Having to maintain the same code in
49+
multiple places causes lower quality code because having to duplicate the
50+
effort of writing documentation, developing tests and fixing bugs is a very
51+
demotivating endeavor.
52+
53+
In fact sometime in 2016 I *did* copy/paste parts of this code into a
54+
project at work, because I needed similar functionality there. Of course
55+
since then the two implementations have started diverging :-p.
56+
57+
2. **Make crypto-drive-manager a dependency of rsync-system-backup.** Although
58+
this approach is less ugly than copy/pasting the code, it still isn't
59+
exactly elegant because the two projects have nothing to do with each other
60+
apart from working with LUKS encrypted disks on Linux.
61+
62+
3. **Extract the functionality into a new package.** In my opinion this is
63+
clearly the most elegant approach, unfortunately it also requires the most
64+
work from me :-). On the plus side I'm publishing the new package with a
65+
test suite which means less untested code remains in crypto-drive-manager_
66+
(which doesn't have a test suite at the time of writing).
67+
68+
While extracting the code I shortly considered integrating the functionality
69+
into debuntu-tools_, however the ``/etc/fstab`` and ``/etc/crypttab`` parsing
70+
isn't specific to Debian or Ubuntu at all and debuntu-tools_ has several
71+
dependencies that aren't relevant to Linux configuration file parsing.
72+
73+
Tangentially related: The reason I went with the extremely generic name
74+
`linux-utils` is because I will be adding more *"specific to Linux but not
75+
Debian"* functionality to this package in the very near future :-).
76+
77+
Contact
78+
-------
79+
80+
The latest version of `linux-utils` is available on PyPI_ and GitHub_. The
81+
documentation is hosted on `Read the Docs`_. For bug reports please create an
82+
issue on GitHub_. If you have questions, suggestions, etc. feel free to send me
83+
an e-mail at `[email protected]`_.
84+
85+
License
86+
-------
87+
88+
This software is licensed under the `MIT license`_.
89+
90+
© 2017 Peter Odding.
91+
92+
.. External references:
93+
94+
.. _crypto-drive-manager: https://pypi.python.org/pypi/crypto-drive-manager
95+
.. _debuntu-tools: https://pypi.python.org/pypi/debuntu-tools
96+
.. _GitHub: https://github.com/xolox/python-linux-utils
97+
.. _Linux: https://en.wikipedia.org/wiki/Linux
98+
.. _MIT license: http://en.wikipedia.org/wiki/MIT_License
99+
.. _per user site-packages directory: https://www.python.org/dev/peps/pep-0370/
100+
101+
.. _PyPI: https://pypi.python.org/pypi/linux-utils
102+
.. _Python Package Index: https://pypi.python.org/pypi/linux-utils
103+
.. _Python: https://www.python.org/
104+
.. _Read the Docs: https://linux-utils.readthedocs.org
105+
.. _rsync-system-backup: https://pypi.python.org/pypi/rsync-system-backup
106+
.. _virtual environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/

docs/conf.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# linux-utils: Linux system administration tools for Python.
2+
#
3+
# Author: Peter Odding <[email protected]>
4+
# Last Change: June 21, 2017
5+
# URL: https://linux-utils.readthedocs.io
6+
7+
"""Sphinx documentation configuration for the `linux-utils` package."""
8+
9+
import os
10+
import sys
11+
12+
# Add the 'linux-utils' source distribution's root directory to the module path.
13+
sys.path.insert(0, os.path.abspath(os.pardir))
14+
15+
# -- General configuration -----------------------------------------------------
16+
17+
# Sphinx extension module names.
18+
extensions = [
19+
'sphinx.ext.autodoc',
20+
'sphinx.ext.intersphinx',
21+
'sphinx.ext.viewcode',
22+
'humanfriendly.sphinx',
23+
]
24+
25+
# Sort members by the source order instead of alphabetically.
26+
autodoc_member_order = 'bysource'
27+
28+
# Paths that contain templates, relative to this directory.
29+
templates_path = ['templates']
30+
31+
# The suffix of source filenames.
32+
source_suffix = '.rst'
33+
34+
# The master toctree document.
35+
master_doc = 'index'
36+
37+
# General information about the project.
38+
project = u'linux-utils'
39+
copyright = u'2017, Peter Odding'
40+
41+
# The version info for the project you're documenting, acts as replacement for
42+
# |version| and |release|, also used in various other places throughout the
43+
# built documents.
44+
45+
# Find the package version and make it the release.
46+
from linux_utils import __version__ as linux_utils_version # noqa
47+
48+
# The short X.Y version.
49+
version = '.'.join(linux_utils_version.split('.')[:2])
50+
51+
# The full version, including alpha/beta/rc tags.
52+
release = linux_utils_version
53+
54+
# The language for content autogenerated by Sphinx. Refer to documentation
55+
# for a list of supported languages.
56+
language = 'en'
57+
58+
# List of patterns, relative to source directory, that match files and
59+
# directories to ignore when looking for source files.
60+
exclude_patterns = ['build']
61+
62+
# If true, '()' will be appended to :func: etc. cross-reference text.
63+
add_function_parentheses = True
64+
65+
# The name of the Pygments (syntax highlighting) style to use.
66+
pygments_style = 'sphinx'
67+
68+
# Refer to the Python standard library.
69+
# From: http://twistedmatrix.com/trac/ticket/4582.
70+
intersphinx_mapping = dict(
71+
python=('https://docs.python.org/2', None),
72+
executor=('https://executor.readthedocs.io/en/latest/', None),
73+
propertymanager=('https://property-manager.readthedocs.io/en/latest/', None),
74+
)
75+
76+
# -- Options for HTML output ---------------------------------------------------
77+
78+
# The theme to use for HTML and HTML Help pages. See the documentation for
79+
# a list of builtin themes.
80+
html_theme = 'nature'
81+
82+
# Output file base name for HTML help builder.
83+
htmlhelp_basename = 'linuxutilsdoc'

docs/index.rst

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. include:: ../README.rst
2+
3+
API documentation
4+
=================
5+
6+
The following documentation is based on the source code of version |release| of
7+
the `linux-utils` package.
8+
9+
**Available modules**
10+
11+
.. contents::
12+
:local:
13+
14+
:mod:`linux_utils`
15+
------------------
16+
17+
.. automodule:: linux_utils
18+
:members:
19+
20+
:mod:`linux_utils.crypttab`
21+
---------------------------
22+
23+
.. automodule:: linux_utils.crypttab
24+
:members:
25+
26+
:mod:`linux_utils.fstab`
27+
------------------------
28+
29+
.. automodule:: linux_utils.fstab
30+
:members:
31+
32+
:mod:`linux_utils.tabfile`
33+
--------------------------
34+
35+
.. automodule:: linux_utils.tabfile
36+
:members:

0 commit comments

Comments
 (0)