Init add with base execute command and tests

This commit is contained in:
John Dewey 2014-05-29 20:16:04 -07:00
parent 20eef51c2e
commit 5319a0c6d0
12 changed files with 216 additions and 28 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.tox/
*.egg-info/
AUTHORS
ChangeLog
*.csv

30
LICENSE
View File

@ -1,4 +1,5 @@
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@ -172,30 +173,3 @@ Apache License
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,2 +1,41 @@
giftwrap
========
Usage
=====
$ pip install giftwrap
$ giftwrap -h
Dependencies
============
* `fpm`
Testing
=======
$ sudo pip install tox
$ tox
License
=======
| | |
|:---------------------|:---------------------------------------------------|
| **Authors** | John Dewey (<john@dewey.ws>) |
| | Craig Tracey (<craigtracey@gmail.com>) |
| | |
| **Copyright** | Copyright (c) 2014, John Dewey |
| | Copyright (c) 2014, Craig Tracey |
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

0
giftwrap/__init__.py Normal file
View File

View File

View File

@ -0,0 +1,40 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014, John Dewey
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest2 as unittest
from giftwrap import util
class TestUtil(unittest.TestCase):
def test_execute_returns_exitcode_tuple(self):
cmd = '/bin/test true'
result, _, _ = util.execute(cmd)
self.assertEquals(0, result)
def test_execute_returns_stdout_tuple(self):
cmd = 'echo stdout'
_, out, _ = util.execute(cmd)
self.assertEquals('stdout\n', out)
def test_execute_returns_stderr_tuple(self):
cmd = 'echo stderr >&2'
_, _, err = util.execute(cmd)
self.assertEquals('stderr\n', err)

38
giftwrap/util.py Normal file
View File

@ -0,0 +1,38 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014, John Dewey
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import subprocess
def execute(command):
"""
Executes a command in a subprocess. Returns a tuple of
(exitcode, out, err).
:param command: Command string to execute.
"""
process = subprocess.Popen(command,
cwd=os.getcwd(),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
(out, err) = process.communicate()
exitcode = process.wait()
return exitcode, out, err

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
pbr

32
setup.cfg Normal file
View File

@ -0,0 +1,32 @@
[metadata]
name = giftwrap
version = 0.1.0
summary = giftwrap - A tool to build full-stack native system packages.
description-file =
README.md
author = John Dewey
author-email = jodewey@cisco.com
home-page = https://github.com/cloudcadre/giftwrap
classifier =
Intended Audience :: Information Technology
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
[global]
setup-hooks =
pbr.hooks.setup_hook
# [entry_points]
# console_scripts =
# giftwrap = giftwrap.shell:main
[files]
packages =
giftwrap
[build_sphinx]
all_files = 1
build-dir = doc/build
source-dir = doc/source

21
setup.py Normal file
View File

@ -0,0 +1,21 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014, John Dewey
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
import setuptools
setuptools.setup(
setup_requires=['pbr'],
pbr=True)

5
test-requirements.txt Normal file
View File

@ -0,0 +1,5 @@
nose
mock
unittest2
flake8
pep8

33
tox.ini Normal file
View File

@ -0,0 +1,33 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py27,pep8
[testenv]
usedevelop = True
setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = nosetests
sitepackages = False
downloadcache = {toxworkdir}/_download
[testenv:pep8]
commands =
flake8 {posargs}
[testenv:venv]
commands = {posargs}
[testenv:pyflakes]
deps = flake8
commands = flake8
[flake8]
ignore = H301,H306
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg
show-source = True