mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[mod] autopep8 on all files that aren't concerned by a PR
This commit is contained in:
parent
a94733c1f9
commit
aad3740933
10 changed files with 181 additions and 154 deletions
|
@ -313,8 +313,6 @@ def backup_create(name=None, description=None, output_directory=None,
|
|||
link = "%s/%s.tar.gz" % (archives_path, name)
|
||||
os.symlink(archive_file, link)
|
||||
|
||||
|
||||
|
||||
# Clean temporary directory
|
||||
if tmp_dir != output_directory:
|
||||
_clean_tmp_dir()
|
||||
|
|
|
@ -113,7 +113,6 @@ def domain_add(auth, domain, dyndns=False):
|
|||
raise MoulinetteError(errno.EINVAL,
|
||||
m18n.n('domain_dyndns_root_unknown'))
|
||||
|
||||
|
||||
try:
|
||||
yunohost.certificate._certificate_install_selfsigned([domain], False)
|
||||
|
||||
|
@ -122,7 +121,6 @@ def domain_add(auth, domain, dyndns=False):
|
|||
except MoulinetteError:
|
||||
raise MoulinetteError(errno.EEXIST, m18n.n('domain_exists'))
|
||||
|
||||
|
||||
attr_dict['virtualdomain'] = domain
|
||||
|
||||
if not auth.add('virtualdomain=%s,ou=domains' % domain, attr_dict):
|
||||
|
@ -133,11 +131,14 @@ def domain_add(auth, domain, dyndns=False):
|
|||
service_regen_conf(names=[
|
||||
'nginx', 'metronome', 'dnsmasq', 'rmilter'])
|
||||
os.system('yunohost app ssowatconf > /dev/null 2>&1')
|
||||
except IOError: pass
|
||||
except IOError:
|
||||
pass
|
||||
except:
|
||||
# Force domain removal silently
|
||||
try: domain_remove(auth, domain, True)
|
||||
except: pass
|
||||
try:
|
||||
domain_remove(auth, domain, True)
|
||||
except:
|
||||
pass
|
||||
raise
|
||||
|
||||
hook_callback('post_domain_add', args=[domain])
|
||||
|
@ -296,6 +297,7 @@ def _get_maindomain():
|
|||
maindomain = f.readline().rstrip()
|
||||
return maindomain
|
||||
|
||||
|
||||
def _set_maindomain(domain):
|
||||
with open('/etc/yunohost/current_host', 'w') as f:
|
||||
f.write(domain)
|
||||
|
|
|
@ -94,7 +94,7 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None
|
|||
|
||||
logger.info(m18n.n('dyndns_key_generating'))
|
||||
|
||||
os.system('cd /etc/yunohost/dyndns && ' \
|
||||
os.system('cd /etc/yunohost/dyndns && '
|
||||
'dnssec-keygen -a hmac-md5 -b 128 -r /dev/urandom -n USER %s' % domain)
|
||||
os.system('chmod 600 /etc/yunohost/dyndns/*.key /etc/yunohost/dyndns/*.private')
|
||||
|
||||
|
@ -108,8 +108,10 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None
|
|||
except requests.ConnectionError:
|
||||
raise MoulinetteError(errno.ENETUNREACH, m18n.n('no_internet_connection'))
|
||||
if r.status_code != 201:
|
||||
try: error = json.loads(r.text)['error']
|
||||
except: error = "Server error"
|
||||
try:
|
||||
error = json.loads(r.text)['error']
|
||||
except:
|
||||
error = "Server error"
|
||||
raise MoulinetteError(errno.EPERM,
|
||||
m18n.n('dyndns_registration_failed', error=error))
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ def firewall_reload(skip_upnp=False):
|
|||
# Iterate over ports and add rule
|
||||
for protocol in ['TCP', 'UDP']:
|
||||
for port in firewall['ipv4'][protocol]:
|
||||
rules.append("iptables -w -A INPUT -p %s --dport %s -j ACCEPT" \
|
||||
rules.append("iptables -w -A INPUT -p %s --dport %s -j ACCEPT"
|
||||
% (protocol, process.quote(str(port))))
|
||||
rules += [
|
||||
"iptables -w -A INPUT -i lo -j ACCEPT",
|
||||
|
@ -253,7 +253,7 @@ def firewall_reload(skip_upnp=False):
|
|||
# Iterate over ports and add rule
|
||||
for protocol in ['TCP', 'UDP']:
|
||||
for port in firewall['ipv6'][protocol]:
|
||||
rules.append("ip6tables -w -A INPUT -p %s --dport %s -j ACCEPT" \
|
||||
rules.append("ip6tables -w -A INPUT -p %s --dport %s -j ACCEPT"
|
||||
% (protocol, process.quote(str(port))))
|
||||
rules += [
|
||||
"ip6tables -w -A INPUT -i lo -j ACCEPT",
|
||||
|
@ -308,7 +308,8 @@ def firewall_upnp(action='status', no_refresh=False):
|
|||
try:
|
||||
# Remove old cron job
|
||||
os.remove('/etc/cron.d/yunohost-firewall')
|
||||
except: pass
|
||||
except:
|
||||
pass
|
||||
action = 'status'
|
||||
no_refresh = False
|
||||
|
||||
|
@ -330,7 +331,8 @@ def firewall_upnp(action='status', no_refresh=False):
|
|||
try:
|
||||
# Remove cron job
|
||||
os.remove(upnp_cron_job)
|
||||
except: pass
|
||||
except:
|
||||
pass
|
||||
enabled = False
|
||||
if action == 'status':
|
||||
no_refresh = True
|
||||
|
@ -364,7 +366,8 @@ def firewall_upnp(action='status', no_refresh=False):
|
|||
if upnpc.getspecificportmapping(port, protocol):
|
||||
try:
|
||||
upnpc.deleteportmapping(port, protocol)
|
||||
except: pass
|
||||
except:
|
||||
pass
|
||||
if not enabled:
|
||||
continue
|
||||
try:
|
||||
|
@ -444,12 +447,14 @@ def _get_ssh_port(default=22):
|
|||
pass
|
||||
return default
|
||||
|
||||
|
||||
def _update_firewall_file(rules):
|
||||
"""Make a backup and write new rules to firewall file"""
|
||||
os.system("cp {0} {0}.old".format(firewall_file))
|
||||
with open(firewall_file, 'w') as f:
|
||||
yaml.safe_dump(rules, f, default_flow_style=False)
|
||||
|
||||
|
||||
def _on_rule_command_error(returncode, cmd, output):
|
||||
"""Callback for rules commands error"""
|
||||
# Log error and continue commands execution
|
||||
|
|
|
@ -87,7 +87,7 @@ def monitor_disk(units=None, mountpoint=None, human_readable=False):
|
|||
# Retrieve monitoring for unit(s)
|
||||
for u in units:
|
||||
if u == 'io':
|
||||
## Define setter
|
||||
# Define setter
|
||||
if len(units) > 1:
|
||||
def _set(dn, dvalue):
|
||||
try:
|
||||
|
@ -111,7 +111,7 @@ def monitor_disk(units=None, mountpoint=None, human_readable=False):
|
|||
for dname in devices_names:
|
||||
_set(dname, 'not-available')
|
||||
elif u == 'filesystem':
|
||||
## Define setter
|
||||
# Define setter
|
||||
if len(units) > 1:
|
||||
def _set(dn, dvalue):
|
||||
try:
|
||||
|
|
|
@ -315,6 +315,7 @@ def service_regen_conf(names=[], with_diff=False, force=False, dry_run=False,
|
|||
|
||||
# Execute hooks for pre-regen
|
||||
pre_args = ['pre', ] + common_args
|
||||
|
||||
def _pre_call(name, priority, path, args):
|
||||
# create the pending conf directory for the service
|
||||
service_pending_path = os.path.join(pending_conf_dir, name)
|
||||
|
@ -336,7 +337,7 @@ def service_regen_conf(names=[], with_diff=False, force=False, dry_run=False,
|
|||
# Iterate over services and process pending conf
|
||||
for service, conf_files in _get_pending_conf(names).items():
|
||||
logger.info(m18n.n(
|
||||
'service_regenconf_pending_applying' if not dry_run else \
|
||||
'service_regenconf_pending_applying' if not dry_run else
|
||||
'service_regenconf_dry_pending_applying',
|
||||
service=service))
|
||||
|
||||
|
@ -444,7 +445,7 @@ def service_regen_conf(names=[], with_diff=False, force=False, dry_run=False,
|
|||
continue
|
||||
elif not failed_regen:
|
||||
logger.success(m18n.n(
|
||||
'service_conf_updated' if not dry_run else \
|
||||
'service_conf_updated' if not dry_run else
|
||||
'service_conf_would_be_updated',
|
||||
service=service))
|
||||
if succeed_regen and not dry_run:
|
||||
|
@ -462,6 +463,7 @@ def service_regen_conf(names=[], with_diff=False, force=False, dry_run=False,
|
|||
|
||||
# Execute hooks for post-regen
|
||||
post_args = ['post', ] + common_args
|
||||
|
||||
def _pre_call(name, priority, path, args):
|
||||
# append coma-separated applied changes for the service
|
||||
if name in result and result[name]['applied']:
|
||||
|
@ -556,7 +558,8 @@ def _tail(file, n, offset=None):
|
|||
return lines[-to_read:offset and -offset or None]
|
||||
avg_line_length *= 1.3
|
||||
|
||||
except IOError: return []
|
||||
except IOError:
|
||||
return []
|
||||
|
||||
|
||||
def _get_files_diff(orig_file, new_file, as_string=False, skip_header=True):
|
||||
|
|
|
@ -192,7 +192,6 @@ def user_create(auth, username, firstname, lastname, mail, password,
|
|||
raise MoulinetteError(errno.EPERM,
|
||||
m18n.n('ssowat_persistent_conf_write_error', error=e.strerror))
|
||||
|
||||
|
||||
if auth.add(rdn, attr_dict):
|
||||
# Invalidate passwd to take user creation into account
|
||||
subprocess.call(['nscd', '-i', 'passwd'])
|
||||
|
@ -238,8 +237,10 @@ def user_delete(auth, username, purge=False):
|
|||
|
||||
# Update SFTP user group
|
||||
memberlist = auth.search(filter='cn=sftpusers', attrs=['memberUid'])[0]['memberUid']
|
||||
try: memberlist.remove(username)
|
||||
except: pass
|
||||
try:
|
||||
memberlist.remove(username)
|
||||
except:
|
||||
pass
|
||||
if auth.update('cn=sftpusers,ou=groups', {'memberUid': memberlist}):
|
||||
if purge:
|
||||
subprocess.call(['rm', '-rf', '/home/{0}'.format(username)])
|
||||
|
@ -445,6 +446,7 @@ def user_info(auth, username):
|
|||
else:
|
||||
raise MoulinetteError(167, m18n.n('user_info_failed'))
|
||||
|
||||
|
||||
def _convertSize(num, suffix=''):
|
||||
for unit in ['K', 'M', 'G', 'T', 'P', 'E', 'Z']:
|
||||
if abs(num) < 1024.0:
|
||||
|
|
|
@ -424,6 +424,7 @@ def get_installed_version(*pkgnames, **kwargs):
|
|||
return versions[pkgnames[0]]
|
||||
return versions
|
||||
|
||||
|
||||
def meets_version_specifier(pkgname, specifier):
|
||||
"""Check if a package installed version meets specifier"""
|
||||
spec = SpecifierSet(specifier)
|
||||
|
|
16
src/yunohost/vendor/acme_tiny/acme_tiny.py
vendored
16
src/yunohost/vendor/acme_tiny/acme_tiny.py
vendored
|
@ -1,5 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
import argparse, subprocess, json, os, sys, base64, binascii, time, hashlib, re, copy, textwrap, logging
|
||||
import argparse
|
||||
import subprocess
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import base64
|
||||
import binascii
|
||||
import time
|
||||
import hashlib
|
||||
import re
|
||||
import copy
|
||||
import textwrap
|
||||
import logging
|
||||
try:
|
||||
from urllib.request import urlopen # Python 3
|
||||
except ImportError:
|
||||
|
@ -12,6 +24,7 @@ LOGGER = logging.getLogger(__name__)
|
|||
LOGGER.addHandler(logging.StreamHandler())
|
||||
LOGGER.setLevel(logging.INFO)
|
||||
|
||||
|
||||
def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA):
|
||||
# helper function base64 encode for jose spec
|
||||
def _b64(b):
|
||||
|
@ -165,6 +178,7 @@ def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA):
|
|||
return """-----BEGIN CERTIFICATE-----\n{0}\n-----END CERTIFICATE-----\n""".format(
|
||||
"\n".join(textwrap.wrap(base64.b64encode(result).decode('utf8'), 64)))
|
||||
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
|
|
Loading…
Add table
Reference in a new issue