Skip to content
Browse files

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

  • Loading branch information...
1 parent 9b38067 commit 0d9038deccf891e34f92f1dd79c588ef794de842 @harlowja harlowja committed Sep 13, 2012
Showing with 75 additions and 100 deletions.
  1. +0 −1 build.py
  2. +3 −2 builder/downloader/tar_ball.py
  3. +1 −5 builder/modules/add_user.py
  4. +10 −92 builder/util.py
  5. +17 −0 checks.sh
  6. +44 −0 pylintrc
View
1 build.py
@@ -27,7 +27,6 @@
import tempfile
import traceback
import urllib
-import urllib2
import uuid
from contextlib import (closing, contextmanager)
View
5 builder/downloader/tar_ball.py
@@ -28,7 +28,8 @@ def __init__(self, config):
self.root_file = config.get('root_file')
def _check_cache(self):
- cache_name = util.hash_blob(self.where_from, 'md5', mlen=8)
+ cache_name = util.hash_blob(self.where_from, 'md5')
+ cache_name = cache_name[0:8]
full_pth = os.path.join(self.cache_dir, "%s.tar.gz" % (cache_name))
if os.path.isfile(full_pth):
return (full_pth, True)
@@ -46,7 +47,7 @@ def _adjust_real_root(self, arch_path):
if not root_gz:
raise RuntimeError(("Needed file %r not found in"
" extracted contents of %s")
- % (self.root_file, cache_pth))
+ % (self.root_file, arch_path))
else:
util.copy(root_gz, arch_path)
return arch_path
View
6 builder/modules/add_user.py
@@ -15,9 +15,6 @@
# under the License.
-
-import os
-
from builder import util
@@ -30,6 +27,5 @@ def modify(name, root, cfg):
(util.quote(name)))
for uname in user_names:
cmd = ['chroot', root,
- 'yinst', 'i', '-yes',
- 'admin/sudo-%s' % (uname)]
+ 'useradd', '-m', str(uname)]
util.subp(cmd, capture=False)
View
102 builder/util.py
@@ -18,24 +18,16 @@
import contextlib
import errno
-import grp
-import gzip
import hashlib
import os
-import platform
-import pwd
import random
import shutil
-import stat
-import string # pylint: disable=W0402
import subprocess
import sys
import tempfile
import time
import types
import urllib2
-import urllib
-import urlparse
import progressbar
import termcolor
@@ -113,16 +105,6 @@ def quote(data, quote_color='green'):
return color(text, quote_color)
-def format(data, params):
- text = str(data)
-
- def replacer(match):
- param_name = match.group(1)
- return color(params[param_name], color=match.group(2).strip())
-
- return re.sub(r"\{([\w\d]+):(.*)\}", replacer, text)
-
-
def color(data, color, bold=False, underline=False, blink=False):
text = str(data)
text_attrs = list()
@@ -139,18 +121,12 @@ def color(data, color, bold=False, underline=False, blink=False):
def find_file(name, path):
- for (root, dirs, files) in os.walk(path):
+ for (root, _dirs, files) in os.walk(path):
if name in files:
return os.path.join(root, name)
return None
-def rand_str(strlen=32, select_from=None):
- if not select_from:
- select_from = string.letters + string.digits
- return "".join([random.choice(select_from) for _x in range(0, strlen)])
-
-
def download_url(url, where_to, timeout=5):
with contextlib.closing(urllib2.urlopen(url, timeout=timeout)) as rh:
status = rh.getcode()
@@ -216,28 +192,6 @@ def progress_cb(tran_byte_am, chunk):
pbar.finish()
-def make_url(scheme, host, port=None,
- path='', params='', query='', fragment=''):
-
- pieces = []
- pieces.append(scheme or '')
-
- netloc = ''
- if host:
- netloc = str(host)
-
- if port is not None:
- netloc += ":" + "%s" % (port)
-
- pieces.append(netloc or '')
- pieces.append(path or '')
- pieces.append(params or '')
- pieces.append(query or '')
- pieces.append(fragment or '')
-
- return urlparse.urlunparse(pieces)
-
-
def obj_name(obj):
if isinstance(obj, (types.TypeType,
types.ModuleType,
@@ -248,17 +202,6 @@ def obj_name(obj):
@contextlib.contextmanager
-def chdir(ndir):
- curr = os.getcwd()
- try:
- os.chdir(ndir)
- yield ndir
- finally:
- os.chdir(curr)
-
-
-
-@contextlib.contextmanager
def tempdir(**kwargs):
# This seems like it was only added in python 3.2
# Make it since its useful...
@@ -270,26 +213,21 @@ def tempdir(**kwargs):
del_dir(tdir)
-def center(text, fill, max_len):
- return '{0:{fill}{align}{size}}'.format(text, fill=fill,
- align="^", size=max_len)
-
-
def del_dir(path):
shutil.rmtree(path)
def load_file(fname, read_cb=None, quiet=False):
- ofh = StringIO()
+ contents = None
try:
with open(fname, 'rb') as ifh:
+ ofh = StringIO()
pipe_in_out(ifh, ofh, chunk_cb=read_cb)
+ contents = ofh.getvalue()
except IOError as e:
if not quiet:
- raise
- if e.errno != errno.ENOENT:
- raise
- contents = ofh.getvalue()
+ if e.errno != errno.ENOENT:
+ raise
return contents
@@ -321,49 +259,29 @@ def print_iterable(to_log, header=None, do_color=True):
print("|-- %s" % (c))
-def hash_blob(blob, routine, mlen=None):
+def hash_blob(blob, routine):
hasher = hashlib.new(routine)
hasher.update(blob)
- digest = hasher.hexdigest()
- if mlen is not None:
- return digest[0:mlen]
- else:
- return digest
-
-
-def rename(src, dest):
- os.rename(src, dest)
+ return hasher.hexdigest()
def ensure_dirs(dirlist, mode=0755):
for d in dirlist:
ensure_dir(d, mode)
-def load_yaml(blob, allowed=(dict,)):
- blob = str(blob)
- converted = yaml.safe_load(blob)
- if not isinstance(converted, allowed):
- raise TypeError(("Yaml load allows %s root types,"
- " but got %s instead") %
- (allowed, obj_name(converted)))
- loaded = converted
- return loaded
+def load_yaml(blob):
+ return yaml.safe_load(str(blob))
def ensure_dir(path, mode=None):
if not os.path.isdir(path):
os.makedirs(path)
chmod(path, mode)
else:
- # Just adjust the mode
chmod(path, mode)
-def sym_link(source, link):
- os.symlink(source, link)
-
-
def del_file(path):
try:
os.unlink(path)
View
17 checks.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+function find_src {
+ files=`find builder -type f | grep "py\$"`
+ echo "build.py $files"
+}
+
+function run_pylint {
+ echo "Running pylint ..."
+ opts="--rcfile=pylintrc --output-format=parseable"
+ files=$(find_src)
+ output_filename="pylint.log"
+ pylint ${opts} ${files} 2>&1 > $output_filename
+ echo "Check '$output_filename' for a full report."
+}
+
+run_pylint
View
44 pylintrc
@@ -0,0 +1,44 @@
+# The format of this file isn't really documented; just use --generate-rcfile
+
+[Master]
+
+[Messages Control]
+
+# http://pylint-messages.wikidot.com/all-codes
+
+# C0111: Don't require docstrings on every method
+# R0912: Too many branches (huh)
+# R0914: Too many local variables is odd.
+# W0142: *args and **kwargs are fine.
+# W0511: TODOs in code comments are fine.
+# W0613: Unused argument '??' should be ok (they are useful sometimes to know intention of variable)
+# W0622: Redefining id is fine.
+
+disable=C0111,W0142,W0622,C0301,R0902,R0201,R0914,W0613,R0912,R0801
+
+[Basic]
+
+# Variable names can be 1 to 31 characters long, with lowercase and underscores
+variable-rgx=[a-z_][a-z0-9_]{0,30}$
+
+# Argument names can be 2 to 31 characters long, with lowercase and underscores
+argument-rgx=[a-z_][a-z0-9_]{1,30}$
+
+# Method names should be at least 3 characters long
+# and be lowercased with underscores
+method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$
+
+# Don't require docstrings on tests.
+no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$
+
+[Design]
+
+max-public-methods=100
+min-public-methods=0
+max-args=6
+
+[Variables]
+
+# List of additional names supposed to be defined in builtins. Remember that
+# you should avoid to define new builtins when possible.
+

0 comments on commit 0d9038d

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