Commit ca4112cf authored by Alan Taylor's avatar Alan Taylor

PEP8 tidy

parent 05835cac
......@@ -36,12 +36,12 @@ You should have received a copy of the GNU General Public License
along with dtr. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------
"""
import concurrent.futures as cf # ThreadPoolExecutor
import math # floor, hypot
import multiprocessing as mp # cpu_count, Queue
import socket # AF_INET, SOCK_STREAM, socket
import subprocess # PIPE, Popen
import sys # exit
import concurrent.futures as cf # ThreadPoolExecutor
import math # floor, hypot
import multiprocessing as mp # cpu_count, Queue
import socket # AF_INET, SOCK_STREAM, socket
import subprocess # PIPE, Popen
import sys # exit
##############################################################################
......@@ -87,6 +87,7 @@ def _axis_bounds(blocks, block_roc):
upper_limit = (block_roc + 1) / blocks
return (lower_limit, upper_limit)
def render_block_normal(settings, block_number):
"""
return bottom left (x, y) and top right (x, y) of a given block number
......@@ -114,6 +115,7 @@ def render_block_normal(settings, block_number):
return (x_min, y_min, x_max, y_max)
def area_in_blocks(settings, cl_args):
"""
yield a series of blocks that will fully contain the area specified
......@@ -149,6 +151,7 @@ def area_in_blocks(settings, cl_args):
for col in range(col_st, col_en + 1):
yield row * settings['blocks_x'] + col + 1
def render_block_pillow(settings, block_number):
"""
a version of render_block_normal() that generates coordinates compatible
......@@ -177,6 +180,7 @@ def render_block_pillow(settings, block_number):
return x_min, y_min, x_max, y_max
def _dist_from_centre(settings, block_number):
"""
return the distance between the centre of the image and the
......@@ -203,6 +207,7 @@ def _dist_from_centre(settings, block_number):
return math.hypot(dxc, dyc)
def no_dupes_ipu(original):
"""
generic function that removes duplicate items from a list (i)n (p)lace;
......@@ -230,6 +235,7 @@ def no_dupes_ipu(original):
ndup -= 1
o_ind -= 1
def tidy_checked(checked, missing):
"""
remove all traces of the missing blocks from the record, making sure
......@@ -254,6 +260,7 @@ def tidy_checked(checked, missing):
for rendered_block in all_matching_blocks:
checked.remove(rendered_block)
def package_filename_for_cygwin(node_op_sys, nix_filename):
"""
Windows applications will expect to receive Windows filenames
......@@ -276,6 +283,7 @@ def package_filename_for_cygwin(node_op_sys, nix_filename):
return '\"$(cygpath -aw \"' + nix_filename + '\")\"'
def block_render_filename(settings, block):
"""
return a filename given the block number and seed
......@@ -295,6 +303,7 @@ def block_render_filename(settings, block):
return 'block_' + str(block).zfill(len(str(settings['blocks_required']))) + \
'_seed_' + str(settings['seed']) + '.' + file_extension(settings)
def node_alive(r_node):
"""
establish whether the node is up by attempting to connect to port 22,
......@@ -330,6 +339,7 @@ def node_alive(r_node):
return alive
def _modern_blender_executable(node, test_blender):
"""
detect whether the located Blender binary can be run, and whether it is
......@@ -358,12 +368,14 @@ def _modern_blender_executable(node, test_blender):
b_vers = response.split()[1]
if float(b_vers) < 2.65:
print(node.ip_address, 'Blender version (' + b_vers.ljust(4) + \
print(
node.ip_address, 'Blender version (' + b_vers.ljust(4) +
') is too old to support the required feature set')
return False
return True
def check_python_version():
"""
simple check that the version of Python running this script is
......@@ -379,6 +391,7 @@ def check_python_version():
py_vers = sys.version.partition(' ')[0]
sys.exit('this script requires Python 3.4 or later (' + py_vers + ' detected), exiting')
def _locate_blender(rni):
"""
find the location of the Blender binary on the remote render node
......@@ -405,14 +418,15 @@ def _locate_blender(rni):
# see if we can find the binary in other plausible locations
blender_binloc = {
'Darwin': ['~/Blender/blender.app/Contents/MacOS/blender', \
'~/Applications/Blender/blender.app/Contents/MacOS/blender', \
'Darwin': [
'~/Blender/blender.app/Contents/MacOS/blender',
'~/Applications/Blender/blender.app/Contents/MacOS/blender',
'/Applications/Blender/blender.app/Contents/MacOS/blender'],
'Linux': ['~/Blender/blender'],
'CYGWIN' : ['~/Blender/blender.exe']}
'CYGWIN': ['~/Blender/blender.exe']}
blender_locations = blender_binloc.get(rni.opsys, '~/Blender/blender.exe')
for b_loc in blender_locations:
find_blender = 'if [ ! -f ' + b_loc + ' ]; then echo "MISSING"; fi'
find_blender = 'if [ ! -f ' + b_loc + ' ]; then echo "MISSING"; fi'
find_response = _remote_command(rni, find_blender)
if 'MISSING' not in find_response:
# binary found, now test to see if we can run it
......@@ -424,6 +438,7 @@ def _locate_blender(rni):
print(rni.ip_address + ' is up, but Blender was not found, or could not be executed')
return ''
def _remote_command(node, execute_command):
"""
execute command on remote node, wait for completion, then return stdout
......@@ -443,12 +458,14 @@ def _remote_command(node, execute_command):
--------------------------------------------------------------------------
"""
on_this_node = node.username + '@' + node.ip_address
remcom = subprocess.Popen(['ssh', on_this_node, execute_command], shell=False, \
remcom = subprocess.Popen(
['ssh', on_this_node, execute_command], shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdo, _) = remcom.communicate(None, None)
return stdo.decode('utf-8', 'ignore').rstrip()
def check_node(node):
"""
determine whether the node is up with a basic connection check,
......@@ -501,6 +518,7 @@ def check_node(node):
return node, node_up, binloc
def remove_dead_nodes(available_nodes, remove=True):
"""
determine whether the node is up with a basic connection check,
......@@ -545,6 +563,7 @@ def remove_dead_nodes(available_nodes, remove=True):
if not available_nodes:
sys.exit('exiting, as no viable render nodes were found')
def file_extension(settings):
"""
generate file extension for chosen filetype
......@@ -573,6 +592,7 @@ def _do_bottom_to_top(ic_settings, blocks):
"""
blocks.sort()
def _do_centre(ic_settings, blocks):
"""
from centre outwards
......@@ -581,6 +601,7 @@ def _do_centre(ic_settings, blocks):
"""
blocks.sort(key=lambda x: _dist_from_centre(ic_settings, x))
def despatch_order(ic_settings, blocks):
"""
set the order that blocks are despatched to be rendered
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment