pep8 cleanup

This commit is contained in:
Campbell Barton
2011-01-01 07:20:34 +00:00
parent 2840e7b764
commit 7f3fe8a2df
47 changed files with 288 additions and 303 deletions

View File

@@ -22,11 +22,12 @@
This module has utility functions for renaming
rna values in fcurves and drivers.
The main function to use is: update_data_paths(...)
The main function to use is: update_data_paths(...)
"""
IS_TESTING = False
class DataPathBuilder(object):
__slots__ = ("data_path", )
""" Dummy class used to parse fcurve and driver data paths.
@@ -37,7 +38,7 @@ class DataPathBuilder(object):
def __getattr__(self, attr):
str_value = ".%s" % attr
return DataPathBuilder(self.data_path + (str_value, ))
def __getitem__(self, key):
str_value = '["%s"]' % key
return DataPathBuilder(self.data_path + (str_value, ))
@@ -51,7 +52,7 @@ class DataPathBuilder(object):
if base is not Ellipsis:
try:
# this only works when running with an old blender
# where the old path will resolve
# where the old path will resolve
base = eval("base" + item)
except:
base_new = Ellipsis
@@ -61,7 +62,7 @@ class DataPathBuilder(object):
try:
print("base." + item_new)
base_new = eval("base." + item_new)
break # found, dont keep looking
break # found, dont keep looking
except:
pass
@@ -77,7 +78,7 @@ import bpy
def id_iter():
type_iter = type(bpy.data.objects)
for attr in dir(bpy.data):
data_iter = getattr(bpy.data, attr, None)
if type(data_iter) == type_iter:
@@ -115,13 +116,13 @@ def find_path_new(id_data, data_path, rna_update_dict, rna_update_from_map):
# ignore ID props for now
if data_path.startswith("["):
return data_path
# recursive path fixing, likely will be one in most cases.
data_path_builder = eval("DataPathBuilder(tuple())." + data_path)
data_resolve = data_path_builder.resolve(id_data, rna_update_from_map)
path_new = [pair[0] for pair in data_resolve]
# print(data_resolve)
data_base = id_data
@@ -138,20 +139,20 @@ def find_path_new(id_data, data_path, rna_update_dict, rna_update_from_map):
# set this as the base for further properties
data_base = data
data_path_new = "".join(path_new)[1:] # skip the first "."
data_path_new = "".join(path_new)[1:] # skip the first "."
return data_path_new
def update_data_paths(rna_update):
''' rna_update triple [(class_name, from, to), ...]
'''
# make a faster lookup dict
rna_update_dict = {}
for ren_class, ren_from, ren_to in rna_update:
rna_update_dict.setdefault(ren_class, {})[ren_from] = ren_to
rna_update_from_map = {}
for ren_class, ren_from, ren_to in rna_update:
rna_update_from_map.setdefault(ren_from, []).append(ren_to)
@@ -174,7 +175,7 @@ def update_data_paths(rna_update):
for tar in var.targets:
id_data_other = tar.id
data_path = tar.data_path
if id_data_other and data_path:
data_path_new = find_path_new(id_data_other, data_path, rna_update_dict, rna_update_from_map)
# print(data_path_new)
@@ -182,9 +183,7 @@ def update_data_paths(rna_update):
if not IS_TESTING:
tar.data_path = data_path_new
print("driver (%s): %s -> %s" % (id_data_other.name, data_path, data_path_new))
for action in anim_data_actions(anim_data):
for fcu in action.fcurves:
data_path = fcu.data_path

View File

@@ -48,7 +48,7 @@ def _main():
pydoc.getpager = lambda: pydoc.plainpager
pydoc.Helper.getline = lambda self, prompt: None
pydoc.TextDoc.use_bold = lambda self, text: text
# Possibly temp. addons path
from os.path import join, dirname, normpath
_sys.path.append(normpath(join(dirname(__file__), "..", "..", "addons", "modules")))

View File

@@ -137,13 +137,12 @@ class bpy_ops_submodule_op(object):
@staticmethod
def _scene_update(context):
scene = context.scene
if scene: # None in backgroud mode
if scene: # None in backgroud mode
scene.update()
else:
import bpy
for scene in bpy.data.scenes:
scene.update()
__doc__ = property(_get_doc)
@@ -196,7 +195,8 @@ class bpy_ops_submodule_op(object):
as_string = op_as_string(idname)
op_class = getattr(bpy.types, idname)
descr = op_class.bl_rna.description
# XXX, workaround for not registering every __doc__ to save time on load.
# XXX, workaround for not registering
# every __doc__ to save time on load.
if not descr:
descr = op_class.__doc__
if not descr:

View File

@@ -204,7 +204,7 @@ def module_names(path, recursive=False):
for filename in sorted(_os.listdir(path)):
if filename == "modules":
pass # XXX, hard coded exception.
pass # XXX, hard coded exception.
elif filename.endswith(".py") and filename != "__init__.py":
fullpath = join(path, filename)
modules.append((filename[0:-3], fullpath))

