-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.py
53 lines (38 loc) · 1.08 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from io import StringIO
import minicli
from usine import cd, connect, env, exists, ls, mkdir, put, run, sudo, screen
@minicli.cli
def create_bar():
with sudo(user='tamer'), cd('/srv/'):
if exists('/tmp/foo'):
mkdir('/tmp/foo/bar')
else:
print('/tmp/foo does not exist')
ls('tamer')
@minicli.cli
def pass_env():
with env(FOO='bar'):
run('echo $FOO')
with sudo(user='tamer'), env(FOO='baz'):
run('echo $FOO')
@minicli.cli
def put_file():
with sudo(user='tamer'):
put('README.md', '/tmp/foobarbaz')
ls('/tmp/foobarbaz')
run('cat /tmp/foobarbaz')
put(StringIO('foobarbazéé'), '/tmp/foobarbaz')
run('cat /tmp/foobarbaz')
@minicli.cli
def with_screen(name='usine', target='8.8.8.8'):
with screen(name):
run(f'ping {target}')
@minicli.cli
def python():
run('python')
@minicli.wrap
def wrapper(hostname, dry_run):
with connect(hostname=hostname, dry_run=dry_run):
yield
if __name__ == '__main__':
minicli.run(hostname='usine', dry_run=False)