def spawn(self): for dest, source in self.settings().items(): if not os.path.isabs(dest): self.warn( "destination path `{}` needs to be absolute".format(dest)) continue if not os.path.isabs(source): source = os.path.join(os.getcwd(), source) if not os.path.exists(source): self.warn("source path `{}` does not exist".format(source)) continue self.say("{} => {}".format(source, dest)) if os.path.isdir(source): tmp = util.make_temp_name(source + dest) with tarfile.open(tmp, "a") as tar: tar.add(source, arcname=os.path.basename(dest)) self.guest().tar_in(tmp, os.path.split(dest)[0]) else: with open(source, "r") as src: self.guest().write(dest, src.read())
def spawn(self): for dest, source in self.settings().items(): if not os.path.isabs(dest): self.warn("destination path `{}` needs to be absolute" .format(dest)) continue if not os.path.isabs(source): source = os.path.join(os.getcwd(), source) if not os.path.exists(source): self.warn("source path `{}` does not exist".format(source)) continue self.say("{} => {}".format(source, dest)) if os.path.isdir(source): tmp = util.make_temp_name(source + dest) with tarfile.open(tmp, "a") as tar: tar.add(source, arcname=os.path.basename(dest)) self.guest().tar_in(tmp, os.path.split(dest)[0]) else: with open(source, "r") as src: self.guest().write(dest, src.read())
def test_make_temp_name(monkeypatch): monkeypatch.setattr("time.time", lambda: 12345678) assert(util.make_temp_name("foo") == "/tmp/xii-42313019c69cd1d99159b3518037f557")