View File

@@ -31,6 +31,7 @@ import bpy as _bpy
import os as _os
import sys as _sys
def _test_import(module_name, loaded_modules):
import traceback
import time
@@ -203,13 +204,11 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
# deal with addons seperately
addon_reset_all(reload_scripts)
# run the active integration preset
filepath = preset_find(_bpy.context.user_preferences.inputs.active_keyconfig, "keyconfig")
if filepath:
keyconfig_set(filepath)
if reload_scripts:
import gc
print("gc.collect() -> %d" % gc.collect())
@@ -368,7 +367,6 @@ def addon_enable(module_name, default_set=True):
import bpy_types as _bpy_types
import imp
_bpy_types._register_immediate = False
def handle_error():
@@ -376,7 +374,6 @@ def addon_enable(module_name, default_set=True):
traceback.print_exc()
_bpy_types._register_immediate = True
# reload if the mtime changes
mod = sys.modules.get(module_name)
if mod:
@@ -428,7 +425,7 @@ def addon_enable(module_name, default_set=True):
if not ext:
ext = _bpy.context.user_preferences.addons.new()
ext.module = module_name
_bpy_types._register_immediate = True
mod.__addon_enabled__ = True
@@ -471,7 +468,7 @@ def addon_disable(module_name, default_set=True):
addon = addons.get(module_name)
if addon:
addons.remove(addon)
print("\tbpy.utils.addon_disable", module_name)
@@ -483,10 +480,10 @@ def addon_reset_all(reload_scripts=False):
# RELEASE SCRIPTS: official scripts distributed in Blender releases
paths = script_paths("addons")
# CONTRIB SCRIPTS: good for testing but not official scripts yet
paths += script_paths("addons_contrib")
# EXTERN SCRIPTS: external projects scripts
paths += script_paths("addons_extern")
@@ -513,9 +510,9 @@ def addon_reset_all(reload_scripts=False):
def preset_find(name, preset_path, display_name=False):
if not name:
return None
for directory in preset_paths(preset_path):
if display_name:
filename = ""
for fn in _os.listdir(directory):
@@ -558,7 +555,7 @@ def keyconfig_set(filepath):
keyconfigs.remove(kc_dupe)
else:
break
kc_new.name = name
keyconfigs.active = kc_new
@@ -595,4 +592,3 @@ def user_resource(type, path="", create=False):
target_path = ""
return target_path

View File

@@ -638,7 +638,7 @@ class OrderedMeta(RNAMeta):
# with doc generation 'self.properties.bl_rna.properties' can fail
class Operator(StructRNA, metaclass=OrderedMeta):
__slots__ = ()
def __getattribute__(self, attr):
properties = StructRNA.path_resolve(self, "properties")
bl_rna = getattr(properties, "bl_rna", None)
@@ -745,7 +745,7 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
import bpy.utils
layout = self.layout
if not searchpaths:
layout.label("* Missing Paths *")

View File

@@ -60,7 +60,7 @@ def rna_idprop_ui_prop_clear(item, prop):
def rna_idprop_context_value(context, context_member, property_type):
space = context.space_data
if space is None or isinstance(space, bpy.types.SpaceProperties):
pin_id = space.pin_id
else:

View File

