mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[microdecision] Remove unused imports + make pep8 happy
This commit is contained in:
parent
7e1712037f
commit
51ea069801
7 changed files with 25 additions and 19 deletions
|
@ -502,8 +502,8 @@ class _ExtendedSubParsersAction(argparse._SubParsersAction):
|
||||||
class ExtendedArgumentParser(argparse.ArgumentParser):
|
class ExtendedArgumentParser(argparse.ArgumentParser):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(ExtendedArgumentParser, self).__init__(
|
super(ExtendedArgumentParser, self).__init__(formatter_class=PositionalsFirstHelpFormatter,
|
||||||
formatter_class=PositionalsFirstHelpFormatter, *args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
# Register additional actions
|
# Register additional actions
|
||||||
self.register('action', 'callback', _CallbackAction)
|
self.register('action', 'callback', _CallbackAction)
|
||||||
|
|
|
@ -9,6 +9,7 @@ from moulinette.core import MoulinetteError
|
||||||
|
|
||||||
# Files & directories --------------------------------------------------
|
# Files & directories --------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def read_file(file_path):
|
def read_file(file_path):
|
||||||
"""
|
"""
|
||||||
Read a regular text file
|
Read a regular text file
|
||||||
|
@ -94,6 +95,7 @@ def write_to_file(file_path, data, file_mode="w"):
|
||||||
m18n.g('error_writing_file',
|
m18n.g('error_writing_file',
|
||||||
file=file_path, error=str(e)))
|
file=file_path, error=str(e)))
|
||||||
|
|
||||||
|
|
||||||
def append_to_file(file_path, data):
|
def append_to_file(file_path, data):
|
||||||
"""
|
"""
|
||||||
Append a single string or a list of string to a text file.
|
Append a single string or a list of string to a text file.
|
||||||
|
|
|
@ -9,9 +9,13 @@ sys.path.append("..")
|
||||||
|
|
||||||
|
|
||||||
old_init = moulinette.core.Moulinette18n.__init__
|
old_init = moulinette.core.Moulinette18n.__init__
|
||||||
|
|
||||||
|
|
||||||
def monkey_path_i18n_init(self, package, default_locale="en"):
|
def monkey_path_i18n_init(self, package, default_locale="en"):
|
||||||
old_init(self, package, default_locale)
|
old_init(self, package, default_locale)
|
||||||
self.load_namespace("moulinette")
|
self.load_namespace("moulinette")
|
||||||
|
|
||||||
|
|
||||||
moulinette.core.Moulinette18n.__init__ = monkey_path_i18n_init
|
moulinette.core.Moulinette18n.__init__ = monkey_path_i18n_init
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,16 +25,23 @@ moulinette.core.Moulinette18n.__init__ = monkey_path_i18n_init
|
||||||
|
|
||||||
|
|
||||||
old_translate = moulinette.core.Translator.translate
|
old_translate = moulinette.core.Translator.translate
|
||||||
|
|
||||||
|
|
||||||
def new_translate(self, key, *args, **kwargs):
|
def new_translate(self, key, *args, **kwargs):
|
||||||
|
|
||||||
if key not in self._translations[self.default_locale].keys():
|
if key not in self._translations[self.default_locale].keys():
|
||||||
raise KeyError("Unable to retrieve key %s for default locale !" % key)
|
raise KeyError("Unable to retrieve key %s for default locale !" % key)
|
||||||
|
|
||||||
return old_translate(self, key, *args, **kwargs)
|
return old_translate(self, key, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
moulinette.core.Translator.translate = new_translate
|
moulinette.core.Translator.translate = new_translate
|
||||||
|
|
||||||
|
|
||||||
def new_m18nn(self, key, *args, **kwargs):
|
def new_m18nn(self, key, *args, **kwargs):
|
||||||
return self._global.translate(key, *args, **kwargs)
|
return self._global.translate(key, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
moulinette.core.Moulinette18n.g = new_m18nn
|
moulinette.core.Moulinette18n.g = new_m18nn
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,4 +104,3 @@ def pytest_cmdline_main(config):
|
||||||
|
|
||||||
# Initialize moulinette
|
# Initialize moulinette
|
||||||
moulinette.init(logging_config=logging, _from_source=False)
|
moulinette.init(logging_config=logging, _from_source=False)
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
|
||||||
import requests_mock
|
|
||||||
|
|
||||||
# Moulinette specific
|
# Moulinette specific
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
from moulinette.utils.filesystem import (
|
from moulinette.utils.filesystem import (read_file, read_json,
|
||||||
read_file, read_json,
|
write_to_file, append_to_file,
|
||||||
write_to_file, append_to_file, write_to_json,
|
write_to_json,
|
||||||
rm,
|
rm,
|
||||||
chmod, chown)
|
chmod, chown)
|
||||||
|
|
||||||
|
@ -61,7 +59,7 @@ def test_read_file():
|
||||||
def test_read_file_badfile():
|
def test_read_file_badfile():
|
||||||
|
|
||||||
with pytest.raises(MoulinetteError):
|
with pytest.raises(MoulinetteError):
|
||||||
read_file(TMP_TEST_FILE+"nope")
|
read_file(TMP_TEST_FILE + "nope")
|
||||||
|
|
||||||
|
|
||||||
def test_read_file_badpermissions():
|
def test_read_file_badpermissions():
|
||||||
|
@ -295,5 +293,3 @@ def test_setpermissions_badgroup():
|
||||||
|
|
||||||
with pytest.raises(MoulinetteError):
|
with pytest.raises(MoulinetteError):
|
||||||
set_permissions(TMP_TEST_FILE, NON_ROOT_USER, "foo", 0111)
|
set_permissions(TMP_TEST_FILE, NON_ROOT_USER, "foo", 0111)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
# General python lib
|
# General python lib
|
||||||
import os
|
|
||||||
import pwd
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import requests_mock
|
import requests_mock
|
||||||
|
@ -14,10 +12,12 @@ from moulinette.utils.network import download_text, download_json
|
||||||
|
|
||||||
TEST_URL = "https://some.test.url/yolo.txt"
|
TEST_URL = "https://some.test.url/yolo.txt"
|
||||||
|
|
||||||
|
|
||||||
def setup_function(function):
|
def setup_function(function):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def teardown_function(function):
|
def teardown_function(function):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
@ -88,5 +88,3 @@ def test_download_json_badjson():
|
||||||
|
|
||||||
with pytest.raises(MoulinetteError):
|
with pytest.raises(MoulinetteError):
|
||||||
download_json(TEST_URL)
|
download_json(TEST_URL)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ def switch_to_non_root_user():
|
||||||
# Test run shell commands #
|
# Test run shell commands #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
def test_run_shell_command_list():
|
def test_run_shell_command_list():
|
||||||
|
|
||||||
commands = ["rm -f %s" % TMP_TEST_FILE]
|
commands = ["rm -f %s" % TMP_TEST_FILE]
|
||||||
|
@ -63,4 +64,3 @@ def test_run_shell_command_badpermissions():
|
||||||
switch_to_non_root_user()
|
switch_to_non_root_user()
|
||||||
with pytest.raises(CalledProcessError):
|
with pytest.raises(CalledProcessError):
|
||||||
run_commands(commands)
|
run_commands(commands)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue