Skip to content

Commit c297e09

Browse files
committed
github port, ready for pypi
1 parent a678641 commit c297e09

18 files changed

+1347
-41
lines changed

.gitignore

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
1-
# Byte-compiled / optimized / DLL files
1+
# General
2+
tmp/
3+
bin/
4+
build/
5+
dist/
6+
downloads/
7+
_trash/
8+
*~
9+
*.tmp
10+
*.bak
11+
*.swp
12+
*.log
13+
14+
15+
# Python
216
__pycache__/
317
*.py[cod]
418
*$py.class
5-
6-
# C extensions
719
*.so
8-
9-
# Distribution / packaging
1020
.Python
11-
env/
12-
build/
13-
develop-eggs/
14-
dist/
15-
downloads/
21+
*.manifest
22+
*.spec
23+
pip-log.txt
24+
pip-delete-this-directory.txt
1625
eggs/
1726
.eggs/
18-
lib/
19-
lib64/
20-
parts/
21-
sdist/
22-
var/
27+
*.egg
2328
*.egg-info/
29+
develop-eggs/
2430
.installed.cfg
25-
*.egg
26-
27-
# PyInstaller
28-
# Usually these files are written by a python script from a template
29-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30-
*.manifest
31-
*.spec
3231

33-
# Installer logs
34-
pip-log.txt
35-
pip-delete-this-directory.txt
3632

3733
# Unit test / coverage reports
3834
htmlcov/
@@ -45,45 +41,53 @@ coverage.xml
4541
*,cover
4642
.hypothesis/
4743

44+
4845
# Translations
4946
*.mo
5047
*.pot
5148

49+
5250
# Django stuff:
53-
*.log
5451
local_settings.py
5552

53+
5654
# Flask stuff:
5755
instance/
5856
.webassets-cache
5957

58+
6059
# Scrapy stuff:
6160
.scrapy
6261

62+
6363
# Sphinx documentation
6464
docs/_build/
6565

66+
6667
# PyBuilder
6768
target/
6869

70+
6971
# IPython Notebook
7072
.ipynb_checkpoints
7173

72-
# pyenv
73-
.python-version
74-
75-
# celery beat schedule file
76-
celerybeat-schedule
77-
78-
# dotenv
79-
.env
8074

8175
# virtualenv
76+
.python-version
77+
.env
78+
.venv/
79+
env/
8280
venv/
8381
ENV/
8482

85-
# Spyder project settings
86-
.spyderproject
8783

88-
# Rope project settings
89-
.ropeproject
84+
# IDE
85+
.idea
86+
.metadata
87+
*~.nib
88+
local.properties
89+
.settings/
90+
.project
91+
*.pydevproject
92+
93+

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language:
2+
- python
3+
4+
python:
5+
- "2.7"
6+
7+
# command to install dependencies
8+
install:
9+
- "pip install -r requirements.txt"
10+
11+
# command to run tests
12+
script:
13+
- pytest tests

LICENSE

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2+
python-keyctl
3+
4+
Copyright (c) 2017 Martin Becker
5+
6+
This work is licensed under the GNU General Public License v3.
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation in version 3 of the License.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
=======================================================================
18+
119
GNU GENERAL PUBLIC LICENSE
220
Version 3, 29 June 2007
321

@@ -631,8 +649,8 @@ to attach them to the start of each source file to most effectively
631649
state the exclusion of warranty; and each file should have at least
632650
the "copyright" line and a pointer to where the full notice is found.
633651

