-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-pack_web_static.py
64 lines (54 loc) · 1.62 KB
/
1-pack_web_static.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
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python3
"""
This module makes use of fabric version 1.14.2
and automates the creation of archive files
on a remote host
"""
# Import Fabric's API module
from datetime import datetime
import os
from fabric.api import task, run, env
from fabric.operations import local
# env.hosts = [
# 'server.domain.tld',
# 'localhost',
# '8c6286ded25f.7c5818d5.alx-cod.online'
# 'ip.add.rr.ess
# 'server2.domain.tld',
# ]
# Set the username
# env.user = "root"
# Set the password [NOT RECOMMENDED]
# env.password = "533e04c5e8f089201105"
# env.hosts = ['localhost']
@task
def do_pack():
"""
compresses web folder files and
versions them based on timestamp.
"""
retval = None
try:
# Create the appropriate directory tree using native python.
result = local("mkdir -p ./versions")
# print("After Creating Dir result: ",type(str(result)))
fileName = "{}".format(datetime.now().strftime('%Y%m%d%H%M%S'))
result = local(
"tar -czvf versions/web_static_{}.tgz\
./web_static".format(fileName))
# print("Result of Tar: ",result)
# Unix -bash implementation
# fileSize = local(
# 'stat -c "%s" versions/web_static_{}.tgz'.format(fileName))
fileSize = os.stat(
os.path.join(
'versions',
'web_static_{}.tgz'.format(fileName))).st_size
retval = "web_static packed: \
versions/web_static_{}.tgz -> {}Bytes".format(fileName, fileSize)
return retval
except BaseException:
return retval
if __name__ == '__main__':
result = do_pack()
print(result)