Skip to content

Commit 46aec6e

Browse files
committed
Python2/3 compatibility: tentative version of create_group_wikis; may need more work.
- Legacy-Id: 16459
1 parent 8c6eb3a commit 46aec6e

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

ietf/utils/management/commands/create_group_wikis.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import os
88
import copy
99
import io
10-
import syslog
1110
import pkg_resources
11+
import six
12+
import syslog
1213

1314
from trac.core import TracError
1415
from trac.env import Environment
@@ -29,7 +30,7 @@
2930

3031
logtag = __name__.split('.')[-1]
3132
logname = "user.log"
32-
syslog.openlog(logtag, syslog.LOG_PID, syslog.LOG_USER)
33+
syslog.openlog(str(logtag), syslog.LOG_PID, syslog.LOG_USER)
3334

3435
class Command(BaseCommand):
3536
help = "Create group wikis for WGs, RGs and Areas which don't have one."
@@ -64,9 +65,10 @@ def do_cmd(self, cmd, *args):
6465
else:
6566
self.note("Running %s %s ..." % (os.path.basename(cmd), " ".join(quoted_args)))
6667
command = [ cmd, ] + list(args)
68+
command = ' '.join(command).encode('utf-8')
6769
code, out, err = pipe(command)
68-
out = out.decode()
69-
err = err.decode()
70+
out = out.decode('utf-8')
71+
err = err.decode('utf-8')
7072
msg = None
7173
if code != 0:
7274
msg = "Error %s: %s when executing '%s'" % (code, err, " ".join(command))
@@ -88,9 +90,8 @@ def create_svn(self, svn):
8890
return msg
8991
err, out= self.svn_admin_cmd("create", svn )
9092
if err:
91-
msg = "Error %s creating svn repository %s:\n %s" % (err, svn, out)
92-
self.log(msg)
93-
return msg
93+
self.log(err)
94+
return err
9495
return ""
9596

9697
# --- trac ---
@@ -137,8 +138,8 @@ def add_default_wiki_pages(self, env):
137138
name = unicode_unquote(name.encode('utf-8'))
138139
if os.path.isfile(filename):
139140
self.note(" Adding page %s" % name)
140-
with io.open(filename) as file:
141-
text = file.read().decode('utf-8')
141+
with io.open(filename, encoding='utf-8') as file:
142+
text = file.read()
142143
self.add_wiki_page(env, name, text)
143144

144145
def add_custom_wiki_pages(self, group, env):
@@ -208,7 +209,7 @@ def create_group_trac(self, group):
208209
sect, key, val = options[i]
209210
val = val.format(**group.__dict__)
210211
options[i] = sect, key, val
211-
# Try to creat ethe environment, remove unwanted defaults, and add
212+
# Try to create the environment, remove unwanted defaults, and add
212213
# custom pages and settings.
213214
if self.dummy_run:
214215
self.note("Would create Trac for group '%s' at %s" % (group.acronym, group.trac_dir))
@@ -327,13 +328,13 @@ def handle(self, *filenames, **options):
327328
self.svn_dir_pattern = options.get('svn_dir_pattern', settings.TRAC_SVN_DIR_PATTERN)
328329
self.group_list = options.get('group_list', None)
329330
self.dummy_run = options.get('dummy_run', False)
330-
self.wiki_dir_pattern = os.path.join(settings.BASE_DIR, '..', self.wiki_dir_pattern)
331+
self.wiki_dir_pattern = os.path.join(str(settings.BASE_DIR), str('..'), self.wiki_dir_pattern)
331332
self.svn_dir_pattern = os.path.join(settings.BASE_DIR, '..', self.svn_dir_pattern)
332333

333334
if not self.group_list is None:
334335
self.group_list = self.group_list.split('.')
335336

336-
if isinstance(self.verbosity, (type(""), type(""))) and self.verbosity.isdigit():
337+
if isinstance(self.verbosity, six.string_types) and self.verbosity.isdigit():
337338
self.verbosity = int(self.verbosity)
338339

339340
if self.dummy_run and self.verbosity < 2:

0 commit comments

Comments
 (0)