Created
February 4, 2014 21:21
-
-
Save gelendir/8812607 to your computer and use it in GitHub Desktop.
Python sh examples
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 characters
from sh import ifconfig, git, cd, touch, wc, find, ps, tail, ls, mkdir | |
def iface_info(iface='wlan0'): | |
print(ifconfig(iface)) | |
def create_git_repo(path): | |
mkdir(path, p=True) | |
cd(path) | |
git.init() | |
touch('README') | |
git.add('README') | |
git.commit(m='Initial commit') | |
def count_files(path): | |
count = wc(find(path, ('-type', 'f')), '-l') | |
print('{0} files'.format(count.strip())) | |
def process_list_to_file(filename): | |
ps('aux', _out=filename) | |
def prepend_last_20_lines(filename): | |
for line in tail('/var/log/Xorg.0.log', n=20, _iter=True): | |
line = line.strip() | |
print('{0} {1}'.format('I HAZ A LINEZ ITZ', line)) | |
def prettify_ls(path): | |
pretty_ls = ls.bake('-la') | |
print(pretty_ls(path)) | |
if __name__ == '__main__': | |
iface_info('eth0') | |
create_git_repo('/home/gregory/testrepo') | |
count_files('/home/gregory/p') | |
process_list_to_file('/home/gregory/process_list.txt') | |
prepend_last_20_lines('/var/log/Xorg.0.log') | |
prettify_ls('/home/gregory') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment