def ensure(self, *args, **kwargs): """ ensure that an args-joined path exists (by default as a file). If you specify a keyword argument 'dir=True' then the path is forced to be a directory path. """ if getattr(self, 'rev', None) is not None: raise py.error.EINVAL(self, "revisions are immutable") target = self.join(*args) dir = kwargs.get('dir', 0) for x in target.parts(reverse=True): if x.check(): break else: raise py.error.ENOENT(target, "has not any valid base!") if x == target: if not x.check(dir=dir): raise dir and py.error.ENOTDIR(x) or py.error.EISDIR(x) return x tocreate = target.relto(x) basename = tocreate.split(self.sep, 1)[0] tempdir = py.path.local.mkdtemp() try: tempdir.ensure(tocreate, dir=dir) cmd = 'svn import -m "%s" "%s" "%s"' % ( "ensure %s" % self._escape(tocreate), self._escape(tempdir.join(basename)), x.join(basename)._encodedurl()) process.cmdexec(cmd) self._lsnorevcache.delentry(x.strpath) # !!! finally: tempdir.remove() return target
def remove(self, rec=1, msg='removed by py lib invocation'): """ remove a file or directory (or a directory tree if rec=1) with checkin message msg.""" if self.rev is not None: raise py.error.EINVAL(self, "revisions are immutable") process.cmdexec('svn rm -m "%s" "%s"' %(msg, self._escape(self))) self._lsnorevcache.delentry(self.dirpath().strpath)
def copy(self, target, msg='copied by py lib invocation'): """ copy path to target with checkin message msg.""" if getattr(target, 'rev', None) is not None: raise py.error.EINVAL(target, "revisions are immutable") process.cmdexec('svn copy -m "%s" "%s" "%s"' %(msg, self._escape(self), self._escape(target))) self._lsnorevcache.delentry(target.dirpath().strpath)
def test_simple_error_exact_status(self): try: cmdexec('exit 1') except cmdexec.Error: e = exvalue() assert e.status == 1 assert py.builtin._istext(e.out) assert py.builtin._istext(e.err)
def test_err(self): try: cmdexec('echoqweqwe123 hallo') raise AssertionError, "command succeeded but shouldn't" except cmdexec.Error, e: assert hasattr(e, 'err') assert hasattr(e, 'out') assert e.err or e.out
def test_err(self): try: cmdexec('echoqweqwe123 hallo') raise AssertionError("command succeeded but shouldn't") except cmdexec.Error: e = exvalue() assert hasattr(e, 'err') assert hasattr(e, 'out') assert e.err or e.out
def generate(self, storedir=None, target='ps'): source = self.get_source() if target is None: return source # unprocessed if storedir is None: storedir = udir pdot = storedir.join('%s.dot' % self.graphname) pdot.write(source) ptarget = pdot.new(ext=target) cmdexec('dot -T%s %s>%s' % (target, str(pdot), str(ptarget))) return ptarget
def generate(self, storedir=None, target="ps"): source = self.get_source() if target is None: return source # unprocessed if storedir is None: storedir = udir pdot = storedir.join("%s.dot" % self.graphname) pdot.write(source) ptarget = pdot.new(ext=target) cmdexec("dot -T%s %s>%s" % (target, str(pdot), str(ptarget))) return ptarget
def _cmdexec(self, cmd): try: out = process.cmdexec(cmd) except py.process.cmdexec.Error, e: if (e.err.find('File Exists') != -1 or e.err.find('File already exists') != -1): raise py.error.EEXIST(self) raise
def _cmdexec(self, cmd): try: out = process.cmdexec(cmd) except py.process.cmdexec.Error: e = sys.exc_info()[1] if e.err.find("File Exists") != -1 or e.err.find("File already exists") != -1: raise py.error.EEXIST(self) raise return out
def _cmdexec(self, cmd): try: out = process.cmdexec(cmd) except py.process.cmdexec.Error: e = sys.exc_info()[1] if (e.err.find("File Exists") != -1 or e.err.find("File already exists") != -1): raise py.error.EEXIST(self) raise return out
def _svnwrite(self, cmd, *args): l = ['svn %s' % cmd] args = ['"%s"' % self._escape(item) for item in args] l.extend(args) l.append('"%s"' % self._encodedurl()) # fixing the locale because we can't otherwise parse string = svncommon.fixlocale() + " ".join(l) if DEBUG: print "execing", string try: out = process.cmdexec(string) except py.process.cmdexec.Error, e: if (e.err.find('File Exists') != -1 or e.err.find('File already exists') != -1): raise py.error.EEXIST(self) raise
def test_simple(self): out = cmdexec('echo hallo') assert out.strip() == 'hallo'
def test_simple_error_exact_status(self): try: cmdexec('exit 1') except cmdexec.Error, e: assert e.status == 1
def test_simple_newline(self): import sys out = cmdexec(r"""%s -c "print ('hello')" """ % sys.executable) assert out == 'hello\n' assert py.builtin._istext(out)
def test_simple(self): out = cmdexec('echo hallo') assert out.strip() == 'hallo' assert py.builtin._istext(out)