Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More cleanups + yinst removal since nobody has that...

  • Loading branch information...
commit 0d9038deccf891e34f92f1dd79c588ef794de842 1 parent 9b38067
Joshua Harlow harlowja authored
1  build.py
@@ -27,7 +27,6 @@
27 27 import tempfile
28 28 import traceback
29 29 import urllib
30   -import urllib2
31 30 import uuid
32 31
33 32 from contextlib import (closing, contextmanager)
5 builder/downloader/tar_ball.py
@@ -28,7 +28,8 @@ def __init__(self, config):
28 28 self.root_file = config.get('root_file')
29 29
30 30 def _check_cache(self):
31   - cache_name = util.hash_blob(self.where_from, 'md5', mlen=8)
  31 + cache_name = util.hash_blob(self.where_from, 'md5')
  32 + cache_name = cache_name[0:8]
32 33 full_pth = os.path.join(self.cache_dir, "%s.tar.gz" % (cache_name))
33 34 if os.path.isfile(full_pth):
34 35 return (full_pth, True)
@@ -46,7 +47,7 @@ def _adjust_real_root(self, arch_path):
46 47 if not root_gz:
47 48 raise RuntimeError(("Needed file %r not found in"
48 49 " extracted contents of %s")
49   - % (self.root_file, cache_pth))
  50 + % (self.root_file, arch_path))
50 51 else:
51 52 util.copy(root_gz, arch_path)
52 53 return arch_path
6 builder/modules/add_user.py
@@ -15,9 +15,6 @@
15 15 # under the License.
16 16
17 17
18   -
19   -import os
20   -
21 18 from builder import util
22 19
23 20
@@ -30,6 +27,5 @@ def modify(name, root, cfg):
30 27 (util.quote(name)))
31 28 for uname in user_names:
32 29 cmd = ['chroot', root,
33   - 'yinst', 'i', '-yes',
34   - 'admin/sudo-%s' % (uname)]
  30 + 'useradd', '-m', str(uname)]
35 31 util.subp(cmd, capture=False)
102 builder/util.py
@@ -18,24 +18,16 @@
18 18
19 19 import contextlib
20 20 import errno
21   -import grp
22   -import gzip
23 21 import hashlib
24 22 import os
25   -import platform
26   -import pwd
27 23 import random
28 24 import shutil
29   -import stat
30   -import string # pylint: disable=W0402
31 25 import subprocess
32 26 import sys
33 27 import tempfile
34 28 import time
35 29 import types
36 30 import urllib2
37   -import urllib
38   -import urlparse
39 31
40 32 import progressbar
41 33 import termcolor
@@ -113,16 +105,6 @@ def quote(data, quote_color='green'):
113 105 return color(text, quote_color)
114 106
115 107
116   -def format(data, params):
117   - text = str(data)
118   -
119   - def replacer(match):
120   - param_name = match.group(1)
121   - return color(params[param_name], color=match.group(2).strip())
122   -
123   - return re.sub(r"\{([\w\d]+):(.*)\}", replacer, text)
124   -
125   -
126 108 def color(data, color, bold=False, underline=False, blink=False):
127 109 text = str(data)
128 110 text_attrs = list()
@@ -139,18 +121,12 @@ def color(data, color, bold=False, underline=False, blink=False):
139 121
140 122
141 123 def find_file(name, path):
142   - for (root, dirs, files) in os.walk(path):
  124 + for (root, _dirs, files) in os.walk(path):
