def write_file(file_path, content): if os.path.isdir(file_path): error("File {filePath} already exists.").format(filePath=os.path.abspath(file_path)) with open(file_path, "a") as outfile: outfile.write(content) success(os.path.abspath(file_path))
def make_view(view_name): if not os.path.isdir('views'): error( "eng generate must be called from the root directory of an engel application." ) write_file(os.path.join(os.path.abspath('views'), view_name + '.py'), render_view(view_name))
def write_file(file_path, content): if os.path.isdir(file_path): error("File {filePath} already exists.").format( filePath=os.path.abspath(file_path)) with open(file_path, "a") as outfile: outfile.write(content) success(os.path.abspath(file_path))
def make_service(svc): if not os.path.isdir('services'): error( "eng generate must be called from the root directory of an engel application." ) write_file(os.path.join(os.path.abspath('services'), svc + '.py'), render_service(svc))
def cli(options): if not options: error(invalid) return action = options[0] for k in valid_actions: if action == k or action == k[0]: valid_actions[k](options[1:]) return error(invalid)
def read_template(template): template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates") filename = template + ".template" template_file = os.path.join(template_dir, filename) if not os.path.isfile(template_file): error("Unknown template file ({tmpl}).".format(tmpl=filename)) data = None with open(template_file, "rU") as infile: data = infile.read() return Template(data)
def generate(options): if len(options) != 2: error("Invalid Syntax.") target = options[0] name = options[1] for key in valid_options: if key == target or target == key[0]: valid_options[key](name) return error("Invalid Operation.")
def new(options): if len(options) != 1: error("Invalid Syntax.") app_name = options[0] info("Generating {appName}...".format(appName=app_name)) create_folder(app_name) app_abspath = os.path.abspath(app_name) write_file(os.path.join(app_abspath, 'app.py'), render_app(app_name)) create_folder(os.path.join(app_abspath, 'views')) write_file(os.path.join(app_abspath, 'views', '__init__.py'), '') write_file(os.path.join(app_abspath, 'views', 'home.py'), render_view('home')) create_folder(os.path.join(app_abspath, 'services')) write_file(os.path.join(app_abspath, 'services', '__init__.py'), '') create_folder(os.path.join(app_abspath, 'public'))
def create_folder(folder_path): if os.path.isdir(folder_path): error("Directory {dirName} already exists.".format(dirName=os.path.abspath(folder_path))) os.mkdir(folder_path) success(os.path.abspath(folder_path) + "/")
def make_view(view_name): if not os.path.isdir('views'): error("eng generate must be called from the root directory of an engel application.") write_file(os.path.join(os.path.abspath('views'), view_name + '.py'), render_view(view_name))
def make_service(svc): if not os.path.isdir('services'): error("eng generate must be called from the root directory of an engel application.") write_file(os.path.join(os.path.abspath('services'), svc + '.py'), render_service(svc))
def create_folder(folder_path): if os.path.isdir(folder_path): error("Directory {dirName} already exists.".format( dirName=os.path.abspath(folder_path))) os.mkdir(folder_path) success(os.path.abspath(folder_path) + "/")