forked from nficano/python-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
37 lines (29 loc) · 974 Bytes
/
helpers.py
File metadata and controls
37 lines (29 loc) · 974 Bytes
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
# -*- coding: utf-8 -*-
import os
import stat
import zipfile
import datetime as dt
def mkdir(path):
if not os.path.exists(path):
os.makedirs(path)
def read(path, loader=None):
with open(path) as fh:
if not loader:
return fh.read()
return loader(fh.read())
def archive(src, dest, filename):
output = os.path.join(dest, filename)
zfh = zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED)
for root, _, files in os.walk(src):
for file in files:
filePath = os.path.join(root, file)
zfh.write(filePath)
# set global read+write+execute permissions (needed to execute binaries)
# TODO: set permission from file
info = zfh.getinfo(filePath.strip("./"))
info.external_attr = 0777 << 16L
zfh.close()
return os.path.join(dest, filename)
def timestamp(fmt='%Y-%m-%d-%H%M%S'):
now = dt.datetime.utcnow()
return now.strftime(fmt)