Mercurial > ~astiob > upreckon > hgweb
comparison upreckon/config.py @ 150:006dce02752c
Added the testee configuration variable and the config.nativize_path function
The testee configuration variable stores the string or iterable of strings to
pass to subprocess.Popen except that the first/only string always follows the
POSIX pathname format or, if the native format is really needed, is prefixed
by slash-slash-colon (the same format is used in Boost.Filesystem).
config.nativize_path is now a part of the public API of the config module.
It converts a path in the format described above into the native format
and can be used in testconf if it needs to use paths other than testee[0].
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Fri, 03 Jun 2011 02:39:02 +0100 |
parents | d5b6708c1955 |
children | 6261eea8a975 |
comparison
equal
deleted
inserted
replaced
149:a1286da36d29 | 150:006dce02752c |
---|---|
12 except ImportError: | 12 except ImportError: |
13 zipimport = None | 13 zipimport = None |
14 else: | 14 else: |
15 zipimport = None | 15 zipimport = None |
16 | 16 |
17 import imp, os, sys, tempfile | 17 import imp, os, posixpath, sys, tempfile |
18 | 18 |
19 __all__ = 'load_problem', 'load_global', 'globalconf' | 19 __all__ = 'load_problem', 'load_global', 'globalconf', 'nativize_path' |
20 | 20 |
21 defaults_problem = {'kind': 'batch', | 21 defaults_problem = {'kind': 'batch', |
22 'usegroups': False, | 22 'usegroups': False, |
23 'maxcputime': None, | 23 'maxcputime': None, |
24 'maxwalltime': None, | 24 'maxwalltime': None, |
80 | 80 |
81 def __exit__(self, exc_type, exc_val, exc_tb): | 81 def __exit__(self, exc_type, exc_val, exc_tb): |
82 self.file.close() | 82 self.file.close() |
83 os.remove(self.name) | 83 os.remove(self.name) |
84 | 84 |
85 def nativize_path(portable_path): | |
86 if portable_path.startswith('//:'): | |
87 return portable_path[3:] | |
88 comps = portable_path.split('/') | |
89 for i, comp in enumerate(comps): | |
90 if comp == '..': | |
91 comps[i] = os.path.pardir | |
92 elif comp == '.': | |
93 comps[i] = os.path.curdir | |
94 native_path = os.path.join(*comps) | |
95 if posixpath.isabs(portable_path) != os.path.isabs(native_path): | |
96 native_path = os.path.sep + native_path | |
97 if posixpath.isabs(portable_path) != os.path.isabs(native_path): | |
98 raise ValueError('cannot make native path relative/absolute') | |
99 return native_path | |
100 | |
85 def load_problem(problem_name): | 101 def load_problem(problem_name): |
86 global builtins | 102 global builtins |
87 try: | 103 try: |
88 dwb = sys.dont_write_bytecode | 104 dwb = sys.dont_write_bytecode |
89 sys.dont_write_bytecode = True | 105 sys.dont_write_bytecode = True |
90 except AttributeError: | 106 except AttributeError: |
91 pass | 107 pass |
92 metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration') | 108 metafile = files.File(problem_name + '/testconf.py', True, 'configuration') |
93 module = None | 109 module = None |
94 with CompatBuiltins() as builtins: | 110 with CompatBuiltins() as builtins: |
95 if zipimport and isinstance(metafile.archive, files.ZipArchive): | 111 if zipimport and isinstance(metafile.archive, files.ZipArchive): |
96 try: | 112 try: |
97 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf') | 113 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf') |
132 setattr(module, name, getattr(module, name, defaults_problem[name])) | 148 setattr(module, name, getattr(module, name, defaults_problem[name])) |
133 if not module.dummyinname: | 149 if not module.dummyinname: |
134 module.dummyinname = getattr(module, 'testcaseinname', module.dummyinname) | 150 module.dummyinname = getattr(module, 'testcaseinname', module.dummyinname) |
135 if not module.dummyoutname: | 151 if not module.dummyoutname: |
136 module.dummyoutname = getattr(module, 'testcaseoutname', module.dummyoutname) | 152 module.dummyoutname = getattr(module, 'testcaseoutname', module.dummyoutname) |
137 if not hasattr(module, 'path'): | 153 if hasattr(module, 'testee'): |
154 if isinstance(module.testee, basestring): | |
155 module.path = nativize_path(module.testee) | |
156 else: | |
157 testee = tuple(module.testee) | |
158 module.path = (nativize_path(testee[0]),) + testee[1:] | |
159 elif not hasattr(module, 'path'): | |
138 if hasattr(module, 'name'): | 160 if hasattr(module, 'name'): |
139 module.path = module.name | 161 module.path = module.name |
140 elif sys.platform != 'win32': | 162 elif sys.platform != 'win32': |
141 module.path = os.path.join(os.path.curdir, problem_name) | 163 module.path = os.path.join(os.path.curdir, problem_name) |
142 else: | 164 else: |