4 The Blender.sys submodule.
9 B{New}: L{exists}, L{makename}, L{join}.
11 This module provides a minimal set of helper functions and data. Its purpose
12 is to avoid the need for the standard Python module 'os', in special 'os.path',
13 though it is only meant for the simplest cases.
20 def f(name): # file selector callback
24 Blender.Window.FileSelector(f)
27 print 'basename:', Blender.sys.basename(filename)
28 print 'dirname:', Blender.sys.dirname(filename)
29 print 'splitext:', Blender.sys.splitext(filename)
31 # what would basename(splitext(filename)[0]) print?
34 @var sep: the platform-specific dir separator for this Blender: '/'
35 everywhere, except on Win systems, that use '\\'.
37 @var dirsep: same as L{sep}.
38 @type progname: string
39 @var progname: the Blender executable (argv[0]).
41 @attention: The module is called sys, not Sys.
46 Get the base name (filename stripped from dir info) of 'path'.
48 @param path: a path name
50 @return: the base name
55 Get the dir name (dir path stripped from filename) of 'path'.
57 @param path: a path name
64 Join the given dir and file paths, using the proper separator for each
68 @param dir: the dir name, like returned from L{dirname}.
69 @param file: the bare filename, like returned from L{basename}.
71 @return: the resulting filename.
72 @warn: this simple function isn't intended to be a complete replacement for
73 the standard os.path.join() one, which handles more general cases.
78 Split 'path' into (root, ext), where 'ext' is a file extension.
80 @param path: a path name
81 @rtype: list with two strings
85 def makename (path = "Blender.Get('filename')", ext = "", strip = 0):
87 Remove extension from 'path', append extension 'ext' (if given)
88 to the result and return it. If 'strip' is non-zero, also remove
93 from Blender.sys import *
94 print makename('/path/to/myfile.txt','.abc', 1) # returns 'myfile.abc'
96 print makename('/path/to/myfile.obj', '-01.obj') # '/path/to/myfile-01.obj'
98 print makename('/path/to/myfile.txt', strip = 1) # 'myfile'
101 print makename(ext = '.txt')
103 print sys.splitext(Blender.Get('filename'))[0]) + '.txt'
106 @param path: a path name or Blender.Get('filename'), if not given.
108 @param ext: an extension to append. For flexibility, a dot ('.') is
109 not automatically included.
111 @return: the resulting string
116 Tell if the given pathname (file or dir) exists.
118 @return: 1 if 'path' exists, 0 otherwise.
123 Get the current time in seconds since a fixed value. Successive calls to
124 this function are garanteed to return values greater than the previous call.
126 @return: the elapsed time in seconds.