cleanup: pep8

This commit is contained in:
2014-11-21 20:58:44 +01:00
parent 47a6eaa936
commit aac29c824d
12 changed files with 57 additions and 77 deletions

View File

@@ -189,7 +189,6 @@ class bam_session:
os.path.join(session_rootdir, ".bam_tmp.zip"), os.path.join(session_rootdir, ".bam_tmp.zip"),
} }
with open(os.path.join(session_rootdir, ".bam_paths_uuid.json")) as f: with open(os.path.join(session_rootdir, ".bam_paths_uuid.json")) as f:
import json import json
paths_uuid = json.load(f) paths_uuid = json.load(f)
@@ -293,7 +292,6 @@ class bam_commands:
print("Project %r initialized" % proj_dirname) print("Project %r initialized" % proj_dirname)
@staticmethod @staticmethod
def create(session_name): def create(session_name):
import os import os
@@ -404,7 +402,6 @@ class bam_commands:
@staticmethod @staticmethod
def commit(paths, message): def commit(paths, message):
import sys
import os import os
import requests import requests
@@ -439,11 +436,9 @@ class bam_commands:
with open(os.path.join(session_rootdir, ".bam_paths_uuid.json")) as f: with open(os.path.join(session_rootdir, ".bam_paths_uuid.json")) as f:
paths_uuid = json.load(f) paths_uuid = json.load(f)
with open(os.path.join(session_rootdir, ".bam_deps_remap.json")) as f: with open(os.path.join(session_rootdir, ".bam_deps_remap.json")) as f:
deps_remap = json.load(f) deps_remap = json.load(f)
paths_add = {} paths_add = {}
paths_modified = {} paths_modified = {}
paths_remove = {} paths_remove = {}
@@ -458,7 +453,6 @@ class bam_commands:
print("Nothing to commit!") print("Nothing to commit!")
return return
for fn_rel, fn_abs in list(paths_modified.items()): for fn_rel, fn_abs in list(paths_modified.items()):
# we may want to be more clever here # we may want to be more clever here
deps = deps_remap.get(fn_rel) deps = deps_remap.get(fn_rel)
@@ -555,7 +549,6 @@ class bam_commands:
# TODO(cam) # TODO(cam)
# if all goes well, rewrite sha1's # if all goes well, rewrite sha1's
@staticmethod @staticmethod
def status(paths): def status(paths):
# TODO(cam) multiple paths # TODO(cam) multiple paths
@@ -565,7 +558,6 @@ class bam_commands:
session_rootdir = bam_config.find_sessiondir(path, abort=True) session_rootdir = bam_config.find_sessiondir(path, abort=True)
print(session_rootdir) print(session_rootdir)
paths_add = {} paths_add = {}
paths_modified = {} paths_modified = {}
paths_remove = {} paths_remove = {}
@@ -623,7 +615,6 @@ class bam_commands:
if file_type != "dir": if file_type != "dir":
print(" %s" % name_short) print(" %s" % name_short)
@staticmethod @staticmethod
def deps(paths, recursive=False): def deps(paths, recursive=False):
import blendfile_path_walker import blendfile_path_walker

View File

@@ -7,7 +7,6 @@ import os
MODULE_DIR = os.path.dirname(__file__) MODULE_DIR = os.path.dirname(__file__)
with open(os.path.join(MODULE_DIR, 'config.json'), 'r') as config: with open(os.path.join(MODULE_DIR, 'config.json'), 'r') as config:
import json
config = json.load(config) config = json.load(config)
@@ -63,4 +62,3 @@ r = requests.put(request_url('/file'),
files=files) files=files)
print(r.text) print(r.text)

View File

@@ -184,7 +184,8 @@ class Application(tk.Frame):
but.grid(row=row, column=0) but.grid(row=row, column=0)
self.grid_members.append(but) self.grid_members.append(but)
def fn(idname=name_short, but_path=but_path): exec_path_dir(idname, but_path) def fn(idname=name_short, but_path=but_path):
exec_path_dir(idname, but_path)
but = tk.Button(self.frame, text=name_short + "/", fg="green", command=fn) but = tk.Button(self.frame, text=name_short + "/", fg="green", command=fn)
but.grid(row=row, column=1, sticky="nw") but.grid(row=row, column=1, sticky="nw")
@@ -213,7 +214,9 @@ class Application(tk.Frame):
if item_type == "file": if item_type == "file":
but = tk.Label(self.frame, text="(b)", width=3, borderwidth="1", relief="solid") but = tk.Label(self.frame, text="(b)", width=3, borderwidth="1", relief="solid")
but.grid(row=row, column=0) but.grid(row=row, column=0)
def fn(idname=name_short): exec_path_blendfile(idname)
def fn(idname=name_short):
exec_path_blendfile(idname)
self.grid_members.append(but) self.grid_members.append(but)
but = tk.Button(self.frame, text=name_short, fg="blue", command=fn) but = tk.Button(self.frame, text=name_short, fg="blue", command=fn)
@@ -231,4 +234,3 @@ root = tk.Tk()
app = Application(root).pack(side="top", fill="both", expand=True) app = Application(root).pack(side="top", fill="both", expand=True)
root.title("BAM") root.title("BAM")
root.mainloop() root.mainloop()

