now exportdirs.py supports relative paths (still needs cleanup)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-05-28 15:39:59 +04:00
parent 1487b4c5d4
commit 220ec2fefd

View File

@ -1,7 +1,7 @@
#======================================================================= #=======================================================================
__version__ = '''0.0.01''' __version__ = '''0.0.01'''
__sub_version__ = '''20130528044626''' __sub_version__ = '''20130528153701'''
__copyright__ = '''(c) Alex A. Naanou 2011''' __copyright__ = '''(c) Alex A. Naanou 2011'''
@ -12,10 +12,17 @@ import shutil
import json import json
import urllib2 import urllib2
from pli.logictypes import OR
from pprint import pprint from pprint import pprint
#-----------------------------------------------------------------------
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
#----------------------------------------------------------build_dirs--- #----------------------------------------------------------build_dirs---
##!!! make this relative-path compatible... ##!!! make this relative-path compatible...
@ -32,8 +39,17 @@ def build_dirs(data, path, rewrite=None):
# gen3 # gen3
if version == '2.0': if version == '2.0':
#images = json.load(open(data['image_file'], 'r')) ##!!! get base path...
##!!!
img = data['image_file']
# absolute path...
if img.startswith('file:///'):
images = json.load(urllib2.urlopen(data['image_file'])) images = json.load(urllib2.urlopen(data['image_file']))
# relative...
else:
images = json.load(open(os.path.join(path, data['image_file']), 'r'))
def get_image(gid, _): def get_image(gid, _):
return images[gid] return images[gid]
@ -58,11 +74,20 @@ def build_dirs(data, path, rewrite=None):
for guid in ribbon: for guid in ribbon:
image = get_image(guid, ribbon) image = get_image(guid, ribbon)
try: try:
# XXX for some magical reason this works and url2pathname does not... p = image['path']
##!!! this will also break on utf paths... # absolute path...
img = urllib2.urlopen(image['path']) if img.startswith('file:///'):
p = img.fp.name ## # XXX for some magical reason this works and url2pathname does not...
img.close() ## ##!!! this will also break on utf paths...
## img = urllib2.urlopen(image['path'])
## p = img.fp.name
## img.close()
p = urllib2.decode(p)
p = p.split('file:///')[-1]
# relative path...
else:
p = os.path.join(path, p)
# XXX do we need to indicate overwriting in the status? # XXX do we need to indicate overwriting in the status?
if rewrite == 'force' or not os.path.exists(os.path.join(level_path, os.path.split(p)[-1])): if rewrite == 'force' or not os.path.exists(os.path.join(level_path, os.path.split(p)[-1])):