~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons_contrib/io_directx_bel/bel/fs.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-05-12 20:02:22 UTC
  • mfrom: (14.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120512200222-lznjs2cxzaq96wua
Tags: 2.63a-1
* New upstream bugfix release
  + debian/patches/: re-worked since source code changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# v0.1
2
 
import bpy
3
 
from os import path as os_path, listdir as os_listdir
4
 
from bpy import path as bpy_path
5
 
 
6
 
# cross platform paths (since ms conform to / path ;) )
7
 
# maybe add utf8 replace to old ascii blender builtin
8
 
# // can be omitted for relative
9
 
def clean(path) :
10
 
    path = path.strip().replace('\\','/')
11
 
    if ('/') not in path : path = '//'+path
12
 
    return path
13
 
    
14
 
## test for existence of a file or a dir
15
 
def exist(path) :
16
 
    if isfile(path) or isdir(path) : return True
17
 
    return False
18
 
 
19
 
## test for existence of a file
20
 
def isfile(path) :
21
 
    if os_path.isfile(path) : return True
22
 
    # could be blender relative
23
 
    path = bpy_path.abspath(path)
24
 
    if os_path.isfile(path) : return True
25
 
    return False
26
 
 
27
 
## test for existence of a dir
28
 
def isdir(path) :
29
 
    if os_path.isdir(path) : return True
30
 
    # could be blender relative
31
 
    path = bpy_path.abspath(path)
32
 
    if os_path.isdir(path) : return True
33
 
    return False
34
 
 
35
 
## returns a list of every absolute filepath
36
 
# to each file within the 'ext' extensions
37
 
# from a folder and its subfolders
38
 
def scanDir(path,ext='all') :
39
 
    files = []
40
 
    fields = os_listdir(path)
41
 
    if ext != 'all' and type(ext) != list : ext = [ext]
42
 
    for item in fields :
43
 
        if os_path.isfile(path + '/' + item) and (ext == 'all' or item.split('.')[-1] in ext) :
44
 
            #print('  file %s'%item)
45
 
            files.append(path + '/' + item)
46
 
        elif os_path.isdir(path + '/' + item) :
47
 
            print('folder %s/%s :'%(path,item))
48
 
            files.extend(scanDir(path + '/' + item))
49
 
    return files
50
 
 
51
 
def saveOptions(operator_name, tokens, filename='last_run'):
52
 
    target_path = os_path.join("operator", operator_name)
53
 
    target_path = os_path.join("presets", target_path)
54
 
    target_path = bpy.utils.user_resource('SCRIPTS',target_path,create=True)
55
 
    if target_path:
56
 
        filepath = os_path.join(target_path, filename) + ".py"
57
 
        file_preset = open(filepath, 'w')
58
 
        file_preset.write("import bpy\nop = bpy.context.active_operator\n\n")
59
 
        properties_blacklist = bpy.types.Operator.bl_rna.properties.keys()
60
 
        for key, value in tokens.items() :
61
 
            if key not in properties_blacklist :
62
 
                # convert thin wrapped sequences to simple lists to repr()
63
 
                try:
64
 
                    value = value[:]
65
 
                except:
66
 
                    pass
67
 
    
68
 
                file_preset.write("op.%s = %r\n" % (key, value))
69
 
 
70
 
        file_preset.close()
71