View File

@@ -55,4 +55,3 @@ def sha1_from_file(fn, block_size=1 << 20):
break break
sha1.update(data) sha1.update(data)
return sha1.hexdigest() return sha1.hexdigest()

View File

@@ -245,7 +245,6 @@ def pack(blendfile_src, blendfile_dst, mode='FILE',
zip_handle.write(src.decode('utf-8'), zip_handle.write(src.decode('utf-8'),
arcname=os.path.relpath(dst, base_dir_dst).decode('utf-8')) arcname=os.path.relpath(dst, base_dir_dst).decode('utf-8'))
yield report(" %s: %r\n" % (colorize("written", color='green'), blendfile_dst)) yield report(" %s: %r\n" % (colorize("written", color='green'), blendfile_dst))
else: else:
raise Exception("%s not a known mode" % mode) raise Exception("%s not a known mode" % mode)
@@ -331,4 +330,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -56,7 +56,7 @@ def create_from_files(deps):
for f_abs in iter_files_blend(dirname): for f_abs in iter_files_blend(dirname):
if f_abs.endswith(".png"): if f_abs.endswith(".png"):
f_rel = bpy.path.relpath(f_abs) f_rel = bpy.path.relpath(f_abs)
image = bpy.data.images.load(f) image = bpy.data.images.load(f_rel)
image.use_fake_user = True image.use_fake_user = True
deps.append(f_abs) deps.append(f_abs)
@@ -96,4 +96,3 @@ if __name__ == "__main__":
import sys import sys
sys.exit(returncode) sys.exit(returncode)

View File

@@ -247,7 +247,6 @@ def bam_run(argv, cwd=None):
import shlex import shlex
sys.stdout.write("bam %s\n" % " ".join([shlex.quote(c) for c in argv])) sys.stdout.write("bam %s\n" % " ".join([shlex.quote(c) for c in argv]))
# input('press_key!:') # input('press_key!:')
with StdIO() as fakeio: with StdIO() as fakeio:
@@ -299,8 +298,8 @@ def blendfile_template_create(blendfile, create_id, deps):
returncode_test = 123 returncode_test = 123
blendfile_deps_json = os.path.join(TEMP_LOCAL, "blend_template_deps.json") blendfile_deps_json = os.path.join(TEMP_LOCAL, "blend_template_deps.json")
os.makedirs(os.path.dirname(blendfile), exist_ok=True) os.makedirs(os.path.dirname(blendfile), exist_ok=True)
stdout, stderr, returncode = run( cmd = (
("blender", "blender",
"--background", "--background",
"--factory-startup", "--factory-startup",
"-noaudio", "-noaudio",
@@ -311,7 +310,8 @@ def blendfile_template_create(blendfile, create_id, deps):
blendfile_deps_json, blendfile_deps_json,
create_id, create_id,
str(returncode_test), str(returncode_test),
)) )
stdout, stderr, returncode = run(cmd)
if os.path.exists(blendfile_deps_json): if os.path.exists(blendfile_deps_json):
import json import json
@@ -577,6 +577,7 @@ class BamListTest(BamSessionTestCase):
import json import json
ret = json.loads(stdout) ret = json.loads(stdout)
self.assertEqual(2, len(ret))
class BamCommitTest(BamSessionTestCase): class BamCommitTest(BamSessionTestCase):
@@ -645,8 +646,7 @@ class BamBlendTest(BamSimpleTestCase):
yield filepath yield filepath
for create_id, create_fn in blendfile_templates.__dict__.items(): for create_id, create_fn in blendfile_templates.__dict__.items():
if (create_id.startswith("create_") and if (create_id.startswith("create_") and create_fn.__class__.__name__ == "function"):
create_fn.__class__.__name__ == "function"):
os.makedirs(TEMP_SESSION) os.makedirs(TEMP_SESSION)
@@ -694,7 +694,6 @@ class BamDeleteTest(BamSessionTestCase):
def test_delete(self): def test_delete(self):
session_name = "mysession" session_name = "mysession"
file_name = "testfile.blend" file_name = "testfile.blend"
file_data = b"hello world!\n"
proj_path, session_path = self.init_session(session_name) proj_path, session_path = self.init_session(session_name)
# now do a real commit # now do a real commit
@@ -717,7 +716,6 @@ class BamDeleteTest(BamSessionTestCase):
stdout, stderr = bam_run(["checkout", file_name, "--output", "new_out"], proj_path) stdout, stderr = bam_run(["checkout", file_name, "--output", "new_out"], proj_path)
self.assertEqual("", stderr) self.assertEqual("", stderr)
# now delete the file we just checked out # now delete the file we just checked out
session_path = os.path.join(proj_path, "new_out") session_path = os.path.join(proj_path, "new_out")
os.remove(os.path.join(session_path, file_name)) os.remove(os.path.join(session_path, file_name))
@@ -740,4 +738,3 @@ if __name__ == '__main__':
data = global_setup() data = global_setup()
unittest.main(exit=False) unittest.main(exit=False)
global_teardown(data) global_teardown(data)

View File

@@ -117,7 +117,6 @@ class DirectoryAPI(Resource):
path_root_abs = os.path.join(path_root_abs, path) path_root_abs = os.path.join(path_root_abs, path)
parent_path = os.pardir parent_path = os.pardir
if not os.path.isdir(path_root_abs): if not os.path.isdir(path_root_abs):
return jsonify(message="Path is not a directory %r" % path_root_abs) return jsonify(message="Path is not a directory %r" % path_root_abs)
@@ -218,7 +217,6 @@ class FileAPI(Resource):
yield report("%s: %r\n" % (colorize("failed to extract", color='red'), filepath)) yield report("%s: %r\n" % (colorize("failed to extract", color='red'), filepath))
return return
with open(filepath_zip, 'rb') as f: with open(filepath_zip, 'rb') as f:
f.seek(0, os.SEEK_END) f.seek(0, os.SEEK_END)
f_size = f.tell() f_size = f.tell()
@@ -246,8 +244,12 @@ class FileAPI(Resource):
file = request.files['file'] file = request.files['file']
# Get the value of the first (and only) result for the specified project setting # Get the value of the first (and only) result for the specified project setting
svn_password = next((setting.value for setting in project.settings if setting.name == 'svn_password')) svn_password = next((setting.value
svn_default_user = next((setting.value for setting in project.settings if setting.name == 'svn_default_user')) for setting in project.settings
if setting.name == 'svn_password'))
svn_default_user = next((setting.value
for setting in project.settings
if setting.name == 'svn_default_user'))
# We get the actual username from the http headers # We get the actual username from the http headers
svn_user = auth.username() svn_user = auth.username()
@@ -324,7 +326,6 @@ class FileAPI(Resource):
result = local_client.run_command('rm', result = local_client.run_command('rm',
[file_path_abs, ]) [file_path_abs, ])
# Commit command # Commit command
result = local_client.run_command('commit', result = local_client.run_command('commit',
[local_client.info()['entry_path'], [local_client.info()['entry_path'],
@@ -333,7 +334,6 @@ class FileAPI(Resource):
'--password', svn_password], '--password', svn_password],
combine=True) combine=True)
return jsonify(message=result) return jsonify(message=result)
else: else:
return jsonify(message='File not allowed') return jsonify(message='File not allowed')
@@ -405,8 +405,6 @@ class FileAPI(Resource):
del write_dict_as_json del write_dict_as_json
# done writing json! # done writing json!
@staticmethod @staticmethod
def allowed_file(filename): def allowed_file(filename):
return '.' in filename and \ return '.' in filename and \
@@ -415,4 +413,3 @@ class FileAPI(Resource):
api.add_resource(DirectoryAPI, '/<project_name>/file_list', endpoint='file_list') api.add_resource(DirectoryAPI, '/<project_name>/file_list', endpoint='file_list')
api.add_resource(FileAPI, '/<project_name>/file', endpoint='file') api.add_resource(FileAPI, '/<project_name>/file', endpoint='file')

View File

@@ -83,6 +83,7 @@ class CustomModelView(ModelView):
return True return True
# return login.current_user.has_role('admin') # return login.current_user.has_role('admin')
class CustomBaseView(BaseView): class CustomBaseView(BaseView):
def is_accessible(self): def is_accessible(self):
return True return True
@@ -108,8 +109,7 @@ class CustomAdminIndexView(admin.AdminIndexView):
# Create admin # Create admin
backend = Admin( backend = Admin(
app, app,
'BAM', "BAM",
index_view=CustomAdminIndexView(), index_view=CustomAdminIndexView(),
base_template='admin/layout_admin.html' base_template="admin/layout_admin.html"
) )

View File

@@ -70,4 +70,3 @@ if context.is_offline_mode():
run_migrations_offline() run_migrations_offline()
else: else:
run_migrations_online() run_migrations_online()