comparison roundup/init.py @ 6011:8bd93c8e98a6

Flake8 cleanup. remove unused imports; formatting fixes. Also #noqa some one liners of the form: if boolean_expression: command
author John Rouillard <rouilj@ieee.org>
date Tue, 31 Dec 2019 21:28:27 -0500
parents 64b05e24dbd8
children 8219c7405a29
comparison
equal deleted inserted replaced
6010:8ccb41b477d1 6011:8bd93c8e98a6
21 __docformat__ = 'restructuredtext' 21 __docformat__ = 'restructuredtext'
22 22
23 import os, errno, email.parser 23 import os, errno, email.parser
24 24
25 25
26 from roundup import install_util, password 26 from roundup import install_util
27 from roundup.configuration import CoreConfig 27 from roundup.configuration import CoreConfig
28 from roundup.i18n import _ 28 from roundup.i18n import _
29
29 30
30 def copytree(src, dst, symlinks=0): 31 def copytree(src, dst, symlinks=0):
31 """Recursively copy a directory tree using copyDigestedFile(). 32 """Recursively copy a directory tree using copyDigestedFile().
32 33
33 The destination directory is allowed to exist. 34 The destination directory is allowed to exist.
43 # Prevent 'hidden' files (those starting with '.') from being considered. 44 # Prevent 'hidden' files (those starting with '.') from being considered.
44 names = [f for f in os.listdir(src) if not f.startswith('.')] 45 names = [f for f in os.listdir(src) if not f.startswith('.')]
45 try: 46 try:
46 os.mkdir(dst) 47 os.mkdir(dst)
47 except OSError as error: 48 except OSError as error:
48 if error.errno != errno.EEXIST: raise 49 if error.errno != errno.EEXIST: raise # noqa
49 for name in names: 50 for name in names:
50 srcname = os.path.join(src, name) 51 srcname = os.path.join(src, name)
51 dstname = os.path.join(dst, name) 52 dstname = os.path.join(dst, name)
52 if symlinks and os.path.islink(srcname): 53 if symlinks and os.path.islink(srcname):
53 linkto = os.readlink(srcname) 54 linkto = os.readlink(srcname)
54 os.symlink(linkto, dstname) 55 os.symlink(linkto, dstname)
55 elif os.path.isdir(srcname): 56 elif os.path.isdir(srcname):
56 copytree(srcname, dstname, symlinks) 57 copytree(srcname, dstname, symlinks)
57 else: 58 else:
58 install_util.copyDigestedFile(srcname, dstname) 59 install_util.copyDigestedFile(srcname, dstname)
60
59 61
60 def install(instance_home, template, settings={}): 62 def install(instance_home, template, settings={}):
61 '''Install an instance using the named template and backend. 63 '''Install an instance using the named template and backend.
62 64
63 'instance_home' 65 'instance_home'
120 ti = loadTemplateInfo(idir) 122 ti = loadTemplateInfo(idir)
121 if ti: 123 if ti:
122 ret[ti['name']] = ti 124 ret[ti['name']] = ti
123 return ret 125 return ret
124 126
127
125 def loadTemplateInfo(path): 128 def loadTemplateInfo(path):
126 ''' Attempt to load a Roundup template from the indicated directory. 129 ''' Attempt to load a Roundup template from the indicated directory.
127 130
128 Return None if there's no template, otherwise a template info 131 Return None if there's no template, otherwise a template info
129 dictionary. 132 dictionary.
132 if not os.path.exists(tif): 135 if not os.path.exists(tif):
133 return None 136 return None
134 137
135 if os.path.exists(os.path.join(path, 'config.py')): 138 if os.path.exists(os.path.join(path, 'config.py')):
136 print(_("WARNING: directory '%s'\n" 139 print(_("WARNING: directory '%s'\n"
137 "\tcontains old-style template - ignored" 140 "\tcontains old-style template - ignored")
138 ) % os.path.abspath(path)) 141 % os.path.abspath(path))
139 return None 142 return None
140 143
141 # load up the template's information 144 # load up the template's information
142 try: 145 try:
143 f = open(tif) 146 f = open(tif)
149 ti['path'] = path 152 ti['path'] = path
150 finally: 153 finally:
151 f.close() 154 f.close()
152 return ti 155 return ti
153 156
157
154 def writeHeader(name, value): 158 def writeHeader(name, value):
155 ''' Write an rfc822-compatible header line, making it wrap reasonably 159 ''' Write an rfc822-compatible header line, making it wrap reasonably
156 ''' 160 '''
157 out = [name.capitalize() + ':'] 161 out = [name.capitalize() + ':']
158 n = len(out[0]) 162 n = len(out[0])
161 out.append('\n') 165 out.append('\n')
162 n = 0 166 n = 0
163 out.append(' ' + word) 167 out.append(' ' + word)
164 n += len(out[-1]) 168 n += len(out[-1])
165 return ''.join(out) + '\n' 169 return ''.join(out) + '\n'
170
166 171
167 def saveTemplateInfo(dir, info): 172 def saveTemplateInfo(dir, info):
168 ''' Save the template info (dict of values) to the TEMPLATE-INFO.txt 173 ''' Save the template info (dict of values) to the TEMPLATE-INFO.txt
169 file in the indicated directory. 174 file in the indicated directory.
170 ''' 175 '''

Roundup Issue Tracker: http://roundup-tracker.org/