Last active
December 15, 2015 11:09
-
-
Save agumonkey/5251164 to your computer and use it in GitHub Desktop.
tired of my bash/zsh misunderstandings, wrote a magnificent `cp -Rv` in python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
def cmd(command): | |
p = subprocess.Popen(command, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT) | |
return iter(p.stdout.readline, b'') | |
def pre(path): | |
if not os.path.isdir(path): | |
os.mkdir(path) | |
else: | |
print("[%s] already exists, continuing." % path) | |
def clean(bstr): | |
return bstr.decode().rstrip() | |
def esc(path): | |
return path.replace('/','_') | |
def srcs(path): | |
return [clean(r) for r in cmd(["find",path,"-type","d","-iname","src"])] | |
def arrows(srcs): | |
""" (src,tgt) """ | |
return [{"src":s,"tgt":root+os.path.sep+esc(s)} for s in srcs] | |
def cmds(arrows): | |
return [list(cmd(["cp","-R","-v",a['src'],a['tgt']])) for a in arrows] | |
# root/**/src > {src,tgt(?)} > cmd`cp -Rv ?src ?tgt` | |
# :done :done :todo | |
if __name__ == "__main__": | |
base="/home/dummy/dev/coursera.scala/" | |
root="/home/dummy/dev/coursera.scala/repos" | |
# pre(root) | |
# cmds(arrows(srcs(base))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment