Commit e89d1e6b347fe31af0f81b9e802e767d508b7fc1
1 parent
9d2e6410
Exists in
master
Finaliza integração do módulo Checkout
Showing
6 changed files
with
83 additions
and
41 deletions
Show diff stats
bpy_checkout.py
@@ -15,7 +15,7 @@ def main(): | @@ -15,7 +15,7 @@ def main(): | ||
15 | sys.exit(4) | 15 | sys.exit(4) |
16 | action = None | 16 | action = None |
17 | for i in bpy.data.actions: | 17 | for i in bpy.data.actions: |
18 | - if (i.name.upper() == action_name): | 18 | + if (str(i.name.upper()) == str(action_name)): |
19 | action = i | 19 | action = i |
20 | break | 20 | break |
21 | if (action == None): | 21 | if (action == None): |
bpy_render.py
@@ -41,10 +41,8 @@ def file_rename(file_full_path): | @@ -41,10 +41,8 @@ def file_rename(file_full_path): | ||
41 | except Exception: | 41 | except Exception: |
42 | return "" | 42 | return "" |
43 | 43 | ||
44 | -def render_video(video_output = ""): | ||
45 | - getcwd = os.path.dirname(os.path.abspath(__file__)) | ||
46 | - base_path = os.path.join(getcwd, video_output) | ||
47 | - bpy.context.scene.render.filepath = base_path + "_" | 44 | +def render_video(upload_dir, sign_name): |
45 | + bpy.context.scene.render.filepath = os.path.join(upload_dir, sign_name + "_") | ||
48 | try: | 46 | try: |
49 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") | 47 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") |
50 | return str("%s%0.4i-%0.4i.mp4" % (bpy.context.scene.render.filepath, bpy.context.scene.frame_start, bpy.context.scene.frame_end)) | 48 | return str("%s%0.4i-%0.4i.mp4" % (bpy.context.scene.render.filepath, bpy.context.scene.frame_start, bpy.context.scene.frame_end)) |
@@ -55,13 +53,13 @@ def main(): | @@ -55,13 +53,13 @@ def main(): | ||
55 | if (len(sys.argv) == 8): | 53 | if (len(sys.argv) == 8): |
56 | json_obj = json.loads(sys.argv[7]) | 54 | json_obj = json.loads(sys.argv[7]) |
57 | try: | 55 | try: |
58 | - video_output = json_obj["video_output"] | ||
59 | - convert_to_webm = json_obj["convert_to_webm"] | 56 | + upload_dir = json_obj["upload_dir"] |
57 | + sign_name = json_obj["sign_name"] | ||
60 | except: | 58 | except: |
61 | sys.exit(3) | 59 | sys.exit(3) |
62 | try: | 60 | try: |
63 | configure_output() | 61 | configure_output() |
64 | - file_rename(render_video(video_output)) | 62 | + file_rename(render_video(upload_dir, sign_name)) |
65 | except: | 63 | except: |
66 | sys.exit(4) | 64 | sys.exit(4) |
67 | else: | 65 | else: |
checkout.py
@@ -3,10 +3,11 @@ | @@ -3,10 +3,11 @@ | ||
3 | import json | 3 | import json |
4 | import os | 4 | import os |
5 | import subprocess | 5 | import subprocess |
6 | +import pyutil | ||
6 | 7 | ||
7 | -getcwd = os.path.dirname(os.path.abspath(__file__)) | ||
8 | -bpy_script_action = os.path.join(getcwd, "bpy_checkout.py") | ||
9 | -bpy_script_render = os.path.join(getcwd, "bpy_render.py") | 8 | +getcwd=os.path.dirname(os.path.abspath(__file__)) |
9 | +bpy_script_action=os.path.join(getcwd, "bpy_checkout.py") | ||
10 | +bpy_script_render=os.path.join(getcwd, "bpy_render.py") | ||
10 | 11 | ||
11 | def file_exists(file_path): | 12 | def file_exists(file_path): |
12 | if ((os.path.isfile(file_path) == 1) and (os.path.exists(file_path) == 1)): | 13 | if ((os.path.isfile(file_path) == 1) and (os.path.exists(file_path) == 1)): |
@@ -14,58 +15,81 @@ def file_exists(file_path): | @@ -14,58 +15,81 @@ def file_exists(file_path): | ||
14 | else: | 15 | else: |
15 | return False | 16 | return False |
16 | 17 | ||
17 | -def check_action(blend_file = "", action_name = "", action_fake_is_valid = True, min_frame_count = 10, hide_output = True): | 18 | +def check_action(blend_file="", action_name="", action_fake_is_valid=True, min_frame_count=10, hide_output=True): |
18 | if (file_exists(blend_file)): | 19 | if (file_exists(blend_file)): |
19 | - if not (isinstance(blend_file, str) and isinstance(action_name, str)): | ||
20 | - return 1 | ||
21 | - if not (isinstance(action_fake_is_valid, bool) and isinstance(min_frame_count, int)): | 20 | + if not ((isinstance(blend_file, str) and isinstance(action_name, str)) or |
21 | + (isinstance(blend_file, unicode) and isinstance(action_name, unicode)) or | ||
22 | + ((isinstance(action_fake_is_valid, bool) and isinstance(min_frame_count, int)))): | ||
23 | + pyutil.log("Args to check_action no match types", 4) | ||
22 | return 1 | 24 | return 1 |
23 | if (action_name == ""): | 25 | if (action_name == ""): |
24 | - action_name = os.path.splitext(blend_file)[0] | 26 | + action_name=os.path.splitext(blend_file)[0] |
25 | try: | 27 | try: |
26 | - json_object = json.JSONEncoder().encode( | 28 | + json_object=json.JSONEncoder().encode( |
27 | { | 29 | { |
28 | - "action_name": action_name.upper(), | 30 | + "action_name": action_name, |
29 | "action_fake_is_valid": action_fake_is_valid, | 31 | "action_fake_is_valid": action_fake_is_valid, |
30 | "min_frame_count": min_frame_count | 32 | "min_frame_count": min_frame_count |
31 | } | 33 | } |
32 | ) | 34 | ) |
33 | if (hide_output): | 35 | if (hide_output): |
34 | - dev_null = open(os.devnull, 'w') | ||
35 | - return subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_action, "--", json_object], stdout = dev_null, stderr = dev_null) | 36 | + dev_null=open(os.devnull, 'w') |
37 | + result_code=subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_action, "--", json_object], stdout=dev_null, stderr=dev_null) | ||
36 | else: | 38 | else: |
37 | - return subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_action, "--", json_object]) | 39 | + result_code=subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_action, "--", json_object]) |
40 | + if (result_code == 4): | ||
41 | + pyutil.log("JSON Key no match", 4) | ||
42 | + elif (result_code == 5): | ||
43 | + pyutil.log("Action in blend file no exists", 4) | ||
44 | + elif (result_code == 6): | ||
45 | + pyutil.log("Action is fake user", 4) | ||
46 | + elif (result_code == 7): | ||
47 | + pyutil.log("Timeline Frame Count is less than 10", 4) | ||
48 | + elif (result_code == 8): | ||
49 | + pyutil.log("Args count no match", 4) | ||
38 | except: | 50 | except: |
51 | + pyutil.log("Subprocess interrupt", 4) | ||
39 | return 2 | 52 | return 2 |
53 | + return result_code | ||
40 | else: | 54 | else: |
55 | + pyutil.log("Blend file not exists", 4) | ||
41 | return 3 | 56 | return 3 |
42 | 57 | ||
43 | -def render_video(blend_file = "", video_output = "", convert_to_webm = True, rm_original_video = True, hide_output = False): | 58 | +def render_video(upload_dir="", blend_file="", sign_name="", convert_to_webm=True, rm_original_video=True, hide_output=False): |
44 | if (file_exists(blend_file)): | 59 | if (file_exists(blend_file)): |
45 | - if not (isinstance(blend_file, str) and isinstance(video_output, str)): | 60 | + if not ((isinstance(upload_dir, str) and isinstance(blend_file, str)) or |
61 | + (isinstance(upload_dir, unicode) and isinstance(blend_file, unicode)) or | ||
62 | + (isinstance(convert_to_webm, bool) and isinstance(rm_original_video, bool) and isinstance(hide_output, bool))): | ||
63 | + pyutil.log("Args to render_video no match types", 4) | ||
46 | return 1 | 64 | return 1 |
47 | try: | 65 | try: |
48 | - json_object = json.JSONEncoder().encode( | 66 | + json_object= json.JSONEncoder().encode( |
49 | { | 67 | { |
50 | - "video_output": video_output.upper(), | ||
51 | - "convert_to_webm": convert_to_webm | 68 | + "upload_dir": upload_dir, |
69 | + "sign_name": sign_name | ||
52 | } | 70 | } |
53 | ) | 71 | ) |
54 | if (hide_output): | 72 | if (hide_output): |
55 | - dev_null = open(os.devnull, 'w') | ||
56 | - result_code = subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_render, "--", json_object], stdout = dev_null, stderr = dev_null) | 73 | + dev_null=open(os.devnull, 'w') |
74 | + result_code=subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_render, "--", json_object], stdout=dev_null, stderr=dev_null) | ||
57 | else: | 75 | else: |
58 | - result_code = subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_render, "--", json_object]) | 76 | + result_code=subprocess.call(['blender', '-b', blend_file, '-noaudio', '-P', bpy_script_render, "--", json_object]) |
59 | if (convert_to_webm): | 77 | if (convert_to_webm): |
60 | - video_mp4 = video_output.upper() + ".mp4" | ||
61 | - video_webm = video_output.upper() + ".webm" | 78 | + video_mp4=os.path.join(upload_dir, sign_name + ".mp4") |
79 | + video_webm=os.path.join(upload_dir, sign_name + ".webm") | ||
62 | subprocess.call(["avconv", "-loglevel", "0", "-y", "-i", video_mp4, "-r", "24", "-vcodec", "libvpx", video_webm]) | 80 | subprocess.call(["avconv", "-loglevel", "0", "-y", "-i", video_mp4, "-r", "24", "-vcodec", "libvpx", video_webm]) |
63 | if (rm_original_video): | 81 | if (rm_original_video): |
64 | subprocess.call(["rm", video_mp4]) | 82 | subprocess.call(["rm", video_mp4]) |
83 | + if (result_code == 4): | ||
84 | + pyutil.log("Except in process", 4) | ||
85 | + elif(result_code == 5): | ||
86 | + pyutil.log("Args count no match", 4) | ||
65 | except: | 87 | except: |
88 | + pyutil.log("Subprocess interrupt", 4) | ||
66 | return 2 | 89 | return 2 |
67 | return result_code | 90 | return result_code |
68 | else: | 91 | else: |
92 | + pyutil.log("JSON Key no match", 4) | ||
69 | return 3 | 93 | return 3 |
70 | 94 | ||
71 | """ | 95 | """ |
corretor.py
1 | +# -*- coding: utf-8 -*- | ||
1 | from flask import request, make_response | 2 | from flask import request, make_response |
2 | from werkzeug import secure_filename | 3 | from werkzeug import secure_filename |
3 | import pbclient | 4 | import pbclient |
@@ -44,6 +45,24 @@ class Corretor: | @@ -44,6 +45,24 @@ class Corretor: | ||
44 | project.allow_anonymous_contributors = False | 45 | project.allow_anonymous_contributors = False |
45 | pbclient.update_project(project) | 46 | pbclient.update_project(project) |
46 | 47 | ||
48 | + def finish_task(self): | ||
49 | + upload_session_id = request.form['upload_session_id'] | ||
50 | + sign_name = request.form['sign_name'] | ||
51 | + upload_dir = os.path.join(self.config['UPLOAD_FOLDER'], upload_session_id) | ||
52 | + blend_file = os.path.join(upload_dir, sign_name + ".blend") | ||
53 | + checkout_result = checkout.render_video(upload_dir, blend_file, sign_name) | ||
54 | + pyutil.log("render_video code: " + str(checkout_result)) | ||
55 | + code = 0 | ||
56 | + result_msg = "" | ||
57 | + if(checkout_result == 0): | ||
58 | + result_msg = "Video gerado com sucesso." | ||
59 | + code = 200 | ||
60 | + else: | ||
61 | + result_msg = "Erro durante geração de vídeo." | ||
62 | + code = 400 | ||
63 | + pyutil.log(result_msg) | ||
64 | + return make_response(result_msg, code) | ||
65 | + | ||
47 | def create_project(self): | 66 | def create_project(self): |
48 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] | 67 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] |
49 | project = self.__find_project(app_short_name) | 68 | project = self.__find_project(app_short_name) |
@@ -91,12 +110,13 @@ class Corretor: | @@ -91,12 +110,13 @@ class Corretor: | ||
91 | file.save(uploaded_file) | 110 | file.save(uploaded_file) |
92 | renamed_file = os.path.join(upload_dir, secure_filename(sign_name + ".blend")) | 111 | renamed_file = os.path.join(upload_dir, secure_filename(sign_name + ".blend")) |
93 | os.rename(uploaded_file, renamed_file) | 112 | os.rename(uploaded_file, renamed_file) |
94 | - check_result = checkout.check_action(str(renamed_file), str(sign_name)) | ||
95 | - if (check_result == 0): | 113 | + checkout_result = checkout.check_action(renamed_file, sign_name) |
114 | + pyutil.log("checkout_result code: " + str(checkout_result)) | ||
115 | + if (checkout_result == 0): | ||
96 | result_msg = "File " + filename + " was uploaded." | 116 | result_msg = "File " + filename + " was uploaded." |
97 | code = 200 | 117 | code = 200 |
98 | else: | 118 | else: |
99 | - result_msg = "File " + filename + " has not expected structure of blend file. " + str(check_result) | 119 | + result_msg = "File " + filename + " has not expected structure of blend file. " + str(checkout_result) |
100 | code = 400 | 120 | code = 400 |
101 | pyutil.log(result_msg) | 121 | pyutil.log(result_msg) |
102 | return make_response(result_msg, code) | 122 | return make_response(result_msg, code) |
main.py
@@ -42,8 +42,11 @@ def upload_file(): | @@ -42,8 +42,11 @@ def upload_file(): | ||
42 | 42 | ||
43 | @app.route("/finish_task", methods=["POST"]) | 43 | @app.route("/finish_task", methods=["POST"]) |
44 | def finish_task(): | 44 | def finish_task(): |
45 | - # TODO read - request.data['upload_session_id'] e request.data['sign_name'] | ||
46 | - return | 45 | + try: |
46 | + return controller.finish_task() | ||
47 | + except: | ||
48 | + pyutil.print_stack_trace() | ||
49 | + raise | ||
47 | 50 | ||
48 | def read_settings(app): | 51 | def read_settings(app): |
49 | here = os.path.abspath(__file__) | 52 | here = os.path.abspath(__file__) |
@@ -60,7 +63,7 @@ def setup_controller(): | @@ -60,7 +63,7 @@ def setup_controller(): | ||
60 | 63 | ||
61 | def run(): | 64 | def run(): |
62 | setup_controller() | 65 | setup_controller() |
63 | - app.run(port=app.config['SERVER_PORT']) | 66 | + app.run(host=app.config['SERVER_HOST'], port=app.config['SERVER_PORT']) |
64 | 67 | ||
65 | if __name__ == '__main__': | 68 | if __name__ == '__main__': |
66 | try: | 69 | try: |
view/template.html
@@ -146,8 +146,6 @@ | @@ -146,8 +146,6 @@ | ||
146 | $("#finish-button").removeClass("disabled-button"); | 146 | $("#finish-button").removeClass("disabled-button"); |
147 | $("#finish-button").addClass("enabled-button"); | 147 | $("#finish-button").addClass("enabled-button"); |
148 | $("#finish-button").off("click").on("click", function() { | 148 | $("#finish-button").off("click").on("click", function() { |
149 | - // endpoint - /finish_task | ||
150 | - // enviar mensagem via POST para renderizar video - upload/<session_hash>/<task.info.sign_name>.blend | ||
151 | enableLoading(); | 149 | enableLoading(); |
152 | $.post("{{ server }}/finish_task", | 150 | $.post("{{ server }}/finish_task", |
153 | { | 151 | { |
@@ -159,8 +157,7 @@ | @@ -159,8 +157,7 @@ | ||
159 | disableLoading(); | 157 | disableLoading(); |
160 | status = status_dict[$("#finish-button").text().trim()]; | 158 | status = status_dict[$("#finish-button").text().trim()]; |
161 | saveAnswer(task, deferred, status); | 159 | saveAnswer(task, deferred, status); |
162 | - } | ||
163 | - ); | 160 | + }); |
164 | }); | 161 | }); |
165 | } | 162 | } |
166 | 163 |