@@ -25,83 +25,87 @@ import bgl
import sys
def cutPoint(text, length):
"Returns position of the last space found before 'length' chars"
l = length
c = text[l]
while c != ' ':
l -= 1
if l == 0: return length # no space found
c = text[l]
return l
def textWrap(text, length = 70):
lines = []
while len(text) > 70:
cpt = cutPoint(text, length)
line, text = text[:cpt], text[cpt + 1:]
lines.append(line)
lines.append(text)
return lines
def cutPoint(text, length):
"Returns position of the last space found before 'length' chars"
l = length
c = text[l]
while c != ' ':
l -= 1
if l == 0:
return length # no space found
c = text[l]
return l
def textWrap(text, length=70):
lines = []
while len(text) > 70:
cpt = cutPoint(text, length)
line, text = text[:cpt], text[cpt + 1:]
lines.append(line)
lines.append(text)
return lines
def write_sysinfo(op):
output_filename = "system-info.txt"
warnings = 0
notices = 0
output_filename = "system-info.txt"
warnings = 0
notices = 0
if output_filename in bpy.data.texts.keys():
output = bpy.data.texts[output_filename]
output.clear()
else:
output = bpy.data.texts.new(name=output_filename)
if output_filename in bpy.data.texts.keys():
output = bpy.data.texts[output_filename]
output.clear()
else:
output = bpy.data.texts.new(name=output_filename)
header = '= Blender {} System Information =\n'.format(bpy.app.version_string)
lilies = '{}\n\n'.format(len(header)*'=')
firstlilies = '{}\n'.format(len(header)*'=')
output.write(firstlilies)
output.write(header)
output.write(lilies)
header = '= Blender {} System Information =\n'.format(bpy.app.version_string)
lilies = '{}\n\n'.format(len(header) * '=')
firstlilies = '{}\n'.format(len(header) * '=')
output.write(firstlilies)
output.write(header)
output.write(lilies)
# build info
output.write('\nBlender:\n')
output.write(lilies)
output.write('version {}, revision {}. {}\n'.format(bpy.app.version_string, bpy.app.build_revision, bpy.app.build_type))
output.write('build date: {}, {}\n'.format(bpy.app.build_date, bpy.app.build_time))
output.write('platform: {}\n'.format(bpy.app.build_platform))
output.write('binary path: {}\n'.format(bpy.app.binary_path))
output.write('build cflags: {}\n'.format(bpy.app.build_cflags))
output.write('build cxxflags: {}\n'.format(bpy.app.build_cxxflags))
output.write('build linkflags: {}\n'.format(bpy.app.build_linkflags))
output.write('build system: {}\n'.format(bpy.app.build_system))
# build info
output.write('\nBlender:\n')
output.write(lilies)
output.write('version {}, revision {}. {}\n'.format(bpy.app.version_string, bpy.app.build_revision, bpy.app.build_type))
output.write('build date: {}, {}\n'.format(bpy.app.build_date, bpy.app.build_time))
output.write('platform: {}\n'.format(bpy.app.build_platform))
output.write('binary path: {}\n'.format(bpy.app.binary_path))
output.write('build cflags: {}\n'.format(bpy.app.build_cflags))
output.write('build cxxflags: {}\n'.format(bpy.app.build_cxxflags))
output.write('build linkflags: {}\n'.format(bpy.app.build_linkflags))
output.write('build system: {}\n'.format(bpy.app.build_system))
# python info
output.write('\nPython:\n')
output.write(lilies)
output.write('version: {}\n'.format(sys.version))
output.write('paths:\n')
for p in sys.path:
output.write('\t{}\n'.format(p))
# python info
output.write('\nPython:\n')
output.write(lilies)
output.write('version: {}\n'.format(sys.version))
output.write('paths:\n')
for p in sys.path:
output.write('\t{}\n'.format(p))
output.write('\nDirectories:\n')
output.write(lilies)
output.write('scripts: {}\n'.format(bpy.utils.script_paths()))
output.write('user scripts: {}\n'.format(bpy.utils.user_script_path()))
output.write('datafiles: {}\n'.format(bpy.utils.user_resource('DATAFILES')))
output.write('config: {}\n'.format(bpy.utils.user_resource('CONFIG')))
output.write('scripts : {}\n'.format(bpy.utils.user_resource('SCRIPTS')))
output.write('autosave: {}\n'.format(bpy.utils.user_resource('AUTOSAVE')))
output.write('tempdir: {}\n'.format(bpy.app.tempdir))
output.write('\nDirectories:\n')
output.write(lilies)
output.write('scripts: {}\n'.format(bpy.utils.script_paths()))
output.write('user scripts: {}\n'.format(bpy.utils.user_script_path()))
output.write('datafiles: {}\n'.format(bpy.utils.user_resource('DATAFILES')))
output.write('config: {}\n'.format(bpy.utils.user_resource('CONFIG')))
output.write('scripts : {}\n'.format(bpy.utils.user_resource('SCRIPTS')))
output.write('autosave: {}\n'.format(bpy.utils.user_resource('AUTOSAVE')))
output.write('tempdir: {}\n'.format(bpy.app.tempdir))
output.write('\nOpenGL\n')
output.write(lilies)
output.write('renderer:\t{}\n'.format(bgl.glGetString(bgl.GL_RENDERER)))
output.write('vendor:\t\t{}\n'.format(bgl.glGetString(bgl.GL_VENDOR)))
output.write('version:\t{}\n'.format(bgl.glGetString(bgl.GL_VERSION)))
output.write('extensions:\n')
output.write('\nOpenGL\n')
output.write(lilies)
output.write('renderer:\t{}\n'.format(bgl.glGetString(bgl.GL_RENDERER)))
output.write('vendor:\t\t{}\n'.format(bgl.glGetString(bgl.GL_VENDOR)))
output.write('version:\t{}\n'.format(bgl.glGetString(bgl.GL_VERSION)))
output.write('extensions:\n')
glext = bgl.glGetString(bgl.GL_EXTENSIONS)
glext = textWrap(glext, 70)
for l in glext:
output.write('\t\t{}\n'.format(l))
op.report({'INFO'}, "System information generated in 'system-info.txt'")
glext = bgl.glGetString(bgl.GL_EXTENSIONS)
glext = textWrap(glext, 70)
for l in glext:
output.write('\t\t{}\n'.format(l))
op.report({'INFO'}, "System information generated in 'system-info.txt'")