Last active
August 22, 2017 15:39
-
-
Save Bost/4fb9be9c02549d1d5032d2481ea6ab88 to your computer and use it in GitHub Desktop.
Revisions
-
Bost revised this gist
Aug 22, 2017 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -31,12 +31,15 @@ def do_exec(cmd): safe_print(cmd_str) p = Popen(cmd_str, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) # output, err = p.communicate(b"input data that is passed to subprocess' stdin") out, err = p.communicate(b"") rc = p.returncode if rc != 0: print(err.decode("utf-8")) res = [cmd_str, rc, out] # out_utf = out.decode("utf-8") # tsplit = out_utf.split("\n") # ret = tsplit[0:(len(tsplit) - 1)] # last array item is an empty string # return ret return res files = [ -
Bost revised this gist
Aug 16, 2017 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,16 @@ import datetime import time from functools import reduce from pathlib import Path def map_f_reduce_add(f, xs): return reduce(operator.add, map(f, xs), []) # only map and reduce! def tstp(): """ See also: import logging logging.info("Foo") """ return datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d_%H%M%S') # return code index in the list returned by do_exec @@ -44,8 +49,8 @@ def do_exec(cmd): ] def links(f): target_dir = str(Path.home()) + "/dev/cheatsheet/cmds/" linkname_dir = target_dir+"crep/" cmd = ["ln", "--symbolic", target_dir+f, linkname_dir+f] do_exec(cmd) -
Bost revised this gist
Aug 8, 2017 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -33,3 +33,21 @@ def do_exec(cmd): res = [cmd_str, rc, output] print(output.decode("utf-8")) return res files = [ "git.sh", "linux.sh", "win.bat", "clojure.clj", "emacs.el", "utf8.txt", ] def links(f): target_dir = "/home/bost/dev/cheatsheet/cmds/" linkname_dir = "/home/bost/dev/cheatsheet/cmds/crep/" cmd = ["ln", "--symbolic", target_dir+f, linkname_dir+f] do_exec(cmd) # w/o the map(...) into list(...) I get only # <map object at 0x7fa54f2b6048> list(map(links, files)) -
Bost created this gist
Jul 31, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #!/usr/bin/env python from subprocess import Popen, PIPE import operator import os import re import datetime import time from functools import reduce def map_f_reduce_add(f, xs): return reduce(operator.add, map(f, xs), []) # only map and reduce! def tstp(): return datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d_%H%M%S') # return code index in the list returned by do_exec idx_rc = 1 idx_res = 2 def safe_print(cmd_str): print(re.sub(r"--password\s+\S+", "--password ******", cmd_str)) def do_exec(cmd): cmd_str = " ".join(list(map(str, cmd))) safe_print(cmd_str) p = Popen(cmd_str, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) # output, err = p.communicate(b"input data that is passed to subprocess' stdin") output, err = p.communicate(b"") rc = p.returncode if rc != 0: print(err.decode("utf-8")) res = [cmd_str, rc, output] print(output.decode("utf-8")) return res