From 79068d3fea4b52cf1fc76ef19714abcfe48e4420 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 6 Jul 2017 17:38:22 +0200 Subject: [PATCH] make php executable path configurable --- .travis.yml | 4 ++-- CHANGELOG.rst | 11 +++++++++++ Makefile | 2 +- README.rst | 19 +++++++++++-------- nextcloud_news_updater/api/cli.py | 2 +- .../common/argumentparser.py | 4 ++++ nextcloud_news_updater/config.py | 2 ++ setup.py | 11 +++-------- tests/nextcloud_news_updater/configs/full.ini | 3 ++- tests/nextcloud_news_updater/test_config.py | 1 + 10 files changed, 38 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index fa7de71..ecb8b87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ sudo: false language: python python: - - "3.4" - "3.5" + - "3.6" before_install: - - pip install pep8 mypy-lang + - pip install pycodestyle mypy script: - make test \ No newline at end of file diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0b447f5..e8b19de 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,6 +3,17 @@ Changelog --------- +10.0.0 ++++++ + +**Breaking Changes** + +* Require Python 3.5 or greater + +**Improvements** + +- Added option to specify PHP binary path + 9.0.1 +++++ diff --git a/Makefile b/Makefile index 3c84413..4a89aba 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ pypi: clean .PHONY: test test: - pep8 . + pycodestyle nextcloud_news_updater python3 -m nextcloud_news_updater --version python3 -m unittest #uncomment once mypy works properly diff --git a/README.rst b/README.rst index 785994f..a11ce0d 100644 --- a/README.rst +++ b/README.rst @@ -26,8 +26,7 @@ console based update API. Dependencies ------------ -* **Python >=3.4** -* **typing** (from pip) if you are running Python 3.4 +* **Python >=3.5** Pre-Installation ---------------- @@ -116,16 +115,16 @@ You can view all options by running:: :: - usage: nextcloud-news-updater [-h] [--threads THREADS] [--timeout TIMEOUT] + usage: __main__.py [-h] [--threads THREADS] [--timeout TIMEOUT] [--interval INTERVAL] [--apilevel {v1-2,v2}] [--loglevel {info,error}] [--config CONFIG] [--phpini PHPINI] [--user USER] [--password PASSWORD] - [--version] [--mode {endless,singlerun}] + [--version] [--mode {endless,singlerun}] [--php PHP] [url] positional arguments: url The URL or absolute path to the directory where - nextcloud is installed. Must be specified on the + Nextcloud is installed. Must be specified on the command line or in the config file. If the URL starts with http:// or https://, a user and password are required. Otherwise the updater tries to use the @@ -156,9 +155,9 @@ You can view all options by running:: Custom absolute path to the php.ini file to use for the command line updater. If omitted, the default one will be used - --user USER, -u USER Admin username to log into Nextcloud. Must be specified - on the command line or in the config file if the - updater should update over HTTP + --user USER, -u USER Admin username to log into Nextcloud. Must be + specified on the command line or in the config file if + the updater should update over HTTP --password PASSWORD, -p PASSWORD Admin password to log into Nextcloud if the updater should update over HTTP @@ -167,6 +166,8 @@ You can view all options by running:: Mode to run the updater in: endless runs the update again after the specified interval, singlerun only executes the update once + --php PHP Path to the PHP binary, e.g. /usr/bin/php7.0, defaults + to php @@ -189,6 +190,8 @@ You can also put your settings in a config file, looking like this: # or v2 which is currently a draft apilevel = v1-2 mode = endless + # path to php binary + php = /usr/bin/php7.0 **Note**: You can omit options in the config file if you want to use the defaults, but you can not have more than the allowed parameters present, otherwise an exception will abort the updater. diff --git a/nextcloud_news_updater/api/cli.py b/nextcloud_news_updater/api/cli.py index 41307fc..1a7a315 100644 --- a/nextcloud_news_updater/api/cli.py +++ b/nextcloud_news_updater/api/cli.py @@ -19,7 +19,7 @@ class CliApi(Api): if not directory.endswith('/'): directory += '/' self.directory = directory - base_command = ['php', '-f', self.directory + 'occ'] + base_command = [config.php, '-f', self.directory + 'occ'] if phpini is not None and phpini.strip() != '': base_command += ['-c', phpini] self.before_cleanup_command = base_command + [ diff --git a/nextcloud_news_updater/common/argumentparser.py b/nextcloud_news_updater/common/argumentparser.py index 985dd9f..10f20df 100644 --- a/nextcloud_news_updater/common/argumentparser.py +++ b/nextcloud_news_updater/common/argumentparser.py @@ -59,6 +59,10 @@ class ArgumentParser: 'specified interval, singlerun only ' 'executes the update once', choices=['endless', 'singlerun']) + self.parser.add_argument('--php', + help='Path to the PHP binary, ' + 'e.g. /usr/bin/php7.0, defaults to ' + 'php', default='php') self.parser.add_argument('url', help='The URL or absolute path to the ' 'directory where Nextcloud is installed.' diff --git a/nextcloud_news_updater/config.py b/nextcloud_news_updater/config.py index 972a39b..092893f 100644 --- a/nextcloud_news_updater/config.py +++ b/nextcloud_news_updater/config.py @@ -36,6 +36,7 @@ class Config: 'mode': Types.string, 'threads': Types.integer, 'interval': Types.integer, + 'php': Types.string, } def __init__(self) -> None: @@ -45,6 +46,7 @@ class Config: self.apilevel = 'v1-2' self.threads = 10 self.mode = 'endless' + self.php = 'php' self.password = '' self.user = None # type: Optional[str] self.url = None # type: Optional[str] diff --git a/setup.py b/setup.py index 1e0e086..75d8a91 100644 --- a/setup.py +++ b/setup.py @@ -2,14 +2,9 @@ from platform import python_version from sys import exit, version_info from setuptools import setup, find_packages -if version_info < (3, 4): - print('Error: Python 3.4 required but found %s' % python_version()) - exit(1) - if version_info < (3, 5): - install_requires = ['typing'] -else: - install_requires = [] + print('Error: Python 3.5 required but found %s' % python_version()) + exit(1) with open('README.rst', 'r') as infile: long_description = infile.read() @@ -30,7 +25,7 @@ setup( include_package_data=True, license='GPL', keywords=['nextcloud', 'news', 'updater', 'RSS', 'Atom', 'feed', 'reader'], - install_requires=install_requires, + install_requires=[], classifiers=[ 'Intended Audience :: System Administrators', 'Environment :: Console', diff --git a/tests/nextcloud_news_updater/configs/full.ini b/tests/nextcloud_news_updater/configs/full.ini index 2537695..fb52488 100644 --- a/tests/nextcloud_news_updater/configs/full.ini +++ b/tests/nextcloud_news_updater/configs/full.ini @@ -7,4 +7,5 @@ loglevel = info url = / phpini = /path/to/custom/php.ini apilevel = v2 -mode = singlerun \ No newline at end of file +mode = singlerun +php = /usr/local/bin/php7.0 \ No newline at end of file diff --git a/tests/nextcloud_news_updater/test_config.py b/tests/nextcloud_news_updater/test_config.py index 9b4a975..2656f84 100644 --- a/tests/nextcloud_news_updater/test_config.py +++ b/tests/nextcloud_news_updater/test_config.py @@ -38,6 +38,7 @@ class TestConfig(TestCase): self.assertEqual(config.phpini, '/path/to/custom/php.ini') self.assertEqual(config.apilevel, 'v2') self.assertEqual(config.mode, 'singlerun') + self.assertEqual(config.php, '/usr/local/bin/php7.0') def test_parse_defaults(self): config = self.parser.parse_file(find_test_config('empty.ini'))