Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 53 lines (39 sloc) 1.4 KB
#!/usr/bin/env python
# Create a manifest file from a staging directory
import sys
import os
import hashlib
import json
import stat
# Based on # (2012-06-25)
def get_permission(path):
"""Returns the permission of a file."""
return oct(stat.S_IMODE(os.stat(path).st_mode))
def gen_manifest(stage_dir):
"""Generate a manifest from a directory"""
manifest = {'files': []}
for root, dirs, files in os.walk(stage_dir):
for file_ in files:
fullpath = os.path.join(root, file_)
contents = open(fullpath, 'rb').read()
sha1 = hashlib.sha1(contents).hexdigest()
filename = os.path.relpath(fullpath, stage_dir)
mode = get_permission(fullpath)
manifest['files'].append({'path': filename, 'sha1': sha1,
'mode': mode})
return manifest
def main(argv=None):
if argv is None:
argv = sys.argv
if len(argv) != 2:
print "Usage: [directory]"
stage_dir = os.path.abspath(argv[1])
#print "Creating manifest for", stage_dir
if not os.path.exists(stage_dir):
print "Error: directory not found"
manifest = gen_manifest(stage_dir)
print json.dumps(manifest)
if __name__ == '__main__':
Something went wrong with that request. Please try again.