Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rarylson committed Mar 15, 2015
2 parents bfd10f2 + fe3c2a2 commit a2a0c7f
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 61 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
source = update_conf_py

[report]
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/build
/dist
*.egg-info/
/.coverage
/htmlcov
*.pyc
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: python

python:
- "2.6"
- "2.7"
# Currently, the project is broke in Python3 because of the ConfigParser
# package (called configparser in Python3 - lowercase). For now, we're
# disabling it.
#- "3.4"

install:
- pip install -r requirements-test.txt
- pip install coveralls
# It's necessary to install the project to create the update-conf.py bin.
# It's used by the 'test_script.py' module.
- python setup.py develop

script:
- make check
# It's necessary to run tests as 'sudo'. 'sudo' is used by the
# 'test_sudo_config.py' module.
- sudo PATH=$PATH make test-with-coverage

after_success: coveralls
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

0.4.3
-----

- Project is working now in Python 2.6;
- Project integrated with Travis and Coveralls;
- It passes in all tests (Python 2.6 and 2.7) and has 100% code coverage.

0.4.2
-----

Expand Down
17 changes: 13 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# From 'setuptools' docs:
# "Automatically include all relevant files in your source distributions,
# without needing to create a MANIFEST.in file"
# From Python sdist docs:
# "If you don’t supply an explicit list of files (or instructions on how
# to generate one), the sdist command puts a minimal default set into the
# source distribution:
# [...]
# - all files that matches the data_files metadata"
# However, 'samples/update-conf.py.conf' wasn't being included in sdist. We
# don't know if it is a bug. Anyway, we're creating our 'MANIFEST.in'.
# don't know if it is a bug. Anyway, we're adding it into our 'MANIFEST.in'.
# See: https://pythonhosted.org/setuptools/setuptools.html
include samples/update-conf.py.conf
# https://docs.python.org/2/distutils/sourcedist.html
include Makefile
include LICENSE
include README.rst
include .coveragerc
include .travis.yml
include *.md
include *.txt
recursive-include samples *
recursive-include tests *
global-exclude tests/tmp
global-exclude tests/tmp/*
global-exclude *.pyc
30 changes: 25 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ all: help
help:
@echo "Usage:"
@echo
@echo " make install install the project in the system (global)"
@echo " make uninstall show tips for uninstalling the project"
@echo " make install install project in system (global)"
@echo " make uninstall show tips for uninstalling"
@echo " make check check PEP8 compliance (and others)"
@echo " make test run the tests (use 'sudo' to run all)"
@echo " make test run tests (use 'sudo' to run all)"
@echo " make check-coverage run tests and check coverage (use 'sudo' to run all)"
@echo " make clean cleanup temporary files"
@echo " make install-develop install the project in develop mode (virtual environment)"
@echo " make install-develop install project in develop mode (virtual environment)"
@echo " make develop-deps-ubuntu install software dependencies (valid only in Ubuntu)"
@echo " make prepare prepare stuff (build, dist, etc) before publishing"
@echo " make publish-test test publishing a version (PyPI Test)"
Expand All @@ -30,6 +31,7 @@ help:
# Tests

check:
check-manifest
python setup.py flake8
# Ignore 'N802' (function name should be lowercase) in tests because we need
# to inherit from the unittest class (that defines the setUp / tearDown
Expand All @@ -39,6 +41,20 @@ check:
test:
python setup.py test

test-with-coverage:
coverage run setup.py test

check-coverage: test-with-coverage
coverage html
@echo
@echo "Check coverage results at"
@echo
@tput setaf 2
@echo " http://localhost:8000"
@tput sgr0
@echo
cd htmlcov && python -m SimpleHTTPServer


# Install

Expand Down Expand Up @@ -106,7 +122,11 @@ clean-build:
rm -Rf dist/
rm -Rf *.egg-info

clean-coverage-report:
rm -f .coverage
rm -Rf htmlcov

clean-pyc:
find . -name "*.pyc" -type f -delete

clean: clean-rst clean-build clean-pyc
clean: clean-rst clean-build clean-coverage-report clean-pyc
37 changes: 17 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
update-conf.py
==============

[![Travis CI - Build Status](https://img.shields.io/travis/rarylson/update-conf.py.svg)](https://travis-ci.org/rarylson/update-conf.py)
[![Coveralls - Coverage Percentage](https://img.shields.io/coveralls/rarylson/update-conf.py.svg)](https://coveralls.io/r/rarylson/update-conf.py)
[![Pypi - Downloads](https://img.shields.io/pypi/dm/update-conf.py.svg)](https://pypi.python.org/pypi/update-conf.py/)
[![Pypi - Version](https://img.shields.io/pypi/v/update-conf.py.svg)](https://pypi.python.org/pypi/update-conf.py/)
[![Licence](https://img.shields.io/pypi/l/update-conf.py.svg)](LICENCE)
[![License](https://img.shields.io/pypi/l/update-conf.py.svg)](LICENSE)
[![Pypi - Wheel](https://pypip.in/wheel/update-conf.py/badge.svg?style=flat)](https://pypi.python.org/pypi/update-conf.py/)

Generate config files from `conf.d` like directories.
Expand All @@ -17,9 +19,9 @@ This project was based in the [update-conf.d project](https://github.com/Atha/up
Install
-------

This project requires Python 2.6 or newer.
This project requires Python 2.6 or Python 2.7.

**PS:** It's possible to use Python 3 also. However, it is not well tested.
**PS:** We're working on Python 3.X compatibility.

To install:

Expand All @@ -38,13 +40,13 @@ python setup.py install
Usage
-----

If you run:
To generate a config file, you can run something like this:

```sh
update-conf.py -f /etc/snmp/snmpd.conf
```

The script will merge the splitted config files in the directory `/etc/snmp/snmpd.conf.d` into the file `/etc/snmp/snmpd.conf`.
The example above will merge the splitted config files in the directory `/etc/snmp/snmpd.conf.d` into the file `/etc/snmp/snmpd.conf`.

If the directory containing the splitted files uses a diferent name pattern, you can pass its name as an argument:

Expand Down Expand Up @@ -74,17 +76,17 @@ update-conf.py --help

### Config files

`update-conf.py` can use config files. It will use a global config file (`/etc/update-conf.py.conf`) or a user-home config file (`~/.update-conf.py.conf`) if they exist.
`update-conf.py` will use the global config file (`/etc/update-conf.py.conf`) or the user-home config file (`~/.update-conf.py.conf`) if they exist.

When installing via `setuptools` or via the source distribution, the global system config (`/etc/update-conf.py.conf`) will be automatically created.
When installing via the source distribution, the global config file (`/etc/update-conf.py.conf`) will be automatically created.

However, when installing via the binary wheel distribution, the config file installation will be skipped. But you can use the sample config file as a start:
However, when installing via the binary wheel distribution, the config file installation will be skipped. But you can use the sample config file as a start point:

```sh
cp {prefix}/share/update-conf.py /etc/update-conf.py.conf
```

It's also possible to use a custom config file:
It's also possible to pass a custom config file via command line args:

```sh
update-conf.py -c my_custom_config.conf -n snmpd
Expand All @@ -98,21 +100,16 @@ This software is released under the [Revised BSD License](LICENSE).
Changelog
---------

You can see the changelog [here](CHANGELOG.md).
Check the [CHANGELOG](CHANGELOG.md) page.

TODO
----

- Publish this software in a Ubuntu PPA;
- Remove dependencies from argparse e configparser before pubishing in the PPA;
- Ubuntu 12.04 and Ubuntu 14.04;
- Use Travis as a continuous integration server;
- Hide "bugtracker_url" warning when running setup.py with setuptools;
- Use code coverage (`coverage`);
- Flags: https://github.com/z4r/python-coveralls
- Create tests for 100% code coverage;
- Code covarage after tests:
- `cd htmlcov && python -m SimpleHTTPServer 8888 && open http://localhost:8888`;
- Hide "bugtracker_url" warning when running `setup.py` with setuptools;
- https://pypi.python.org/pypi/bumpversion/ in `Makefile`;
- check-manifest in `Makefile` / `setup.py`;
- should `README.rst` be in `MANIFEST.in`?;
- https://github.com/blog/1184-contributing-guidelines
- Add a `CONTRIBUTING.md` file (https://github.com/blog/1184-contributing-guidelines);
- Make project compatible with Python 3.X;
- Add a test installing `update-conf.py` from PyPI Test (`make publish-test`).
5 changes: 1 addition & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
-r requirements.txt
-r requirements-test.txt

setuptools>=0.8
pypandoc>=0.9
pep8>=1.6
flake8>=2.2
pep8-naming>=0.2
7 changes: 7 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-r requirements.txt

unittest2>=1.0.0
coverage>=3.7
flake8>=2.2
pep8-naming>=0.2
check-manifest>=0.22
20 changes: 4 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import shutil
from distutils import log
from setuptools import setup, Command
from setuptools.command.sdist import sdist
from setuptools.command.register import register
from setuptools.command.install import install

Expand Down Expand Up @@ -88,17 +87,6 @@ def run(self):
os.remove(tmp_readme_md)


class SdistCommand(sdist):
"""Check if we're using README.rst before creating the source dist
"""

def finalize_options(self):
if not using_rst:
raise Exception("{} file not found".format(README_RST))

return sdist.finalize_options(self)


class RegisterCommand(register):
"""Check if we're using README.rst before registering in Pypi
"""
Expand Down Expand Up @@ -173,7 +161,6 @@ def run(self):
"License :: OSI Approved",
"Natural Language :: English",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
Expand All @@ -191,7 +178,7 @@ def run(self):

# Data files
data_files=[
(join("share", main.__program__), [sample_config_path, ]),
(join("share", main.__program__), [sample_config, ]),
],

# Extra
Expand All @@ -201,9 +188,11 @@ def run(self):
"pypandoc>=0.9",
],
"test": [
"pep8>=1.6",
"unittest2>=1.0.0",
"coverage>=3.7",
"flake8>=2.2",
"pep8-naming>=0.2",
"check-manifest>=0.22",
],
},

Expand All @@ -213,7 +202,6 @@ def run(self):
# Commands
cmdclass={
"generate_rst": GenerateRstCommand,
"sdist": SdistCommand,
"register": RegisterCommand,
"install": InstallCommand,
}
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion tests/test_create_temp_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from StringIO import StringIO
import filecmp

import unittest
# Import unittest2 for Python 2.6 compatibility
import unittest2 as unittest

from update_conf_py import main
import utils
Expand Down
3 changes: 2 additions & 1 deletion tests/test_get_splitted.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from os.path import join, basename
from StringIO import StringIO

import unittest
# Import unittest2 for Python 2.6 compatibility
import unittest2 as unittest

from update_conf_py import main
import utils
Expand Down
25 changes: 22 additions & 3 deletions tests/test_parse_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from os.path import join
from StringIO import StringIO

import unittest
# Import unittest2 for Python 2.6 compatibility
import unittest2 as unittest

from update_conf_py import main
import utils
Expand All @@ -20,6 +21,10 @@ def setUp(self):
self.section_name = "test1"
self.config_file_path = "tests/tmp/test1"
self.config_dir_path = "tests/tmp/test1.d"
self.section_name_2 = "test2"
self.config_file_path_2 = "tests/tmp/test2"
self.config_dir_path_2 = "tests/snippets/test2"
self.config_comment_prefix_2 = ";"
# These tests must be done from the root dir
self.chdir_old = os.getcwd()
os.chdir(utils.ROOT_DIR)
Expand Down Expand Up @@ -79,16 +84,30 @@ def test_wrong_cmd_args(self):
sys.stderr = stderr_old

def test_config_parse(self):
"""App must parse options from a config file
"""App must parse options from a config file (and use defaut values
from the other options)
"""
sys.argv = [sys.argv[0], "-c", self.config_path, "-n", "test1"]
sys.argv = [
sys.argv[0], "-c", self.config_path, "-n", self.section_name]
args = main._parse_all()
self.assertEqual(args.file, self.config_file_path)
self.assertEqual(args.dir, self.config_dir_path)
self.assertEqual(args.comment_prefix, "#")
self.assertEqual(args.config, self.config_path)
self.assertEqual(args.name, self.section_name)

def test_config_parse_full(self):
"""App must parse all options from a config file
"""
sys.argv = [
sys.argv[0], "-c", self.config_path, "-n", self.section_name_2]
args = main._parse_all()
self.assertEqual(args.file, self.config_file_path_2)
self.assertEqual(args.dir, self.config_dir_path_2)
self.assertEqual(args.comment_prefix, self.config_comment_prefix_2)
self.assertEqual(args.config, self.config_path)
self.assertEqual(args.name, self.section_name_2)

def test_nonexistent_config_parse(self):
"""App must print an error and exit when no config file was found
"""
Expand Down

0 comments on commit a2a0c7f

Please sign in to comment.