Skip to content

Commit 7161113

Browse files
author
Chris Hirsch
committed
Initial commit. Probably not ready for packaging yet
0 parents  commit 7161113

File tree

6 files changed

+232
-0
lines changed

6 files changed

+232
-0
lines changed

CHANGES.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
======================================
2+
Changes for robotframework-unixfilesystem
3+
======================================
4+
5+
2015/08/25 0.0.1
6+
================
7+
8+
- initial version

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include README.rst

README.rst

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
==========================
2+
robotframework-unixfilesystem
3+
==========================
4+
5+
**robotframework-unixfilesystem** is a `Robot Framework
6+
<http://code.google.com/p/robotframework/>`_ test library to test
7+
UNIX filesystem attributes like permissions, ownership etc.
8+
9+
Installation
10+
++++++++++++
11+
12+
To install, just fetch the latest version from PyPI:.
13+
14+
pip install --upgrade robotframework-unixfilesystem
15+
16+
Usage
17+
+++++
18+
19+
Setup in the robotframework Settings section:
20+
21+
============ ================
22+
Setting Value
23+
============ ================
24+
Library UnixFilesystemLibrary
25+
============ ================
26+
27+
\
28+
29+
These keyword actions are available::
30+
31+
Get Owner From Path:
32+
Does an lstat on the Path and returns the owner of the file/directory:
33+
34+
Arguments:
35+
- path: the path to the file/directory you wish to get ownership on (e.g. /tmp/test.txt or ../foo)
36+
Return:
37+
- owner: returns the owner of the file (e.g. root or chris)
38+
39+
Owner From Path Should Match:
40+
Does an lstat on the Path and checks to see if the supplied owner matches.
41+
Returns True if a match is found or False otherwise.
42+
43+
Arguments:
44+
- owner: the username to check against ownership of the path (e.g. root or chris)
45+
- path: the path to the file/directory you wish to get ownership on (e.g. /tmp/test.txt or ../foo)
46+
Return:
47+
- returns True if the owner of the Path matches Owner, False otherwise
48+
49+
Get Permissions From Path As Octal
50+
Gets the permissions via lstat of the supplied Path and returns those permissions as
51+
an octal value.
52+
53+
Arguments:
54+
- path: the path to the file/directory you wish to get ownership on (e.g. /tmp/test.txt or ../foo)
55+
Return:
56+
- permissions: Returns the octal permissions of the path (e.g. 0755 or 0644)
57+
58+
Permissions From Path Should Match:
59+
Gets the permissions via lstat of the supplied Path and checks if those permissions
60+
match the supplied Permissions.
61+
Returns True if a match is found or False otherwise.
62+
63+
Arguments:
64+
- path: the path to the file/directory you wish to get ownership on (e.g. /tmp/test.txt or ../foo)
65+
- permissions: octal permissions (e.g. 0755 or 0644)
66+
Return:
67+
- returns True if the owner of the Path matches Permissions, False otherwise
68+
69+
70+
71+
Here is an example of how to use the library:
72+
73+
================== ========================== ===================================
74+
Action Argument Argument
75+
================== ========================== ===================================
76+
${Owner}= Get Owner From Path path=/tmp/test.txt
77+
Should Match ${Owner} root
78+
================== ========================== ===================================
79+
80+
Here is an example of how to check that the owner of a path matches the supplied owner
81+
82+
============================ ========================== ===================================
83+
Action Argument Argument
84+
============================ ========================== ===================================
85+
Owner From Path Should Match root path=/tmp/text.txt
86+
============================ ========================== ===================================
87+
88+
Here is an example of how to get permissions from the path as an octal
89+
90+
================== ================================== ===================================
91+
Action Argument Argument
92+
================== ================================== ===================================
93+
${Permissions} Get Permissions From Path as Octal path=/tmp/
94+
Should Match ${Permissions} 0644
95+
================== ================================== ===================================
96+
97+
Here is an example of how to check that permissions from the path match the octal
98+
99+
================================== ==========================
100+
Action Argument
101+
================================== ==========================
102+
Permissions From Path Should Match 0644
103+
================================== ==========================
104+
105+
106+
107+
License
108+
+++++++
109+
110+
The robotframework-unixfilesystem is licensed under the `Apache 2.0 License
111+
<http://www.apache.org/licenses/LICENSE-2.0.html>`_.

