Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-07-03 07:47:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-07-03 07:55:02 +0300
commit8c15d612a5cdfe39233c7f2b7556742091c82558 (patch)
tree248e7611f9245c1796515baef2ace410bf896c9d /source/blender
parentb66aa0b0a6b123e833d4038a77a5d3f04c37a9a0 (diff)
Cleanup: pep8
Diffstat (limited to 'source/blender')
-rwxr-xr-xsource/blender/datatoc/datatoc_icon_split.py86
-rwxr-xr-xsource/blender/datatoc/datatoc_icon_split_to_png.py1
-rwxr-xr-xsource/blender/makesrna/rna_cleanup/rna_cleaner.py105
-rwxr-xr-xsource/blender/makesrna/rna_cleanup/rna_cleaner_merge.py78
-rw-r--r--source/blender/python/rna_dump.py5
-rw-r--r--source/blender/python/simple_enum_gen.py6
6 files changed, 156 insertions, 125 deletions
diff --git a/source/blender/datatoc/datatoc_icon_split.py b/source/blender/datatoc/datatoc_icon_split.py
index aae907ec340..faf8d57be77 100755
--- a/source/blender/datatoc/datatoc_icon_split.py
+++ b/source/blender/datatoc/datatoc_icon_split.py
@@ -68,7 +68,7 @@ def image_from_file(filepath):
if bpy is not None:
pixels, pixel_w, pixel_h = image_from_file__bpy(filepath)
- #else:
+ # else:
# pixels, pixel_w, pixel_h = image_from_file__py(filepath)
return pixels, pixel_w, pixel_h
@@ -95,12 +95,14 @@ def write_subimage(sub_x, sub_y, sub_w, sub_h,
with open(filepath, 'wb') as f:
- f.write(struct.pack('<6I',
+ f.write(
+ struct.pack(
+ '<6I',
sub_w, sub_h,
sub_x, sub_y,
# redundant but including to maintain consistency
- pixel_w, pixel_h,
- ))
+ pixel_w, pixel_h,
+ ))
for y in range(sub_h):
for x in range(sub_w):
@@ -113,8 +115,9 @@ def write_subimage(sub_x, sub_y, sub_w, sub_h,
_dice_icon_name_cache = {}
-def dice_icon_name(x, y, parts_x, parts_y,
- name_style=None, prefix=""):
+def dice_icon_name(
+ x, y, parts_x, parts_y,
+ name_style=None, prefix=""):
"""
How to name icons, this is mainly for what name we get in git,
the actual names don't really matter, its just nice to have the
@@ -143,7 +146,7 @@ def dice_icon_name(x, y, parts_x, parts_y,
icon_name = _dice_icon_name_cache[index]
# for debugging its handy to sort by number
- #~ id_str = "%03d_%s%s.dat" % (index, prefix, icon_name)
+ # ~ id_str = "%03d_%s%s.dat" % (index, prefix, icon_name)
id_str = "%s%s.dat" % (prefix, icon_name)
@@ -158,16 +161,18 @@ def dice_icon_name(x, y, parts_x, parts_y,
return id_str
-def dice(filepath, output, output_prefix, name_style,
- parts_x, parts_y,
- minx, miny, maxx, maxy,
- minx_icon, miny_icon, maxx_icon, maxy_icon,
- spacex_icon, spacey_icon,
- ):
+def dice(
+ filepath, output, output_prefix, name_style,
+ parts_x, parts_y,
+ minx, miny, maxx, maxy,
+ minx_icon, miny_icon, maxx_icon, maxy_icon,
+ spacex_icon, spacey_icon,
+):
- is_simple = (max(minx, miny, maxx, maxy,
- minx_icon, miny_icon, maxx_icon, maxy_icon,
- spacex_icon, spacey_icon) == 0)
+ is_simple = (max(
+ minx, miny, maxx, maxy,
+ minx_icon, miny_icon, maxx_icon, maxy_icon,
+ spacex_icon, spacey_icon) == 0)
pixels, pixel_w, pixel_h = image_from_file(filepath)
@@ -199,9 +204,11 @@ def dice(filepath, output, output_prefix, name_style,
for x in range(parts_x):
for y in range(parts_y):
- id_str = dice_icon_name(x, y,
- parts_x, parts_y,
- name_style=name_style, prefix=output_prefix)
+ id_str = dice_icon_name(
+ x, y,
+ parts_x, parts_y,
+ name_style=name_style, prefix=output_prefix
+ )
filepath = os.path.join(output, id_str)
if VERBOSE:
print(" writing:", filepath)
@@ -235,25 +242,35 @@ def main():
parser = argparse.ArgumentParser(description=__doc__, epilog=epilog)
# File path options
- parser.add_argument("--image", dest="image", metavar='FILE',
- help="Image file")
-
- parser.add_argument("--output", dest="output", metavar='DIR',
- help="Output directory")
-
- parser.add_argument("--output_prefix", dest="output_prefix", metavar='STRING',
- help="Output prefix")
+ parser.add_argument(
+ "--image", dest="image", metavar='FILE',
+ help="Image file",
+ )
+ parser.add_argument(
+ "--output", dest="output", metavar='DIR',
+ help="Output directory",
+ )
+ parser.add_argument(
+ "--output_prefix", dest="output_prefix", metavar='STRING',
+ help="Output prefix",
+ )
# Icon naming option
- parser.add_argument("--name_style", dest="name_style", metavar='ENUM', type=str,
- choices=('', 'UI_ICONS'),
- help="The metod used for naming output data")
+ parser.add_argument(
+ "--name_style", dest="name_style", metavar='ENUM', type=str,
+ choices=('', 'UI_ICONS'),
+ help="The metod used for naming output data",
+ )
# Options for dicing up the image
- parser.add_argument("--parts_x", dest="parts_x", metavar='INT', type=int,
- help="Grid X parts")
- parser.add_argument("--parts_y", dest="parts_y", metavar='INT', type=int,
- help="Grid Y parts")
+ parser.add_argument(
+ "--parts_x", dest="parts_x", metavar='INT', type=int,
+ help="Grid X parts",
+ )
+ parser.add_argument(
+ "--parts_y", dest="parts_y", metavar='INT', type=int,
+ help="Grid Y parts",
+ )
_help = "Inset from the outer edge (in pixels)"
parser.add_argument("--minx", dest="minx", metavar='INT', type=int, help=_help)
@@ -287,5 +304,6 @@ def main():
args.spacex_icon, args.spacey_icon,
)
+
if __name__ == "__main__":
main()
diff --git a/source/blender/datatoc/datatoc_icon_split_to_png.py b/source/blender/datatoc/datatoc_icon_split_to_png.py
index 39bbf1110fb..b583b10b9ff 100755
--- a/source/blender/datatoc/datatoc_icon_split_to_png.py
+++ b/source/blender/datatoc/datatoc_icon_split_to_png.py
@@ -67,5 +67,6 @@ def main():
icondata_to_png(file_src, file_dst)
+
if __name__ == "__main__":
main()
diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner.py b/source/blender/makesrna/rna_cleanup/rna_cleaner.py
index f1cd46f3d57..a936e6499bc 100755
--- a/source/blender/makesrna/rna_cleanup/rna_cleaner.py
+++ b/source/blender/makesrna/rna_cleanup/rna_cleaner.py
@@ -56,19 +56,19 @@ def check_commandline():
"""
import sys
# Usage
- if len(sys.argv)==1 or len(sys.argv)>3:
+ if len(sys.argv) == 1 or len(sys.argv) > 3:
usage()
if sys.argv[1] == '-h':
help()
elif not sys.argv[1].endswith((".txt", ".py")):
- print ('\nBad input file extension... exiting.')
+ print('\nBad input file extension... exiting.')
usage()
else:
inputfile = sys.argv[1]
if len(sys.argv) == 2:
sort_priority = default_sort_choice
- print ('\nSecond parameter missing: choosing to order by %s.' % font_bold(sort_priority))
- elif len(sys.argv)==3:
+ print('\nSecond parameter missing: choosing to order by %s.' % font_bold(sort_priority))
+ elif len(sys.argv) == 3:
sort_priority = sys.argv[2]
if sort_priority not in sort_choices:
print('\nWrong sort_priority... exiting.')
@@ -93,9 +93,11 @@ def check_prefix(prop, btype):
return ""
-def check_if_changed(a,b):
- if a != b: return 'changed'
- else: return 'same'
+def check_if_changed(a, b):
+ if a != b:
+ return 'changed'
+ else:
+ return 'same'
def get_props_from_txt(input_filename):
@@ -103,12 +105,12 @@ def get_props_from_txt(input_filename):
If the file is *.txt, the script assumes it is formatted as outlined in this script docstring
"""
- file=open(input_filename,'r')
- file_lines=file.readlines()
+ file = open(input_filename, 'r')
+ file_lines = file.readlines()
file.close()
- props_list=[]
- props_length_max=[0,0,0,0,0,0,0,0]
+ props_list = []
+ props_length_max = [0, 0, 0, 0, 0, 0, 0, 0]
done_text = "+"
done = 0
@@ -117,7 +119,7 @@ def get_props_from_txt(input_filename):
for iii, line in enumerate(file_lines):
# debug
- #print(line)
+ # print(line)
line_strip = line.strip()
# empty line or comment
if not line_strip:
@@ -136,7 +138,7 @@ def get_props_from_txt(input_filename):
if '*' in bclass:
comment, bclass = [x.strip() for x in bclass.split('*', 1)]
else:
- comment= ''
+ comment = ''
# skipping the header if we have one.
# the header is assumed to be "NOTE * CLASS.FROM -> TO: TYPE DESCRIPTION"
@@ -155,7 +157,7 @@ def get_props_from_txt(input_filename):
# make life easy and strip quotes
description = description.replace("'", "").replace('"', "").replace("\\", "").strip()
except ValueError:
- btype, description = [tail,'NO DESCRIPTION']
+ btype, description = [tail, 'NO DESCRIPTION']
# keyword-check
kwcheck = check_prefix(bto, btype)
@@ -164,17 +166,17 @@ def get_props_from_txt(input_filename):
changed = check_if_changed(bfrom, bto)
# lists formatting
- props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, description]
+ props = [comment, changed, bclass, bfrom, bto, kwcheck, btype, description]
props_list.append(props)
- props_length_max=list(map(max,zip(props_length_max,list(map(len,props)))))
+ props_length_max = list(map(max, zip(props_length_max, list(map(len, props)))))
if done_text in comment:
done += 1
tot += 1
- print("Total done %.2f" % (done / tot * 100.0) )
+ print("Total done %.2f" % (done / tot * 100.0))
- return (props_list,props_length_max)
+ return (props_list, props_length_max)
def get_props_from_py(input_filename):
@@ -185,25 +187,25 @@ def get_props_from_py(input_filename):
# adds the list "rna_api" to this function's scope
rna_api = __import__(input_filename[:-3]).rna_api
- props_length_max = [0 for i in rna_api[0]] # this way if the vector will take more elements we are safe
- for index,props in enumerate(rna_api):
+ props_length_max = [0 for i in rna_api[0]] # this way if the vector will take more elements we are safe
+ for index, props in enumerate(rna_api):
comment, changed, bclass, bfrom, bto, kwcheck, btype, description = props
kwcheck = check_prefix(bto, btype) # keyword-check
changed = check_if_changed(bfrom, bto) # changed?
description = repr(description)
description = description.replace("'", "").replace('"', "").replace("\\", "").strip()
rna_api[index] = [comment, changed, bclass, bfrom, bto, kwcheck, btype, description]
- props_length = list(map(len,props)) # lengths
- props_length_max = list(map(max,zip(props_length_max,props_length))) # max lengths
- return (rna_api,props_length_max)
+ props_length = list(map(len, props)) # lengths
+ props_length_max = list(map(max, zip(props_length_max, props_length))) # max lengths
+ return (rna_api, props_length_max)
def get_props(input_filename):
if input_filename.endswith(".txt"):
- props_list,props_length_max = get_props_from_txt(input_filename)
+ props_list, props_length_max = get_props_from_txt(input_filename)
elif input_filename.endswith(".py"):
- props_list,props_length_max = get_props_from_py(input_filename)
- return (props_list,props_length_max)
+ props_list, props_length_max = get_props_from_py(input_filename)
+ return (props_list, props_length_max)
def sort(props_list, sort_priority):
@@ -222,7 +224,7 @@ def sort(props_list, sort_priority):
else:
props_list = sorted(props_list, key=lambda p: p[i])
- print ('\nSorted by %s.' % font_bold(sort_priority))
+ print('\nSorted by %s.' % font_bold(sort_priority))
return props_list
@@ -250,30 +252,35 @@ def write_files(basename, props_list, props_length_max):
* rna_api.py: unformatted, just as final output
"""
- f_rna = open("rna_api.py",'w')
- f_txt = open(basename + '_work.txt','w')
- f_py = open(basename + '_work.py','w')
+ f_rna = open("rna_api.py", 'w')
+ f_txt = open(basename + '_work.txt', 'w')
+ f_py = open(basename + '_work.py', 'w')
# reminder: props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, description]
# [comment *] ToolSettings.snap_align_rotation -> use_snap_align_rotation: boolean [Align rotation with the snapping target]
rna = py = txt = ''
props_list = [['NOTE', 'CHANGED', 'CLASS', 'FROM', 'TO', 'KEYWORD-CHECK', 'TYPE', 'DESCRIPTION']] + props_list
for props in props_list:
- #txt
+ # txt
# quick way we can tell if it changed
- if props[3] == props[4]: txt += "#"
- else: txt += " "
+ if props[3] == props[4]:
+ txt += "#"
+ else:
+ txt += " "
- if props[0] != '': txt += '%s * ' % props[0] # comment
- txt += '%s.%s -> %s: %s "%s"\n' % tuple(props[2:5] + props[6:]) # skipping keyword-check
+ if props[0] != '':
+ txt += '%s * ' % props[0] # comment
+ txt += '%s.%s -> %s: %s "%s"\n' % tuple(props[2:5] + props[6:]) # skipping keyword-check
# rna_api
- if props[0] == 'NOTE': indent = '# '
- else: indent = ' '
- rna += indent + '("%s", "%s", "%s", "%s", "%s"),\n' % tuple(props[2:5] + props[6:]) # description is already string formatted
+ if props[0] == 'NOTE':
+ indent = '# '
+ else:
+ indent = ' '
+ rna += indent + '("%s", "%s", "%s", "%s", "%s"),\n' % tuple(props[2:5] + props[6:]) # description is already string formatted
# py
- blanks = [' '* (x[0]-x[1]) for x in zip(props_length_max,list(map(len,props)))]
- props = [('"%s"%s' if props[-1] != x[0] else "%s%s") % (x[0],x[1]) for x in zip(props,blanks)]
+ blanks = [' ' * (x[0] - x[1]) for x in zip(props_length_max, list(map(len, props)))]
+ props = [('"%s"%s' if props[-1] != x[0] else "%s%s") % (x[0], x[1]) for x in zip(props, blanks)]
py += indent + '(%s, %s, %s, %s, %s, %s, %s, "%s"),\n' % tuple(props)
f_txt.write(txt)
@@ -290,7 +297,7 @@ def write_files(basename, props_list, props_length_max):
f_py.close()
f_rna.close()
- print ('\nSaved %s, %s and %s.\n' % (font_bold(f_txt.name), font_bold(f_py.name), font_bold(f_rna.name) ) )
+ print('\nSaved %s, %s and %s.\n' % (font_bold(f_txt.name), font_bold(f_py.name), font_bold(f_rna.name)))
def main():
@@ -298,21 +305,21 @@ def main():
global sort_choices, default_sort_choice
global kw_prefixes, kw
- sort_choices = ['note','changed','class','from','to','kw', 'class.to']
+ sort_choices = ['note', 'changed', 'class', 'from', 'to', 'kw', 'class.to']
default_sort_choice = sort_choices[-1]
- kw_prefixes = [ 'active','apply','bl','exclude','has','invert','is','lock', \
- 'pressed','show','show_only','use','use_only','layers','states', 'select']
- kw = ['active','hide','invert','select','layers','mute','states','use','lock']
+ kw_prefixes = ['active', 'apply', 'bl', 'exclude', 'has', 'invert', 'is', 'lock',
+ 'pressed', 'show', 'show_only', 'use', 'use_only', 'layers', 'states', 'select']
+ kw = ['active', 'hide', 'invert', 'select', 'layers', 'mute', 'states', 'use', 'lock']
input_filename, sort_priority = check_commandline()
- props_list,props_length_max = get_props(input_filename)
- props_list = sort(props_list,sort_priority)
+ props_list, props_length_max = get_props(input_filename)
+ props_list = sort(props_list, sort_priority)
output_basename = file_basename(input_filename)
- write_files(output_basename, props_list,props_length_max)
+ write_files(output_basename, props_list, props_length_max)
-if __name__=='__main__':
+if __name__ == '__main__':
import sys
if not sys.version.startswith("3"):
print("Incorrect python version, use python 3!")
diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py b/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py
index a5d5cebcbb7..236313f1f5c 100755
--- a/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py
+++ b/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py
@@ -6,56 +6,58 @@ import sys
Example usage:
python3 rna_cleaner_merge.py out_work.py rna_booleans_work.py
'''
+
+
def main():
- def work_line_id(line):
- return line[2].split("|")[-1], line[3] # class/from
+ def work_line_id(line):
+ return line[2].split("|")[-1], line[3] # class/from
+ if not (sys.argv[-1].endswith(".py") and sys.argv[-2].endswith(".py")):
+ print("Only accepts 2 py files as arguments.")
- if not (sys.argv[-1].endswith(".py") and sys.argv[-2].endswith(".py")):
- print("Only accepts 2 py files as arguments.")
+ sys.path.insert(0, ".")
- sys.path.insert(0, ".")
+ mod_from = __import__(sys.argv[-1][:-3])
+ mod_to = __import__(sys.argv[-2][:-3])
- mod_from = __import__(sys.argv[-1][:-3])
- mod_to = __import__(sys.argv[-2][:-3])
+ mod_to_dict = dict([(work_line_id(line), line) for line in mod_to.rna_api])
+ mod_from_dict = dict([(work_line_id(line), line) for line in mod_from.rna_api])
- mod_to_dict = dict([(work_line_id(line), line) for line in mod_to.rna_api])
- mod_from_dict = dict([(work_line_id(line), line) for line in mod_from.rna_api])
+ rna_api_new = []
- rna_api_new = []
+ for key, val_orig in mod_to_dict.items():
+ try:
+ val_new = mod_from_dict.pop(key)
+ except:
+ # print("not found", key)
+ val_new = val_orig
- for key, val_orig in mod_to_dict.items():
- try:
- val_new = mod_from_dict.pop(key)
- except:
- # print("not found", key)
- val_new = val_orig
+ # always take the class from the base
+ val = list(val_orig)
+ val[0] = val_new[0] # comment
+ val[4] = val_new[4] # -> to
+ val = tuple(val)
+ rna_api_new.append(val)
- # always take the class from the base
- val = list(val_orig)
- val[0] = val_new[0] # comment
- val[4] = val_new[4] # -> to
- val = tuple(val)
- rna_api_new.append(val)
+ def write_work_file(file_path, rna_api):
+ rna_api = list(rna_api)
+ rna_api.sort(key=work_line_id)
+ file_out = open(file_path, "w")
+ file_out.write("rna_api = [\n")
+ for line in rna_api:
+ file_out.write(" %s,\n" % (repr(line)))
+ file_out.write("]\n")
+ file_out.close()
- def write_work_file(file_path, rna_api):
- rna_api = list(rna_api)
- rna_api.sort(key=work_line_id)
- file_out = open(file_path, "w")
- file_out.write("rna_api = [\n")
- for line in rna_api:
- file_out.write(" %s,\n" % (repr(line)))
- file_out.write("]\n")
- file_out.close()
+ file_path = sys.argv[-2][:-3] + "_merged.py"
+ write_work_file(file_path, rna_api_new)
- file_path = sys.argv[-2][:-3] + "_merged.py"
- write_work_file(file_path, rna_api_new)
+ if mod_from_dict:
+ file_path = sys.argv[-2][:-3] + "_lost.py"
+ write_work_file(file_path, list(mod_from_dict.values()))
+ print("Warning '%s' contains lost %d items from module %s.py" % (file_path, len(mod_from_dict), mod_from.__name__))
- if mod_from_dict:
- file_path = sys.argv[-2][:-3] + "_lost.py"
- write_work_file(file_path, list(mod_from_dict.values()))
- print("Warning '%s' contains lost %d items from module %s.py" % (file_path, len(mod_from_dict), mod_from.__name__))
if __name__ == "__main__":
- main()
+ main()
diff --git a/source/blender/python/rna_dump.py b/source/blender/python/rna_dump.py
index 7259ceb67a0..3c09175910e 100644
--- a/source/blender/python/rna_dump.py
+++ b/source/blender/python/rna_dump.py
@@ -129,6 +129,7 @@ def seek(r, txt, recurs):
newtxt = txt + '[' + str(i) + ']'
seek(r[i], newtxt, recurs + 1)
+
seek(bpy.data, 'bpy.data', 0)
# seek(bpy.types, 'bpy.types', 0)
'''
@@ -140,8 +141,8 @@ for d in dir(bpy.types):
seek(r, 'bpy.types.' + d + '.bl_rna', 0)
'''
-#print dir(bpy)
+# print dir(bpy)
#import sys
-#sys.exit()
+# sys.exit()
print("iter over ", seek_count, "rna items")
diff --git a/source/blender/python/simple_enum_gen.py b/source/blender/python/simple_enum_gen.py
index 1c68a7c0e7a..8ac5c782821 100644
--- a/source/blender/python/simple_enum_gen.py
+++ b/source/blender/python/simple_enum_gen.py
@@ -50,8 +50,10 @@ for d in defs.split('\n'):
if not w:
continue
- try: w.remove("#define")
- except: pass
+ try:
+ w.remove("#define")
+ except:
+ pass
# print w