Projects
Kolab:16
pykolab
0003-Fix-unicode-in-roundcube-config-templates....
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0003-Fix-unicode-in-roundcube-config-templates.patch of Package pykolab (Revision 28)
Currently displaying revision
28
,
Show latest
From 423c0ead53fa34c3f0ddc7c987ad66b121cce6ca Mon Sep 17 00:00:00 2001 From: "Jeroen van Meeuwen (Kolab Systems)" <vanmeeuwen@kolabsys.com> Date: Tue, 21 May 2019 17:36:34 +0200 Subject: [PATCH 3/3] Fix unicode in roundcube config templates --- pykolab/setup/setup_roundcube.py | 229 +++++++++++++++++-------------- pykolab/translate.py | 21 ++- 2 files changed, 142 insertions(+), 108 deletions(-) diff --git a/pykolab/setup/setup_roundcube.py b/pykolab/setup/setup_roundcube.py index 9b6d664..9c0c347 100644 --- a/pykolab/setup/setup_roundcube.py +++ b/pykolab/setup/setup_roundcube.py @@ -17,7 +17,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -from Cheetah.Template import Template import grp import hashlib import os @@ -27,6 +26,8 @@ import subprocess import sys import time +from Cheetah.Template import Template + import components import pykolab @@ -38,63 +39,66 @@ from pykolab.translate import _ log = pykolab.getLogger('pykolab.setup') conf = pykolab.getConf() + def __init__(): - components.register('roundcube', execute, description=description(), after=['mysql','ldap']) + components.register('roundcube', execute, description=description(), after=['mysql', 'ldap']) + def description(): return _("Setup Roundcube.") + def execute(*args, **kw): print >> sys.stderr, utils.multiline_message( - _(""" - Please supply a password for the MySQL user 'roundcube'. - This password will be used by the Roundcube webmail - interface. - """) - ) + _(""" + Please supply a password for the MySQL user 'roundcube'. + This password will be used by the Roundcube webmail + interface. + """) + ) mysql_roundcube_password = utils.ask_question( - _("MySQL roundcube password"), - default=utils.generate_password(), - password=True, - confirm=True - ) + _("MySQL roundcube password"), + default=utils.generate_password(), + password=True, + confirm=True + ) conf.mysql_roundcube_password = mysql_roundcube_password rc_settings = { - 'des_key': re.sub( - r'[^a-zA-Z0-9]', - "", - "%s%s" % ( - hashlib.md5("%s" % random.random()).digest().encode("base64"), - hashlib.md5("%s" % random.random()).digest().encode("base64") - ) - )[:24], - - 'imap_admin_login': conf.get('cyrus-imap', 'admin_login'), - 'imap_admin_password': conf.get('cyrus-imap', 'admin_password'), - 'ldap_base_dn': conf.get('ldap', 'base_dn'), - 'ldap_group_base_dn': conf.get('ldap', 'group_base_dn'), - 'ldap_group_filter': conf.get('ldap', 'group_filter'), - 'ldap_ldap_uri': conf.get('ldap', 'ldap_uri'), - 'ldap_resource_base_dn': conf.get('ldap', 'resource_base_dn'), - 'ldap_resource_filter': conf.get('ldap', 'resource_filter'), - 'ldap_service_bind_dn': conf.get('ldap', 'service_bind_dn'), - 'ldap_service_bind_pw': conf.get('ldap', 'service_bind_pw'), - 'ldap_user_base_dn': conf.get('ldap', 'user_base_dn'), - 'ldap_user_filter': conf.get('ldap', 'user_filter'), - 'primary_domain': conf.get('kolab','primary_domain'), - 'mysql_uri': 'mysqli://roundcube:%s@localhost/roundcube' % (mysql_roundcube_password), - 'conf': conf - } + 'des_key': re.sub( + r'[^a-zA-Z0-9]', + "", + "%s%s" % ( + hashlib.md5("%s" % random.random()).digest().encode("base64"), + hashlib.md5("%s" % random.random()).digest().encode("base64") + ) + )[:24], + + 'imap_admin_login': conf.get('cyrus-imap', 'admin_login'), + 'imap_admin_password': conf.get('cyrus-imap', 'admin_password'), + 'ldap_base_dn': conf.get('ldap', 'base_dn'), + 'ldap_group_base_dn': conf.get('ldap', 'group_base_dn'), + 'ldap_group_filter': conf.get('ldap', 'group_filter'), + 'ldap_ldap_uri': conf.get('ldap', 'ldap_uri'), + 'ldap_resource_base_dn': conf.get('ldap', 'resource_base_dn'), + 'ldap_resource_filter': conf.get('ldap', 'resource_filter'), + 'ldap_service_bind_dn': conf.get('ldap', 'service_bind_dn'), + 'ldap_service_bind_pw': conf.get('ldap', 'service_bind_pw'), + 'ldap_user_base_dn': conf.get('ldap', 'user_base_dn'), + 'ldap_user_filter': conf.get('ldap', 'user_filter'), + 'primary_domain': conf.get('kolab', 'primary_domain'), + 'mysql_uri': 'mysqli://roundcube:%s@localhost/roundcube' % (mysql_roundcube_password), + 'conf': conf + } rc_paths = [ - "/usr/share/roundcubemail/", - "/usr/share/roundcube/", - "/srv/www/roundcubemail/", - "/var/www/roundcubemail/" - ] + "/usr/share/roundcubemail/", + "/usr/share/roundcube/", + "/srv/www/roundcubemail/", + "/var/www/roundcubemail/" + ] rcpath = '' for rc_path in rc_paths: @@ -114,22 +118,22 @@ def execute(*args, **kw): rc_settings['skin'] = 'larry' want_files = [ - 'acl.inc.php', - 'calendar.inc.php', - 'config.inc.php', - 'kolab_addressbook.inc.php', - 'kolab_auth.inc.php', - 'kolab_delegation.inc.php', - 'kolab_files.inc.php', - 'kolab_folders.inc.php', - 'libkolab.inc.php', - 'managesieve.inc.php', - 'owncloud.inc.php', - 'password.inc.php', - 'recipient_to_contact.inc.php', - 'terms.html', - 'terms.inc.php' - ] + 'acl.inc.php', + 'calendar.inc.php', + 'config.inc.php', + 'kolab_addressbook.inc.php', + 'kolab_auth.inc.php', + 'kolab_delegation.inc.php', + 'kolab_files.inc.php', + 'kolab_folders.inc.php', + 'libkolab.inc.php', + 'managesieve.inc.php', + 'owncloud.inc.php', + 'password.inc.php', + 'recipient_to_contact.inc.php', + 'terms.html', + 'terms.inc.php' + ] for want_file in want_files: template_file = None @@ -137,29 +141,30 @@ def execute(*args, **kw): template_file = '/etc/kolab/templates/roundcubemail/%s.tpl' % (want_file) elif os.path.isfile('/usr/share/kolab/templates/roundcubemail/%s.tpl' % (want_file)): template_file = '/usr/share/kolab/templates/roundcubemail/%s.tpl' % (want_file) - elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'roundcubemail', '%s.tpl' % (want_file)))): - template_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'roundcubemail', '%s.tpl' % (want_file))) - if not template_file == None: + if template_file is not None: log.debug(_("Using template file %r") % (template_file), level=8) - fp = open(template_file, 'r') + fp = codecs.open(template_file, 'r', encoding='utf-8') template_definition = fp.read() fp.close() t = Template(template_definition, searchList=[rc_settings]) log.debug( - _("Successfully compiled template %r, writing out to %r") % (template_file, want_file), - level=8 - ) + _("Successfully compiled template %r, writing out to %r") % ( + template_file, + want_file + ), + level=8 + ) fp = None if os.path.isdir('/etc/roundcubemail'): - fp = open('/etc/roundcubemail/%s' % (want_file), 'w') + fp = codecs.open('/etc/roundcubemail/%s' % (want_file), 'w', encoding='utf-8') elif os.path.isdir('/etc/roundcube'): - fp = open('/etc/roundcube/%s' % (want_file), 'w') + fp = codecs.open('/etc/roundcube/%s' % (want_file), 'w', encoding='utf-8') - if not fp == None: - fp.write(t.__str__()) + if fp is not None: + fp.write(unicode(t())) fp.close() schema_files = [] @@ -167,41 +172,42 @@ def execute(*args, **kw): directories.sort() for directory in directories: if directory.startswith("roundcubemail"): - for nested_root, nested_directories, nested_filenames in os.walk(os.path.join(root, directory)): - for filename in nested_filenames: + for _root, _directories, _filenames in os.walk(os.path.join(root, directory)): + for filename in _filenames: if filename.startswith('mysql.initial') and filename.endswith('.sql'): - schema_filepath = os.path.join(nested_root,filename) - if not schema_filepath in schema_files: + schema_filepath = os.path.join(_root, filename) + if schema_filepath not in schema_files: schema_files.append(schema_filepath) if len(schema_files) > 0: break + if len(schema_files) > 0: break for root, directories, filenames in os.walk(rcpath + 'plugins/calendar/drivers/kolab/'): for filename in filenames: if filename.startswith('mysql') and filename.endswith('.sql'): - schema_filepath = os.path.join(root,filename) - if not schema_filepath in schema_files: + schema_filepath = os.path.join(root, filename) + if schema_filepath not in schema_files: schema_files.append(schema_filepath) for root, directories, filenames in os.walk(rcpath + 'plugins/libkolab/'): for filename in filenames: if filename.startswith('mysql') and filename.endswith('.sql'): - schema_filepath = os.path.join(root,filename) - if not schema_filepath in schema_files: + schema_filepath = os.path.join(root, filename) + if schema_filepath not in schema_files: schema_files.append(schema_filepath) for root, directories, filenames in os.walk('/usr/share/doc/'): directories.sort() for directory in directories: if directory.startswith("chwala"): - for nested_root, nested_directories, nested_filenames in os.walk(os.path.join(root, directory)): - for filename in nested_filenames: + for _root, _directories, _filenames in os.walk(os.path.join(root, directory)): + for filename in _filenames: if filename.startswith('mysql.initial') and filename.endswith('.sql'): - schema_filepath = os.path.join(nested_root,filename) - if not schema_filepath in schema_files: + schema_filepath = os.path.join(_root, filename) + if schema_filepath not in schema_files: schema_files.append(schema_filepath) if len(schema_files) > 0: @@ -210,14 +216,9 @@ def execute(*args, **kw): break if not os.path.isfile('/tmp/kolab-setup-my.cnf'): - utils.multiline_message( - """Please supply the MySQL root password""" - ) + utils.multiline_message("""Please supply the MySQL root password""") - mysql_root_password = utils.ask_question( - _("MySQL root password"), - password=True - ) + mysql_root_password = utils.ask_question(_("MySQL root password"), password=True) data = """ [mysql] @@ -226,7 +227,7 @@ password='%s' """ % (mysql_root_password) fp = open('/tmp/kolab-setup-my.cnf', 'w') - os.chmod('/tmp/kolab-setup-my.cnf', 0600) + os.chmod('/tmp/kolab-setup-my.cnf', 600) fp.write(data) fp.close() @@ -235,14 +236,30 @@ password='%s' p1.stdout.close() p2.communicate() - p1 = subprocess.Popen(['echo', 'GRANT ALL PRIVILEGES ON roundcube.* TO \'roundcube\'@\'localhost\' IDENTIFIED BY \'%s\';' % (mysql_roundcube_password)], stdout=subprocess.PIPE) + p1 = subprocess.Popen( + [ + 'echo', + 'GRANT ALL PRIVILEGES ON roundcube.* TO \'roundcube\'@\'localhost\' IDENTIFIED BY \'%s\';' % ( + mysql_roundcube_password + ) + ], + stdout=subprocess.PIPE + ) p2 = subprocess.Popen(['mysql', '--defaults-file=/tmp/kolab-setup-my.cnf'], stdin=p1.stdout) p1.stdout.close() p2.communicate() for schema_file in schema_files: p1 = subprocess.Popen(['cat', schema_file], stdout=subprocess.PIPE) - p2 = subprocess.Popen(['mysql', '--defaults-file=/tmp/kolab-setup-my.cnf', 'roundcube'], stdin=p1.stdout) + p2 = subprocess.Popen( + [ + 'mysql', + '--defaults-file=/tmp/kolab-setup-my.cnf', + 'roundcube' + ], + stdin=p1.stdout + ) + p1.stdout.close() p2.communicate() @@ -267,11 +284,13 @@ password='%s' webserver_gid = None - for webserver_group in [ 'apache', 'www-data', 'www' ]: + for webserver_group in ['apache', 'www-data', 'www']: try: - (a,b,webserver_gid,c) = grp.getgrnam(webserver_group) + (_, _, webserver_gid, _) = grp.getgrnam(webserver_group) break - except Exception, errmsg: + + # pylint: disable=broad-except + except Exception: pass if webserver_gid is not None: @@ -280,11 +299,13 @@ password='%s' for filename in filenames: try: os.chown( - os.path.join(root, filename), - root_uid, - webserver_gid - ) - except Exception, errmsg: + os.path.join(root, filename), + root_uid, + webserver_gid + ) + + # pylint: disable=broad-except + except Exception: pass httpservice = 'httpd.service' @@ -300,7 +321,7 @@ password='%s' elif os.path.isfile('/sbin/service'): subprocess.call(['/sbin/service', 'httpd', 'restart']) elif os.path.isfile('/usr/sbin/service'): - subprocess.call(['/usr/sbin/service','apache2','restart']) + subprocess.call(['/usr/sbin/service', 'apache2', 'restart']) else: log.error(_("Could not start the webserver server service.")) @@ -311,6 +332,6 @@ password='%s' elif os.path.isfile('/usr/sbin/update-rc.d'): subprocess.call(['/usr/sbin/update-rc.d', 'apache2', 'defaults']) else: - log.error(_("Could not configure to start on boot, the " + \ - "webserver server service.")) - + log.error( + _("Could not configure to start on boot, the webserver server service.") + ) diff --git a/pykolab/translate.py b/pykolab/translate.py index 7bac219..d2eb0ca 100644 --- a/pykolab/translate.py +++ b/pykolab/translate.py @@ -25,19 +25,24 @@ except ImportError: import gettext import os -N_ = lambda x: x +N_ = lambda x: x # noqa: E731 # This function as such may, at times, cause tracebacks. -#_ = lambda x: current.lgettext(x) +# _ = lambda x: current.lgettext(x) +# pylint: disable=invalid-name current = gettext.translation(domain, fallback=True) + def _(x): try: return current.lgettext(x) - except Exception, errmsg: + + # pylint: disable=broad-except + except Exception: return x + def getDefaultLangs(): languages = [] for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): @@ -51,24 +56,32 @@ def getDefaultLangs(): # now normalize and expand the languages nelangs = [] for lang in languages: + + # pylint: disable=protected-access for nelang in gettext._expand_lang(lang): if nelang not in nelangs: nelangs.append(nelang) return nelangs + def setUserLanguage(lang): + # pylint: disable=global-statement global current if not len(lang.split('.')) > 1 and not lang.endswith('.UTF-8'): lang = "%s.UTF-8" % (lang) langs = [] + + # pylint: disable=protected-access for l in gettext._expand_lang(lang): if l not in langs: langs.append(l) try: current = gettext.translation(domain, languages=langs, fallback=True) - except: + + # pylint: disable=broad-except + except Exception: pass -- 2.21.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.