setup.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
3+
from os.path import join, dirname
4+
5+
execfile(join(dirname(__file__), 'src', 'UnixFilesystemLibrary', 'version.py'))
6+
7+
from distutils.core import setup
8+
9+
CLASSIFIERS = """
10+
Programming Language :: Python
11+
Topic :: Software Development :: Testing
12+
"""[1:-1]
13+
14+
long_description=open(join(dirname(__file__), 'README.rst',)).read()
15+
16+
setup(
17+
name = 'robotframework-unixfilesystemlibrary',
18+
version = VERSION,
19+
description = 'Robot Framework UNIX Filesystem Library',
20+
long_description = long_description,
21+
author = 'Chris Hirsch',
22+
author_email = '[email protected]',
23+
url = 'https://github.com/ChrisHirsch/robotframework-unixfilesystem',
24+
license = 'Apache License 2.0',
25+
keywords = 'robotframework testing testautomation unix filesystem attributes',
26+
platforms = 'any',
27+
zip_safe = False,
28+
classifiers = CLASSIFIERS.splitlines(),
29+
package_dir = {'' : 'src'},
30+
install_requires = ['robotframework'],
31+
extras_require = dict(test=['zope.testing']),
32+
packages = ['UnixFilesystemLibrary'],
33+
)

src/UnixFilesystemLibrary/__init__.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import os
2+
import pwd
3+
4+
from robot.api import logger
5+
6+
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
7+
execfile(os.path.join(THIS_DIR, 'version.py'))
8+
9+
__version__ = VERSION
10+
11+
12+
class UnixFilesystemLibrary(object):
13+
14+
ROBOT_LIBRARY_VERSION = VERSION
15+
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
16+
17+
def get_uid_from_path(self, path):
18+
"""
19+
Return the UNIX User ID of the path
20+
"""
21+
logger.debug("HERE!")
22+
if not os.path.exists(path):
23+
raise Exception('Could not open file ' + path)
24+
return os.stat(path).st_uid
25+
26+
def get_owner_from_path(self, path):
27+
"""
28+
Return the owner (name) of the path
29+
"""
30+
logger.debug("get_owner_from_path")
31+
hope = self.get_uid_from_path(path)
32+
logger.debug("hope=" + str(hope))
33+
morehope = pwd.getpwuid(hope)
34+
logger.debug("morehope=" + str(morehope))
35+
36+
return str(morehope.pw_name)
37+
38+
def owner_from_path_should_match(self, owner, path):
39+
"""
40+
Return True if the owner matches user name of the path
41+
"""
42+
path_owner = self.get_owner_from_path(path)
43+
logger.debug("path_owner=" + str(path_owner))
44+
logger.debug("I return this=" + str(owner == path_owner))
45+
46+
return owner == path_owner
47+
48+
def get_permissions_from_path_as_octal(self, path):
49+
"""
50+
Returns the octal values of the path
51+
"""
52+
info = os.lstat(path)
53+
logger.debug("info=" + str(info))
54+
myoct = oct(info.st_mode & 0777)
55+
logger.debug("oct info=" + str(myoct))
56+
return str(myoct)
57+
58+
def get_permissions_from_path_as_list(self, path):
59+
"""
60+
Returns a list of modes from the lstat
61+
"""
62+
raise NotImplementedError("Sorry, we currently don't support \
63+
permissions as a list. Feel free to implement\
64+
and submit a pull request")
65+
66+
def permissions_from_path_should_match(self, path, mode):
67+
"""
68+
Returns True if the the octal values of the path mactches the mode. ie '0755'
69+
"""
70+
info = os.lstat(path)
71+
logger.debug("info=" + str(info))
72+
myoct = oct(info.st_mode & 0777)
73+
logger.debug("oct info=" + str(myoct))
74+
logger.debug("mode =" + mode)
75+
return str(myoct) == str(mode)
76+
77+
78+

src/UnixFilesystemLibrary/version.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = '0.0.1'

0 commit comments

Comments
 (0)