def spawnViewer(self, fp): """ Spawns the first available image viewer specified in my I{exList}. "Returns" a C{Deferred} that fires with the PID of the spawned image viewer process. """ for ex in self.exList: exPath = ex[0] if os.path.exists(exPath): self.ivp = self.IV_Protocol() args = [os.path.basename(exPath)] for arg in ex[1:]: if "{}" in arg: arg = arg.replace("{}", os.path.basename(fp.path)) args.append(arg) args.append(fp.path) self.transport = reactor.spawnProcess(self.ivp, exPath, args, env=None) self.savePID(self.transport.pid) stderr = yield self.ivp.d if stderr: if not self.noComplain: msg(0, "Error launching '{}':\n{}", args[0], stderr) else: break else: if not self.noComplain: msg(0, "No image viewer found")
def tearDown(self): msg(None) while self.pendingCalls: call = list(self.pendingCalls.keys())[0] if call.active(): self.pendingCalls[call].callback(None) call.cancel() msg(None)
def __init__(self, *args, **kw): if getattr(self, 'verbose', False) or globals().get('VERBOSE', False): msg(True) self.pendingCalls = {} super(TestCase, self).__init__(*args, **kw)
def extract_examples(): """ Call via the I{ade-examples} entry point to extract example files to a subdirectory I{ade-examples} of your home directory, creating the subdirectory if necessary. It will not overwrite existing files, so feel free to modify the examples. Delete a modified example file (or the whole subdirectory) and run this again to restore the default file. """ import re pkg_dir = ('ade', 'examples') from ade.util import msg msg(True) import os, os.path, shutil, pkg_resources sDir = pkg_resources.resource_filename(*pkg_dir) eDir = os.path.expanduser(os.path.join("~", "-".join(pkg_dir))) msg("Extracting {} to\n{}\n{}", " ".join(pkg_dir), eDir, "-" * 79) if os.path.exists(eDir): msg("Subdirectory already exists") else: os.mkdir(eDir) msg("Subdirectory created") reFile = re.compile(r'[a-z].+\.(py|c|txt)$') for fileName in pkg_resources.resource_listdir(*pkg_dir): if not reFile.match(fileName): continue ePath = os.path.join(eDir, fileName) if os.path.exists(ePath): msg("{} already exists", ePath) else: sPath = os.path.join(sDir, fileName) if os.path.isfile(sPath): shutil.copy(sPath, ePath) msg("{} created", ePath)