Python cleanups, round 1: whitespace
- Use 4 spaces instead of 2 for indentation. This is Python standard and is also in Google's styleguide for Python: https://google.github.io/styleguide/pyguide.html#Indentation - Use 2 newlines between functions/classes This does introduce a few line-too-long errors to clean up which will be fixed in the follow-up commit, but wanted to keep this as easy to review as possible (git diff -w should be minimal) Change-Id: I463f18d11e72745107350ac0ae5588d1fb626ed6
This commit is contained in:
@@ -17,6 +17,7 @@ FAILURE_MESSAGE = 'This commit message does not match the standard.' \
|
||||
PASS_SCORE = '--code-review=0'
|
||||
PASS_MESSAGE = ''
|
||||
|
||||
|
||||
def main():
|
||||
change = None
|
||||
project = None
|
||||
@@ -76,11 +77,13 @@ def main():
|
||||
|
||||
passes(commit)
|
||||
|
||||
|
||||
def usage():
|
||||
print('Usage:\n')
|
||||
print(sys.argv[0] + ' --change <change id> --project <project name> ' \
|
||||
+ '--branch <branch> --commit <sha1> --patchset <patchset id>')
|
||||
|
||||
|
||||
def fail(commit, message):
|
||||
command = SSH_COMMAND + FAILURE_SCORE + ' -m \\\"' \
|
||||
+ _shell_escape(FAILURE_MESSAGE + '\n\n' + message) \
|
||||
@@ -88,11 +91,13 @@ def fail( commit, message ):
|
||||
subprocess.getstatusoutput(command)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def passes(commit):
|
||||
command = SSH_COMMAND + PASS_SCORE + ' -m \\\"' \
|
||||
+ _shell_escape(PASS_MESSAGE) + ' \\\" ' + commit
|
||||
subprocess.getstatusoutput(command)
|
||||
|
||||
|
||||
def _shell_escape(x):
|
||||
s = ''
|
||||
for c in x:
|
||||
@@ -102,6 +107,6 @@ def _shell_escape(x):
|
||||
s = s + c
|
||||
return s
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
@@ -269,6 +269,7 @@ def clean_up():
|
||||
|
||||
|
||||
def main():
|
||||
<<<<<<< HEAD
|
||||
p = optparse.OptionParser()
|
||||
p.add_option("-u", "--user_count", action="store",
|
||||
default=100,
|
||||
@@ -301,5 +302,40 @@ def main():
|
||||
for idx, u in enumerate(gerrit_users):
|
||||
for _ in range(random.randint(1, 5)):
|
||||
create_change(u, project_names[4 * idx / len(gerrit_users)])
|
||||
=======
|
||||
p = optparse.OptionParser()
|
||||
p.add_option("-u", "--user_count", action="store",
|
||||
default=100,
|
||||
type='int',
|
||||
help="number of users to generate")
|
||||
p.add_option("-p", "--port", action="store",
|
||||
default=8080,
|
||||
type='int',
|
||||
help="port of server")
|
||||
(options, _) = p.parse_args()
|
||||
global BASE_URL
|
||||
BASE_URL = BASE_URL % options.port
|
||||
print(BASE_URL)
|
||||
|
||||
set_up()
|
||||
gerrit_users = get_random_users(options.user_count)
|
||||
|
||||
group_names = create_gerrit_groups()
|
||||
for idx, u in enumerate(gerrit_users):
|
||||
u["groups"].append(group_names[idx % len(group_names)])
|
||||
if idx % 5 == 0:
|
||||
# Also add to security group
|
||||
u["groups"].append(group_names[4])
|
||||
|
||||
generate_ssh_keys(gerrit_users)
|
||||
create_gerrit_users(gerrit_users)
|
||||
|
||||
project_names = create_gerrit_projects(group_names)
|
||||
|
||||
for idx, u in enumerate(gerrit_users):
|
||||
for _ in xrange(random.randint(1, 5)):
|
||||
create_change(u, project_names[4 * idx / len(gerrit_users)])
|
||||
|
||||
>>>>>>> 730efd14f4... Python cleanups, round 1: whitespace
|
||||
|
||||
main()
|
||||
|
@@ -10,12 +10,14 @@ fnCompiledRegex = re.compile(removeSelfInvokeRegex, re.DOTALL)
|
||||
regexBehavior = r"<script>(.+)<\/script>"
|
||||
behaviorCompiledRegex = re.compile(regexBehavior, re.DOTALL)
|
||||
|
||||
|
||||
def _open(filename, mode="r"):
|
||||
try:
|
||||
return open(filename, mode, encoding="utf-8")
|
||||
except TypeError:
|
||||
return open(filename, mode)
|
||||
|
||||
|
||||
def replaceBehaviorLikeHTML(fileIn, fileOut):
|
||||
with _open(fileIn) as f:
|
||||
file_str = f.read()
|
||||
@@ -24,16 +26,19 @@ def replaceBehaviorLikeHTML (fileIn, fileOut):
|
||||
with _open("polygerrit-ui/temp/behaviors/" + fileOut.replace("html", "js"), "w+") as f:
|
||||
f.write(match.group(1))
|
||||
|
||||
|
||||
def replaceBehaviorLikeJS(fileIn, fileOut):
|
||||
with _open(fileIn) as f:
|
||||
file_str = f.read()
|
||||
with _open("polygerrit-ui/temp/behaviors/" + fileOut, "w+") as f:
|
||||
f.write(file_str)
|
||||
|
||||
|
||||
def generateStubBehavior(behaviorName):
|
||||
with _open("polygerrit-ui/temp/behaviors/" + behaviorName + ".js", "w+") as f:
|
||||
f.write("/** @polymerBehavior **/\n" + behaviorName + "= {};")
|
||||
|
||||
|
||||
def replacePolymerElement(fileIn, fileOut, root):
|
||||
with _open(fileIn) as f:
|
||||
key = fileOut.split('.')[0]
|
||||
@@ -56,6 +61,7 @@ def replacePolymerElement (fileIn, fileOut, root):
|
||||
elements[key]["js"] = "polygerrit-ui/temp/" + fileOut
|
||||
elements[key]["package"] = package
|
||||
|
||||
|
||||
def writeTempFile(file, root):
|
||||
# This is included in an extern because it is directly on the window object.
|
||||
# (for now at least).
|
||||
|
@@ -19,6 +19,7 @@
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
|
||||
def print_help():
|
||||
for (n, v) in vars(sys.modules['__main__']).items():
|
||||
if not n.startswith("__") and not n in ['help', 'reload'] \
|
||||
@@ -29,4 +30,5 @@ def print_help():
|
||||
print("Welcome to the Gerrit Inspector")
|
||||
print("Enter help() to see the above again, EOF to quit and stop Gerrit")
|
||||
|
||||
|
||||
print_help()
|
||||
|
@@ -74,6 +74,7 @@ def cache_entry(args):
|
||||
name = '%s-%s' % (path.basename(args.o), h)
|
||||
return path.join(CACHE_DIR, name)
|
||||
|
||||
|
||||
opts = OptionParser()
|
||||
opts.add_option('-o', help='local output file')
|
||||
opts.add_option('-u', help='URL to download')
|
||||
|
@@ -56,6 +56,7 @@ args, _ = opts.parse_args()
|
||||
|
||||
batch_option = '--batch' if args.batch else None
|
||||
|
||||
|
||||
def _build_bazel_cmd(*args):
|
||||
cmd = ['bazel']
|
||||
if batch_option:
|
||||
@@ -64,15 +65,18 @@ def _build_bazel_cmd(*args):
|
||||
cmd.append(arg)
|
||||
return cmd
|
||||
|
||||
|
||||
def retrieve_ext_location():
|
||||
return check_output(_build_bazel_cmd('info', 'output_base')).strip()
|
||||
|
||||
|
||||
def gen_bazel_path():
|
||||
bazel = check_output(['which', 'bazel']).strip().decode('UTF-8')
|
||||
with open(path.join(ROOT, ".bazel_path"), 'w') as fd:
|
||||
fd.write("bazel=%s\n" % bazel)
|
||||
fd.write("PATH=%s\n" % environ["PATH"])
|
||||
|
||||
|
||||
def _query_classpath(target):
|
||||
deps = []
|
||||
t = cp_targets[target]
|
||||
@@ -84,6 +88,7 @@ def _query_classpath(target):
|
||||
deps = [line.rstrip('\n') for line in open(name)]
|
||||
return deps
|
||||
|
||||
|
||||
def gen_project(name='gerrit', root=ROOT):
|
||||
p = path.join(root, '.project')
|
||||
with open(p, 'w') as fd:
|
||||
@@ -102,6 +107,7 @@ def gen_project(name='gerrit', root=ROOT):
|
||||
</projectDescription>\
|
||||
""" % {"name": name}, file=fd)
|
||||
|
||||
|
||||
def gen_plugin_classpath(root):
|
||||
p = path.join(root, '.classpath')
|
||||
with open(p, 'w') as fd:
|
||||
@@ -120,6 +126,7 @@ def gen_plugin_classpath(root):
|
||||
<classpathentry kind="output" path="eclipse-out/classes"/>
|
||||
</classpath>""" % {"testpath": testpath}, file=fd)
|
||||
|
||||
|
||||
def gen_classpath(ext):
|
||||
def make_classpath():
|
||||
impl = minidom.getDOMImplementation()
|
||||
@@ -270,6 +277,7 @@ def gen_classpath(ext):
|
||||
print('error generating project for %s: %s' % (plugin, err),
|
||||
file=sys.stderr)
|
||||
|
||||
|
||||
def gen_factorypath(ext):
|
||||
doc = minidom.getDOMImplementation().createDocument(None, 'factorypath', None)
|
||||
for jar in _query_classpath(AUTO):
|
||||
@@ -284,6 +292,7 @@ def gen_factorypath(ext):
|
||||
with open(p, 'w') as fd:
|
||||
doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8')
|
||||
|
||||
|
||||
try:
|
||||
ext_location = retrieve_ext_location().decode("utf-8")
|
||||
gen_project(args.project_name)
|
||||
|
@@ -118,12 +118,14 @@ def build_bower_json(version_targets, seeds):
|
||||
json.dump(bower_json, f, indent=2)
|
||||
return ret
|
||||
|
||||
|
||||
def decode(input):
|
||||
try:
|
||||
return input.decode("utf-8")
|
||||
except TypeError:
|
||||
return input
|
||||
|
||||
|
||||
def bower_command(args):
|
||||
base = subprocess.check_output(["bazel", "info", "output_base"]).strip()
|
||||
exp = os.path.join(decode(base), "external", "bower", "*npm_binary.tgz")
|
||||
|
@@ -33,6 +33,7 @@ def extract(path, outdir, bin):
|
||||
# Use a temp directory adjacent to outdir so shutil.move can use the same
|
||||
# device atomically.
|
||||
tmpdir = tempfile.mkdtemp(dir=os.path.dirname(outdir))
|
||||
|
||||
def cleanup():
|
||||
try:
|
||||
shutil.rmtree(tmpdir)
|
||||
@@ -57,6 +58,7 @@ def extract(path, outdir, bin):
|
||||
# finished.
|
||||
extract_one(tar.getmember(bin))
|
||||
|
||||
|
||||
def main(args):
|
||||
path = args[0]
|
||||
suffix = '.npm_binary.tgz'
|
||||
|
@@ -16,6 +16,7 @@
|
||||
import unittest
|
||||
from util import resolve_url
|
||||
|
||||
|
||||
class TestResolveUrl(unittest.TestCase):
|
||||
""" run to test:
|
||||
python -m unittest -v util_test
|
||||
@@ -39,5 +40,6 @@ class TestResolveUrl(unittest.TestCase):
|
||||
{'MAVEN_EXAMPLE': 'http://maven.example.com/release'})
|
||||
self.assertEqual(url, 'http://maven.example.com/release/foo.jar')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user