Skip to content

Commit

Permalink
fix comma style; support zipfiles as well as tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGermuska committed Mar 8, 2013
1 parent 2b86f4e commit b6fab5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions cactus/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
'''
def _init_parser():
parser = argparse.ArgumentParser(description=description)
parser.add_argument('command',metavar="COMMAND", help="The command to execute (one of [create|build|serve|deploy] )")
parser.add_argument('option1',metavar="OPTION1", nargs='?', help="option 1")
parser.add_argument('option2',metavar="OPTION2", nargs='?', help="option 2")
parser.add_argument('command', metavar="COMMAND", help="The command to execute (one of [create|build|serve|deploy] )")
parser.add_argument('option1', metavar="OPTION1", nargs='?', help="option 1")
parser.add_argument('option2', metavar="OPTION2", nargs='?', help="option 2")
parser.add_argument('--skeleton', required=False, help="If provided, the path to a .tar.gz file or a directory which will be used in place of the default 'skeleton' for a cactus project.")
return parser

Expand Down Expand Up @@ -83,7 +83,7 @@ def main():
# Run the command
if command == 'create':
if not option1: exit('Missing path')
create(option1,args)
create(option1, args)

elif command == 'build':
build(os.getcwd())
Expand Down
26 changes: 16 additions & 10 deletions cactus/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import socket
import tempfile
import tarfile
import zipfile

import boto

Expand Down Expand Up @@ -64,35 +65,40 @@ def verify(self):
logging.info('This does not look like a (complete) cactus project (missing "%s" subfolder)', p)
sys.exit()

def bootstrap(self,skeleton=None):
def bootstrap(self, skeleton=None):
"""
Bootstrap a new project at a given path.
"""

skeleton_tarball = None
skeletonArchive = None
if skeleton is None:
from .skeleton import data
logging.info("Building from data")
skeletonFile = tempfile.NamedTemporaryFile(delete=False, suffix='.tar.gz')
skeletonFile.write(base64.b64decode(data))
skeletonFile.close()
skeleton_tarball = skeletonFile.name
skeletonArchive = tarfile.open(name=skeleton_tarball, mode='r')
elif os.path.isfile(skeleton):
if skeleton.endswith('.tar.gz') or skeleton.endswith('.tgz'):
skeleton_tarball = skeleton
if tarfile.is_tarfile(skeleton):
skeletonArchive = tarfile.open(name=skeleton, mode='r')
elif zipfile.is_zipfile(skeleton):
skeletonArchive = zipfile.ZipFile(skeleton)
else:
logging.error("At this time, skeleton argument must be a tarball or a directory (ending with .tar.gz or .tgz extension).")
logging.error("Unknown file archive type. At this time, skeleton argument must be a directory, a zipfile, or a tarball.")
sys.exit()

if skeleton_tarball:
if skeletonArchive:
print skeletonArchive
os.mkdir(self.path)
skeletonArchive = tarfile.open(name=skeleton_tarball, mode='r')
skeletonArchive.extractall(path=self.path)
skeletonArchive.close()
logging.info('New project generated at %s', self.path)
elif os.path.isdir(skeleton):
shutil.copytree(skeleton,self.path)

logging.info('New project generated at %s', self.path)
shutil.copytree(skeleton, self.path)
logging.info('New project generated at %s', self.path)
else:
logging.error("Cannot process skeleton '%s'. At this time, skeleton argument must be a directory, a zipfile, or a tarball." % skeleton)

def context(self):
"""
Expand Down

0 comments on commit b6fab5d

Please sign in to comment.