Ejemplo n.º 1
0
    def abort(self, failure=None):
        os.chdir(self.pwd)
        if not exists(self.project_name):
            return

        if failure:
            sh.bold_red_on_black("\r\nOOps, it broke :(\n\n{}\n".format(unicode(failure)))

        try:
            sh.bold_yellow_on_black("\r\nDo you want to remove the directory `{}` ?\n".format(self.project_name))
            if raw_input('(type "y" or "n"): ').lower().strip() == 'y':
                shutil.rmtree(self.project_name)

        except KeyboardInterrupt:
            sh.bold_red("Aborted without removing the directory `{}\n".format(self.project_name))
Ejemplo n.º 2
0
    def run(self, args):
        if not args:
            sh.bold_white_on_black("USAGE: ")
            sh.bold_green_on_black("shrine create name_of_the_project\n")
            raise SystemExit(1)

        self.project_name = unicode(args.pop(0)).strip()
        self.project_path = join(self.pwd, self.project_name)
        self.shrine_tmp_dir = '{}_temp'.format(self.project_name)

        if os.path.exists(self.project_name):
            sh.bold_red_on_black("{} already exists\n".format(self.project_name))
            print
            raise SystemExit(1)

        if not re.search(r'^[a-zA-Z][\w_]+$', self.project_name):
            example = re.sub(r'^[\W0-9]+', '', self.project_name)
            example = ''.join(re.findall(r'^[a-zA-Z]\w+', example)) or 'project_name'

            sh.bold_red_on_black("Invalid shrine name: {}\n".format(self.project_name))
            sh.bold_white_on_black("Please use a valid python package name\n")
            sh.bold_white_on_black("Example: ")
            sh.bold_green_on_black(example)
            print
            raise SystemExit(1)

        self.ask_user_preferences()
        sh.bold_yellow_on_black("Creating `{}`...".format(self.project_name))

        templates = [
            SHRINE_FILE('skel/README.md'),
            SHRINE_FILE('skel/Procfile'),
            SHRINE_FILE('skel/requirements.txt'),
            SHRINE_FILE('skel/.gitignore'),
        ]
        templates.extend(glob(SHRINE_FILE('skel/*.py')))

        os.makedirs(self.project_name)

        tmp_dir_path = join(self.project_name, self.shrine_tmp_dir)
        os.makedirs(tmp_dir_path)

        for template in templates:
            name = basename(template)
            self.create_file(name)

        static_dirs = [
            SHRINE_FILE('skel/media'),
            SHRINE_FILE('skel/templates'),
            SHRINE_FILE('skel/controllers'),
        ]

        for path in static_dirs:
            self.clone_dir(basename(path))

        sh.bold_yellow_on_black(logo)
        print

        self.create_git_repository()
        self.prepare_for_heroku()
        sh.bold_green_on_black('now execute:\n\n')
        sh.bold_white_on_black('  cd {}\n'.format(self.project_name))
        sh.bold_white_on_black('  shrine run\n')