~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons/system_demo_mode/config.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
 
 
4
def blend_list(path):
 
5
    for dirpath, dirnames, filenames in os.walk(path):
 
6
 
 
7
        # skip '.svn'
 
8
        if dirpath.startswith("."):
 
9
            continue
 
10
 
 
11
        for filename in filenames:
 
12
            if filename.lower().endswith(".blend"):
 
13
                filepath = os.path.join(dirpath, filename)
 
14
                yield filepath
 
15
 
 
16
 
 
17
def generate(dirpath, random_order, **kwargs):
 
18
 
 
19
    # in case file is selected!
 
20
    if not os.path.exists(dirpath) or not os.path.isdir(dirpath):
 
21
        dirpath = os.path.dirname(dirpath)
 
22
 
 
23
    files = list(blend_list(dirpath))
 
24
    if random_order:
 
25
        import random
 
26
        random.shuffle(files)
 
27
    else:
 
28
        files.sort()
 
29
 
 
30
    config = []
 
31
    for f in files:
 
32
        defaults = kwargs.copy()
 
33
        defaults["file"] = f
 
34
        config.append(defaults)
 
35
 
 
36
    return config, dirpath
 
37
 
 
38
 
 
39
def as_string(dirpath, random_order, **kwargs):
 
40
    """ Config loader is in demo_mode.py
 
41
    """
 
42
    cfg, dirpath = generate(dirpath, random_order, **kwargs)
 
43
 
 
44
    # hint for reader, can be used if files are not found.
 
45
    cfg_str = []
 
46
    cfg_str += ["# generated file\n"]
 
47
    cfg_str += ["\n"]
 
48
    cfg_str += ["# edit the search path so other systems may find the files below\n"]
 
49
    cfg_str += ["# based on name only if the absolute paths cant be found\n"]
 
50
    cfg_str += ["# Use '//' for current blend file path.\n"]
 
51
    cfg_str += ["\n"]
 
52
    cfg_str += ["search_path = %r\n" % dirpath]
 
53
    cfg_str += ["\n"]
 
54
 
 
55
    # All these work but use nicest formatting!
 
56
    if 0:  # works but not nice to edit.
 
57
        cfg_str += ["config = %r" % cfg]
 
58
    elif 0:
 
59
        import pprint
 
60
        cfg_str += ["config = %s" % pprint.pformat(cfg, indent=0, width=120)]
 
61
    elif 0:
 
62
        cfg_str += [("config = %r" % cfg).replace("{", "\n    {")]
 
63
    else:
 
64
        import pprint
 
65
 
 
66
        def dict_as_kw(d):
 
67
            return "dict(%s)" % ", ".join(("%s=%s" % (k, pprint.pformat(v))) for k, v in sorted(d.items()))
 
68
        ident = "    "
 
69
        cfg_str += ["config = [\n"]
 
70
        for cfg_item in cfg:
 
71
            cfg_str += ["%s%s,\n" % (ident, dict_as_kw(cfg_item))]
 
72
        cfg_str += ["%s]\n\n" % ident]
 
73
 
 
74
    return "".join(cfg_str), dirpath