634-
{one line to give the program's name and a brief idea of what it does.}
635-
Copyright (C) {year} {name of author}
652+
<one line to give the program's name and a brief idea of what it does.>
653+
Copyright (C) <year> <name of author>
636654

637655
This program is free software: you can redistribute it and/or modify
638656
it under the terms of the GNU General Public License as published by
@@ -652,7 +670,7 @@ Also add information on how to contact you by electronic and paper mail.
652670
If the program does terminal interaction, make it output a short
653671
notice like this when it starts in an interactive mode:
654672

655-
{project} Copyright (C) {year} {fullname}
673+
<program> Copyright (C) <year> <name of author>
656674
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657675
This is free software, and you are welcome to redistribute it
658676
under certain conditions; type `show c' for details.
@@ -672,3 +690,4 @@ may consider it more useful to permit linking proprietary applications with
672690
the library. If this is what you want to do, use the GNU Lesser General
673691
Public License instead of this License. But first, please read
674692
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
693+

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
init:
2+
pip install -r requirements.txt
3+
4+
test:
5+
pytest tests
6+
7+
build:
8+
python setup.py sdist
9+
python setup.py bdist_wheel
10+
11+
pypi: clean build
12+
twine upload dist/* -r testpypi
13+
14+
clean:
15+
find . -type f -name '*~' -delete
16+
find . -type f -name '*.o' -delete
17+
find . -type f -name '*.pyc' -delete
18+
rm -rf build dist .cache *.egg-info tests/__pycache__
19+

README.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,169 @@
1+
[//]: # (-*- coding: utf-8 -*-)
2+
3+
4+
15
# python-keyctl
6+
27
Basic management of keys in the Linux kernel keyring in Python. Also comes with a small gui.
8+
9+
10+
## Table of contents
11+
12+
[//]: # (AUTO TOC BEGIN)
13+
14+
* [Description](#description)
15+
* [Requirements](#requirements)
16+
* [Installation](#installation)
17+
* [Usage](#usage)
18+
* [Module](#module)
19+
* [GUI](#gui)
20+
* [Development](#development)
21+
* [Warning](#warning)
22+
* [Similar projects](#similar-projects)
23+
* [License](#license)
24+
25+
[//]: # (AUTO TOC END)
26+
27+
28+
## Description
29+
30+
This is a small library to make use of some functions of the kernel keyring in Python. You can read, add and delete keys.
31+
32+
It simply uses the keyctl command (invoking it via subprocess), so this util must be installed.
33+
34+
Available functions:
35+
36+
* **list** *(list all keys in keyring)*
37+
* **describe** *(retrieve key name/description)*
38+
* **read/pipe/print** *(retrieve key content)*
39+
* **update** *(modify key content)*
40+
* **add** *(add key)*
41+
* **revoke/unlink** *(delete key)*
42+
* **search/request** *(search for a key by name)*
43+
* **clear** *(remove all keys from keyring)*
44+
45+
There are many more functions with keys in the kernel keyring (e.g. permissions) that is needed for proper keymanagement. But for my usecase I just needed the given simple functionality.
46+
47+
48+
## Requirements
49+
50+
Python 2.7
51+
```
52+
$ sudo apt-get install python2.7
53+
$ python --version
54+
Python 2.7.3
55+
```
56+
57+
pip
58+
```
59+
$ sudo apt-get install python-pip
60+
$ pip --version
61+
pip 9.0.1 from .... (python 2.7)
62+
```
63+
64+
The 'keyctl' command
65+
```
66+
$ sudo apt-get install keyutils
67+
$ dpkg -s keyutils | grep Version
68+
Version: 1.5.2-2
69+
```
70+
71+
For the GUI you also need:
72+
73+
Qt4
74+
```
75+
google it for your distribution
76+
```
77+
78+
PySide
79+
```
80+
$ pip install pyside
81+
$ pip show pyside | grep Version
82+
Version: 1.2.4
83+
```
84+
85+
86+
## Installation
87+
88+
```
89+
$ pip install keyctl
90+
```
91+
92+
Ready to use.
93+
94+
95+
## Usage
96+
97+
### Module
98+
Get all keys:
99+
```python
100+
from keyctl import Key
101+
keylist = Key.list()
102+
for mykey in keylist:
103+
print mykey.id
104+
```
105+
106+
Read existing key:
107+
```python
108+
from keyctl import Key
109+
mykey = Key(123)
110+
print mykey.name
111+
print mykey.data
112+
print mykey.data_hex
113+
```
114+
115+
Find key by name:
116+
```python
117+
from keyctl import Key
118+
mykey = Key.search('test key')
119+
print mykey.id
120+
```
121+
122+
Add key:
123+
```python
124+
from keyctl import Key
125+
mykey = Key.add('test key', 'test content')
126+
print mykey.id
127+
```
128+
129+
Delete key:
130+
```python
131+
from keyctl import Key
132+
mykey = Key(123)
133+
mykey.delete()
134+
```
135+
136+
Update key:
137+
```python
138+
from keyctl import Key
139+
mykey = Key(123)
140+
mykey.update('new content')
141+
```
142+
143+
144+
### GUI
145+
To open the GUI, run the installed command.
146+
```
147+
$ keyctlgui
148+
```
149+
150+
151+
## Development
152+
153+
### Warning
154+
155+
If you run the integrated tests, your user keyring will be cleared. Don't do this when you have active keys e.g. for encryption.
156+
157+
158+
## Similar projects
159+
160+
Similar projects you might want to checkout:
161+
162+
* https://github.com/sassoftware/python-keyutils (more complete, available in debian repo)
163+
* https://github.com/jdukes/pykeyctl (more complete, direct library wrapper)
164+
165+
166+
## License
167+
168+
GPL-3.0
169+
see [LICENSE](https://raw.githubusercontent.com/tuxberlin/python-keyctl/master/LICENSE) file

keyctl/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# -*- coding: utf-8 -*-
3+
4+
from .keyctlwrapper import KeyctlWrapper
5+
from .keyctlwrapper import KeyNotExistError, KeyAlreadyExistError, KeyctlOperationError
6+
7+
from .key import Key
8+
9+
10+
# -------------------------------------------------------------------
11+
12+
13+
import subprocess
14+
15+
# test for keyctl
16+
try:
17+
subprocess.check_output(['which', 'keyctl'])
18+
except subprocess.CalledProcessError:
19+
raise OSError('The commandline util \'keyctl\' must be installed to use this module. ' +
20+
'Install it via \'apt-get install keyutils\'.')

0 commit comments

Comments
 (0)