143 125 if name in files:
144 126 return os.path.join(root, name)
145 127 return None
146 128
147 129
148   -def rand_str(strlen=32, select_from=None):
149   - if not select_from:
150   - select_from = string.letters + string.digits
151   - return "".join([random.choice(select_from) for _x in range(0, strlen)])
152   -
153   -
154 130 def download_url(url, where_to, timeout=5):
155 131 with contextlib.closing(urllib2.urlopen(url, timeout=timeout)) as rh:
156 132 status = rh.getcode()
@@ -216,28 +192,6 @@ def progress_cb(tran_byte_am, chunk):
216 192 pbar.finish()
217 193
218 194
219   -def make_url(scheme, host, port=None,
220   - path='', params='', query='', fragment=''):
221   -
222   - pieces = []
223   - pieces.append(scheme or '')
224   -
225   - netloc = ''
226   - if host:
227   - netloc = str(host)
228   -
229   - if port is not None:
230   - netloc += ":" + "%s" % (port)
231   -
232   - pieces.append(netloc or '')
233   - pieces.append(path or '')
234   - pieces.append(params or '')
235   - pieces.append(query or '')
236   - pieces.append(fragment or '')
237   -
238   - return urlparse.urlunparse(pieces)
239   -
240   -
241 195 def obj_name(obj):
242 196 if isinstance(obj, (types.TypeType,
243 197 types.ModuleType,
@@ -248,17 +202,6 @@ def obj_name(obj):
248 202
249 203
250 204 @contextlib.contextmanager
251   -def chdir(ndir):
252   - curr = os.getcwd()
253   - try:
254   - os.chdir(ndir)
255   - yield ndir
256   - finally:
257   - os.chdir(curr)
258   -
259   -
260   -
261   -@contextlib.contextmanager
262 205 def tempdir(**kwargs):
263 206 # This seems like it was only added in python 3.2
264 207 # Make it since its useful...
@@ -270,26 +213,21 @@ def tempdir(**kwargs):
270 213 del_dir(tdir)
271 214
272 215
273   -def center(text, fill, max_len):
274   - return '{0:{fill}{align}{size}}'.format(text, fill=fill,
275   - align="^", size=max_len)
276   -
277   -
278 216 def del_dir(path):
279 217 shutil.rmtree(path)
280 218
281 219
282 220 def load_file(fname, read_cb=None, quiet=False):
283   - ofh = StringIO()
  221 + contents = None
284 222 try:
285 223 with open(fname, 'rb') as ifh:
  224 + ofh = StringIO()
286 225 pipe_in_out(ifh, ofh, chunk_cb=read_cb)
  226 + contents = ofh.getvalue()
287 227 except IOError as e:
288 228 if not quiet:
289   - raise
290   - if e.errno != errno.ENOENT:
291   - raise
292   - contents = ofh.getvalue()
  229 + if e.errno != errno.ENOENT:
  230 + raise
293 231 return contents
294 232
295 233
@@ -321,18 +259,10 @@ def print_iterable(to_log, header=None, do_color=True):
321 259 print("|-- %s" % (c))
322 260
323 261
324   -def hash_blob(blob, routine, mlen=None):
  262 +def hash_blob(blob, routine):
325 263 hasher = hashlib.new(routine)
326 264 hasher.update(blob)
327   - digest = hasher.hexdigest()
328   - if mlen is not None:
329   - return digest[0:mlen]
330   - else:
331   - return digest
332   -
333   -
334   -def rename(src, dest):
335   - os.rename(src, dest)
  265 + return hasher.hexdigest()
336 266
337 267
338 268 def ensure_dirs(dirlist, mode=0755):
@@ -340,15 +270,8 @@ def ensure_dirs(dirlist, mode=0755):
340 270 ensure_dir(d, mode)
341 271
342 272
343   -def load_yaml(blob, allowed=(dict,)):
344   - blob = str(blob)
345   - converted = yaml.safe_load(blob)
346   - if not isinstance(converted, allowed):
347   - raise TypeError(("Yaml load allows %s root types,"
348   - " but got %s instead") %
349   - (allowed, obj_name(converted)))
350   - loaded = converted
351   - return loaded
  273 +def load_yaml(blob):
  274 + return yaml.safe_load(str(blob))
352 275
353 276
354 277 def ensure_dir(path, mode=None):
@@ -356,14 +279,9 @@ def ensure_dir(path, mode=None):
356 279 os.makedirs(path)
357 280 chmod(path, mode)
358 281 else:
359   - # Just adjust the mode
360 282 chmod(path, mode)
361 283
362 284
363   -def sym_link(source, link):
364   - os.symlink(source, link)
365   -
366   -
367 285 def del_file(path):
368 286 try:
369 287 os.unlink(path)
17 checks.sh
... ... @@ -0,0 +1,17 @@
  1 +#!/bin/bash
  2 +
  3 +function find_src {
  4 + files=`find builder -type f | grep "py\$"`
  5 + echo "build.py $files"
  6 +}
  7 +
  8 +function run_pylint {
  9 + echo "Running pylint ..."
  10 + opts="--rcfile=pylintrc --output-format=parseable"
  11 + files=$(find_src)
  12 + output_filename="pylint.log"
  13 + pylint ${opts} ${files} 2>&1 > $output_filename
  14 + echo "Check '$output_filename' for a full report."
  15 +}
  16 +
  17 +run_pylint
44 pylintrc
... ... @@ -0,0 +1,44 @@
  1 +# The format of this file isn't really documented; just use --generate-rcfile
  2 +
  3 +[Master]
  4 +
  5 +[Messages Control]
  6 +
  7 +# http://pylint-messages.wikidot.com/all-codes
  8 +
  9 +# C0111: Don't require docstrings on every method
  10 +# R0912: Too many branches (huh)
  11 +# R0914: Too many local variables is odd.
  12 +# W0142: *args and **kwargs are fine.
  13 +# W0511: TODOs in code comments are fine.
  14 +# W0613: Unused argument '??' should be ok (they are useful sometimes to know intention of variable)
  15 +# W0622: Redefining id is fine.
  16 +
  17 +disable=C0111,W0142,W0622,C0301,R0902,R0201,R0914,W0613,R0912,R0801
  18 +
  19 +[Basic]
  20 +
  21 +# Variable names can be 1 to 31 characters long, with lowercase and underscores
  22 +variable-rgx=[a-z_][a-z0-9_]{0,30}$
  23 +
  24 +# Argument names can be 2 to 31 characters long, with lowercase and underscores
  25 +argument-rgx=[a-z_][a-z0-9_]{1,30}$
  26 +
  27 +# Method names should be at least 3 characters long
  28 +# and be lowercased with underscores
  29 +method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$
  30 +
  31 +# Don't require docstrings on tests.
  32 +no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$
  33 +
  34 +[Design]
  35 +
  36 +max-public-methods=100
  37 +min-public-methods=0
  38 +max-args=6
  39 +
  40 +[Variables]
  41 +
  42 +# List of additional names supposed to be defined in builtins. Remember that
  43 +# you should avoid to define new builtins when possible.
  44 +

0 comments on commit 0d9038d

Please sign in to comment.
Something went wrong with that request. Please try again.