[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34230] trunk/blender/release/scripts/op/ io_scene_x3d/import_x3d.py: x3d import now passes pep8 checker
Campbell Barton
ideasman42 at gmail.com
Mon Jan 10 14:56:16 CET 2011
Revision: 34230
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34230
Author: campbellbarton
Date: 2011-01-10 13:56:14 +0000 (Mon, 10 Jan 2011)
Log Message:
-----------
x3d import now passes pep8 checker
Modified Paths:
--------------
trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py
Modified: trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py 2011-01-10 13:16:04 UTC (rev 34229)
+++ trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py 2011-01-10 13:56:14 UTC (rev 34230)
@@ -26,17 +26,23 @@
except:
from os.path import exists
+
def baseName(path):
return path.split('/')[-1].split('\\')[-1]
+
def dirName(path):
return path[:-len(baseName(path))]
+
def imageConvertCompat(path):
- try: import os
- except: return path
- if os.sep=='\\': return path # assime win32 has quicktime, dont convert
+ try:
+ import os
+ except:
+ return path
+ if os.sep == '\\':
+ return path # assime win32 has quicktime, dont convert
if path.lower().endswith('.gif'):
path_to = path[:-3] + 'png'
@@ -45,8 +51,8 @@
if exists(path_to):
return path_to
'''
- # print '\n'+path+'\n'+path_to+'\n'
- os.system('convert "%s" "%s"' % (path, path_to)) # for now just hope we have image magick
+ # print('\n'+path+'\n'+path_to+'\n')
+ os.system('convert "%s" "%s"' % (path, path_to)) # for now just hope we have image magick
if exists(path_to):
return path_to
@@ -61,10 +67,8 @@
# rotation first defines axis then ammount in radians
-
# =============================== VRML Spesific
-
def vrmlFormat(data):
'''
Keep this as a valid vrml file, but format in a way we can predict.
@@ -79,35 +83,35 @@
i = l.find('#')
- if i==-1:
+ if i == -1:
return l
# Most cases accounted for! if we have a comment at the end of the line do this...
#j = l.find('url "')
j = l.find('"')
- if j == -1: # simple no strings
+ if j == -1: # simple no strings
return l[:i].strip()
q = False
- for i,c in enumerate(l):
+ for i, c in enumerate(l):
if c == '"':
- q = not q # invert
+ q = not q # invert
elif c == '#':
- if q==False:
- return l[:i-1]
+ if q == False:
+ return l[:i - 1]
return l
- data = '\n'.join([strip_comment(l) for l in data.split('\n') ]) # remove all whitespace
+ data = '\n'.join([strip_comment(l) for l in data.split('\n')]) # remove all whitespace
- EXTRACT_STRINGS = True # only needed when strings or filesnames containe ,[]{} chars :/
+ EXTRACT_STRINGS = True # only needed when strings or filesnames containe ,[]{} chars :/
if EXTRACT_STRINGS:
# We need this so we can detect URL's
- data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
+ data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
string_ls = []
@@ -121,20 +125,19 @@
i = data.find(search, last_i)
if i != -1:
- start = i + len(search) # first char after end of search
+ start = i + len(search) # first char after end of search
end = data.find('"', start)
if end != -1:
item = data[start:end]
- string_ls.append( item )
+ string_ls.append(item)
data = data[:start] + data[end:]
- ok = True # keep looking
+ ok = True # keep looking
last_i = (end - len(item)) + 1
- # print last_i, item, '|' + data[last_i] + '|'
+ # print(last_i, item, '|' + data[last_i] + '|')
# done with messy extracting strings part
-
# Bad, dont take strings into account
'''
data = data.replace('#', '\n#')
@@ -144,35 +147,34 @@
data = data.replace('}', '\n}\n')
data = data.replace('[', '\n[\n')
data = data.replace(']', '\n]\n')
- data = data.replace(',', ' , ') # make sure comma's seperate
+ data = data.replace(',', ' , ') # make sure comma's seperate
if EXTRACT_STRINGS:
# add strings back in
- search = '"' # fill in these empty strings
+ search = '"' # fill in these empty strings
ok = True
last_i = 0
while ok:
ok = False
i = data.find(search + '"', last_i)
- # print i
+ # print(i)
if i != -1:
- start = i + len(search) # first char after end of search
+ start = i + len(search) # first char after end of search
item = string_ls.pop(0)
- # print item
+ # print(item)
data = data[:start] + item + data[start:]
last_i = start + len(item) + 1
ok = True
-
# More annoying obscure cases where USE or DEF are placed on a newline
# data = data.replace('\nDEF ', ' DEF ')
# data = data.replace('\nUSE ', ' USE ')
- data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
+ data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
# Better to parse the file accounting for multiline arrays
'''
@@ -182,30 +184,31 @@
return [l for l in data.split('\n') if l]
-NODE_NORMAL = 1 # {}
-NODE_ARRAY = 2 # []
-NODE_REFERENCE = 3 # USE foobar
+NODE_NORMAL = 1 # {}
+NODE_ARRAY = 2 # []
+NODE_REFERENCE = 3 # USE foobar
# NODE_PROTO = 4 #
lines = []
+
def getNodePreText(i, words):
- # print lines[i]
+ # print(lines[i])
use_node = False
while len(words) < 5:
- if i>=len(lines):
+ if i >= len(lines):
break
'''
elif lines[i].startswith('PROTO'):
return NODE_PROTO, i+1
'''
- elif lines[i]=='{':
+ elif lines[i] == '{':
# words.append(lines[i]) # no need
- # print "OK"
- return NODE_NORMAL, i+1
- elif lines[i].count('"') % 2 != 0: # odd number of quotes? - part of a string.
- # print 'ISSTRING'
+ # print("OK")
+ return NODE_NORMAL, i + 1
+ elif lines[i].count('"') % 2 != 0: # odd number of quotes? - part of a string.
+ # print('ISSTRING')
break
else:
new_words = lines[i].split()
@@ -218,16 +221,17 @@
# Check for USE node - no {
# USE #id - should always be on the same line.
if use_node:
- # print 'LINE', i, words[:words.index('USE')+2]
- words[:] = words[:words.index('USE')+2]
- if lines[i] == '{' and lines[i+1] == '}':
+ # print('LINE', i, words[:words.index('USE')+2])
+ words[:] = words[:words.index('USE') + 2]
+ if lines[i] == '{' and lines[i + 1] == '}':
# USE sometimes has {} after it anyway
- i+=2
+ i += 2
return NODE_REFERENCE, i
- # print "error value!!!", words
+ # print("error value!!!", words)
return 0, -1
+
def is_nodeline(i, words):
if not lines[i][0].isalpha():
@@ -239,10 +243,10 @@
# Is this a prototype??
if lines[i].startswith('PROTO'):
words[:] = lines[i].split()
- return NODE_NORMAL, i+1 # TODO - assumes the next line is a '[\n', skip that
+ return NODE_NORMAL, i + 1 # TODO - assumes the next line is a '[\n', skip that
if lines[i].startswith('EXTERNPROTO'):
words[:] = lines[i].split()
- return NODE_ARRAY, i+1 # TODO - assumes the next line is a '[\n', skip that
+ return NODE_ARRAY, i + 1 # TODO - assumes the next line is a '[\n', skip that
'''
proto_type, new_i = is_protoline(i, words, proto_field_defs)
@@ -251,21 +255,22 @@
'''
# Simple "var [" type
- if lines[i+1] == '[':
+ if lines[i + 1] == '[':
if lines[i].count('"') % 2 == 0:
words[:] = lines[i].split()
- return NODE_ARRAY, i+2
+ return NODE_ARRAY, i + 2
node_type, new_i = getNodePreText(i, words)
if not node_type:
- if DEBUG: print "not node_type", lines[i]
+ if DEBUG:
+ print("not node_type", lines[i])
return 0, 0
# Ok, we have a { after some values
# Check the values are not fields
for i, val in enumerate(words):
- if i != 0 and words[i-1] in ('DEF', 'USE'):
+ if i != 0 and words[i - 1] in ('DEF', 'USE'):
# ignore anything after DEF, it is a ID and can contain any chars.
pass
elif val[0].isalpha() and val not in ('TRUE', 'FALSE'):
@@ -275,9 +280,10 @@
return 0, 0
#if node_type==NODE_REFERENCE:
- # print words, "REF_!!!!!!!"
+ # print(words, "REF_!!!!!!!")
return node_type, new_i
+
def is_numline(i):
'''
Does this line start with a number?
@@ -307,27 +313,45 @@
if l.startswith(', '):
line_start += 2
- line_end = len(l)-1
- line_end_new = l.find(' ', line_start) # comma's always have a space before them
+ line_end = len(l) - 1
+ line_end_new = l.find(' ', line_start) # comma's always have a space before them
if line_end_new != -1:
line_end = line_end_new
try:
- float(l[line_start:line_end]) # works for a float or int
+ float(l[line_start:line_end]) # works for a float or int
return True
except:
return False
class vrmlNode(object):
- __slots__ = 'id', 'fields', 'proto_node', 'proto_field_defs', 'proto_fields', 'node_type', 'parent', 'children', 'parent', 'array_data', 'reference', 'lineno', 'filename', 'blendObject', 'DEF_NAMESPACE', 'ROUTE_IPO_NAMESPACE', 'PROTO_NAMESPACE', 'x3dNode'
+ __slots__ = ('id',
+ 'fields',
+ 'proto_node',
+ 'proto_field_defs',
+ 'proto_fields',
+ 'node_type',
+ 'parent',
+ 'children',
+ 'parent',
+ 'array_data',
+ 'reference',
+ 'lineno',
+ 'filename',
+ 'blendObject',
+ 'DEF_NAMESPACE',
+ 'ROUTE_IPO_NAMESPACE',
+ 'PROTO_NAMESPACE',
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list