Skip to content

Commit 80ee3e7

Browse files
committed
first commit
0 parents  commit 80ee3e7

File tree

8 files changed

+249
-0
lines changed

8 files changed

+249
-0
lines changed

.gitignore

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
*.dylib
9+
10+
# Distribution / packaging
11+
.Python
12+
env/
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*,cover
47+
.hypothesis/
48+
49+
.venv
50+
*.zip
51+
### https://raw.github.com/github/gitignore/be3333655bffe9507d66cc864aee95ed6052b4ed/Global/vim.gitignore
52+
53+
[._]*.s[a-w][a-z]
54+
[._]s[a-w][a-z]
55+
*.un~
56+
Session.vim
57+
.netrwhist
58+
*~

LICENSE

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

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
libspecinfra-python
2+
=======
3+
4+
# Description
5+
6+
Python bindings for libspecinfra.
7+
8+
# Requirements
9+
10+
- Python 3
11+
- [libspecinfra](https://github.com/libspecinfra/specinfra) (with rust-lang compiler)
12+
13+
# Installation
14+
15+
```sh
16+
git clone [email protected]:libspecinfra/specinfra.git
17+
git clone [email protected]:libspecinfra/libspecinfra-python.git
18+
cd specinfra
19+
cargo build
20+
cp target/debug/libspecinfra.dylib ../libpecinfra-python/
21+
cd ../libpecinfra-python
22+
python setup.py install
23+
```
24+
25+
**※ Installation from [PyPI](https://pypi.python.org/pypi) will be supported in the future.**
26+
27+
# Sample code
28+
29+
```python
30+
import libspecinfra
31+
import libspecinfra.backend
32+
33+
direct = libspecinfra.backend.Direct()
34+
specinfra = libspecinfra.Specinfra(direct)
35+
f = specinfra.file('/etc/passwd')
36+
37+
print(oct(f.mode())) # => 0o644
38+
```
39+
40+
Development
41+
-----------
42+
43+
- Source hosted at [GitHub](https://github.com/libspecinfra/libspecinfra-python)
44+
- Report issues/questions/feature requests on [GitHub
45+
Issues](https://github.com/libspecinfra/libspecinfra-python/issues)
46+
47+
Pull requests are very welcome! Make sure your patches are well tested.
48+
Ideally create a topic branch for every separate change you make. For
49+
example:
50+
51+
1. Fork the repo
52+
2. Create your feature branch (`git checkout -b my-new-feature`)
53+
3. Commit your changes (`git commit -am 'Added some feature'`)
54+
4. Push to the branch (`git push origin my-new-feature`)
55+
5. Create new Pull Request
56+
57+
License
58+
-------
59+
60+
MIT License (see [LICENSE](https://github.com/libspecinfra/libspecinfra-python/blob/master/LICENSE))

libspecinfra/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
libspecinfra-python
3+
----
4+
Python bindings for libspecinfra
5+
"""
6+
7+
__version__ = '0.0.1'
8+
9+
import sys
10+
import ctypes
11+
import libspecinfra.resource
12+
13+
from libspecinfra.structures import SpecinfraS, BackendWrapperS
14+
15+
library = None
16+
17+
def load():
18+
global library
19+
20+
if library is None:
21+
prefix = {'win32': ''}.get(sys.platform, 'lib')
22+
extension = {'darwin': '.dylib', 'win32': '.dll'}.get(sys.platform, '.so')
23+
library = ctypes.cdll.LoadLibrary(
24+
'{}specinfra{}'.format(prefix, extension))
25+
26+
return library
27+
28+
29+
class Specinfra(object):
30+
31+
def __init__(self, direct):
32+
lib = load()
33+
lib.specinfra_new.argtypes = (ctypes.POINTER(BackendWrapperS),)
34+
lib.specinfra_new.restype = ctypes.POINTER(SpecinfraS)
35+
self.lib = lib
36+
self.obj = lib.specinfra_new(direct.obj)
37+
38+
def file(self, path):
39+
return libspecinfra.resource.File(self.obj, path)

libspecinfra/backend/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ctypes
2+
import libspecinfra
3+
from libspecinfra.structures import BackendWrapperS
4+
5+
6+
class Direct(object):
7+
8+
def __init__(self):
9+
lib = libspecinfra.load()
10+
lib.backend_direct_new.restype = ctypes.POINTER(BackendWrapperS)
11+
self.obj = lib.backend_direct_new()

libspecinfra/resource/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ctypes
2+
import libspecinfra
3+
4+
from libspecinfra.structures import SpecinfraS, FileS
5+
6+
7+
class File(object):
8+
9+
def __init__(self, specinfra, path):
10+
lib = libspecinfra.load()
11+
lib.specinfra_file.argtypes = (ctypes.POINTER(SpecinfraS), ctypes.c_char_p,)
12+
lib.specinfra_file.restype = ctypes.POINTER(FileS)
13+
lib.resource_file_mode.argtypes = (ctypes.POINTER(FileS),)
14+
lib.resource_file_mode.restype = ctypes.c_uint
15+
self.lib = lib
16+
self.obj = lib.specinfra_file(specinfra, path.encode('utf-8'))
17+
18+
def mode(self):
19+
return self.lib.resource_file_mode(self.obj)

libspecinfra/structures.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import ctypes
2+
3+
class SpecinfraS(ctypes.Structure): pass;
4+
5+
class BackendWrapperS(ctypes.Structure): pass;
6+
7+
class FileS(ctypes.Structure): pass;

setup.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
import os
3+
4+
from setuptools import setup, find_packages
5+
6+
description = 'Python bindings for libspecinfra.'
7+
8+
setup_options = dict(
9+
name='libspecinfra-python',
10+
version='0.0.1',
11+
description=description,
12+
long_description=description,
13+
author='Masashi Terui',
14+
author_email='[email protected]',
15+
url='https://github.com/libspecinfra/libspecinfra-python',
16+
packages=find_packages(exclude=['tests*', 'specinfra*']),
17+
# rust extensions are not zip safe, just like C-extensions.
18+
zip_safe=False,
19+
license='MIT License',
20+
classifiers=[
21+
'Development Status :: 2 - Pre-Alpha',
22+
'Environment :: MacOS X',
23+
'Intended Audience :: Developers',
24+
'Intended Audience :: System Administrators',
25+
'License :: OSI Approved :: MIT License',
26+
'Programming Language :: Python',
27+
'Programming Language :: Python :: 3',
28+
'Programming Language :: Rust',
29+
],
30+
keywords='libspecinfra specinfra',
31+
)
32+
33+
setup(**setup_options)

0 commit comments

Comments
 (0)