Example #1
0
    def clone_dir(self, name):
        sh.bold_white_on_black(u'Creating ')
        sh.bold_cyan_on_black(self.project_file(name))
        context = self.get_context()

        try:
            shutil.copytree(SHRINE_FILE('skel', name), self.project_file(name))

            for filename in glob(self.project_file(name, '*.html')):
                contents = open(filename).read()
                for name in context:
                    variable = '@{}@'.format(name)
                    contents = contents.replace(variable, context[name])

                open(filename, 'w').write(contents)
        except:
            sh.bold_red_on_black(ballot)
            raise
        else:
            sh.bold_green_on_black(checkmark)

        sh.indent()
        for path in glob(self.project_file(join(name, '*'))):
            sh.bold_white(arrow)
            sh.bold_green_on_black(path)
            print
        sh.dedent()
Example #2
0
    def create_file(self, name):
        context = self.get_context()

        with self.new_file(name) as destination:
            with self.skel_file(name) as view:
                sh.bold_white_on_black(u'Creating ')
                sh.bold_green_on_black(self.project_file(name))

                try:
                    body = view.read()
                    inside = body.format(**context)
                    destination.write(inside)
                except:
                    sh.bold_red(ballot)
                    raise
                else:
                    sh.bold_green(checkmark)
Example #3
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')