def pack_war(self): import subprocess # 1. render build.xml file into project dir. war_params = {'appName': self.application_name, 'genPath': self.japp_path} build_xml_content = self.__code_tpl__('ci/build.xml', war_params) build_xml_file = os.path.join(self.app_dir, 'build.xml') storage_file(self.app_dir, build_xml_content, 'build.xml') # 2. call ant run subprocess. ant_path = os.path.join(self.japp_path, 'ci', 'ant', 'bin', 'ant') ant_cmds = '%s clean package' % ant_path compile_process = subprocess.Popen(ant_cmds, shell=True, stdout=subprocess.PIPE) while compile_process.poll() is None: print compile_process.stdout.readline() # 3. clean build file. os.remove(build_xml_file)
def conf(self): storage_path = os.path.join(self.app_dir, 'src', 'main', 'resources') params = {'appName': self.application_name} file_content = self.__code_tpl__('conf/application.conf', params) storage_file(storage_path, file_content, 'application.conf') file_content = self.__code_tpl__('conf/ehcache.xml', params) storage_file(storage_path, file_content, 'ehcache.xml') file_content = self.__code_tpl__('conf/logback.xml', params) storage_file(storage_path, file_content, 'logback.xml') file_content = self.__code_tpl__('conf/shiro.ini', params) storage_file(storage_path, file_content, 'shiro.ini')
def idea(self): idea_ipr = self.application_name + '.ipr' idea_iws = self.application_name + '.iws' idea_iml = self.application_name + '.iml' params = {'appName': self.application_name, 'appSN': uuid.uuid4(), 'gen_path': self.japp_path} file_content = self.__code_tpl__('idea/app.module', params) storage_file(self.app_dir, file_content, idea_iml) file_content = self.__code_tpl__('idea/app.project', params) storage_file(self.app_dir, file_content, idea_ipr) file_content = self.__code_tpl__('idea/app.workspace', params) storage_file(self.app_dir, file_content, idea_iws) print 'Convert the Intellij idea project Success.'
def code(self): # .gitignore copy ignore_git = open(os.path.join(self.japp_path, 'deps', 'git', 'ignore'), 'r') storage_file(self.app_dir, ignore_git.read(), '.gitignore') ignore_git.close() storage_path = os.path.join( self.app_dir, "src", "main", "java", "app", "controllers") params = {'appName': self.application_name} file_content = self.__code_tpl__('code/IndexController.java', params) storage_file(storage_path, file_content, 'IndexController.java') storage_path = os.path.join( self.app_dir, "src", "main", "webapp", "WEB-INF", "views") file_content = self.__code_tpl__('code/index.ftl', params) storage_file(storage_path, file_content, 'index.ftl')
def syncdb(self): """ sync database with model. only mysql. """ conf = read_conf(self.app_dir) if 'db.url' not in conf: print 'This Application is not enable database or not mysql database.' sys.exit() db_url = conf['db.url'] host_index = db_url.find(':', 12) host = db_url[13:host_index] port_idx = db_url.find('/', host_index) port = db_url[host_index + 1: port_idx] db = db_url[port_idx + 1: db_url.find('?', port_idx)] db_user = conf['db.username'] db_pwd = conf['db.password'] import MySQLdb db = MySQLdb.connect(host, db_user, db_pwd, db) cursor = db.cursor() sql = 'show tables' models = [] try: cursor.execute(sql) results = cursor.fetchall() for row in results: # table name like ol_member_type real_table_name = row[0] row__find = real_table_name.find('_') table_name = 'tmp_' + real_table_name[row__find + 1: len(real_table_name)] # find table column name cursor.execute( "select column_name from information_schema.columns where table_name='%s'" % real_table_name) columns = cursor.fetchall() column_list = [] for column in columns: column_list.append(column[0]) models.append({'model': underline_to_camel(table_name).replace('tmp', ''), 'table': real_table_name, 'columns': ','.join(column_list)}) cursor.close() except: print "error unkown tables;" finally: db.close() model_dir = os.path.join(self.app_dir, 'src', 'main', 'java', 'app', 'models') sql_conf_dir = os.path.join(self.app_dir, 'src', 'main', 'resources', 'sqlcnf') for _m in models: model_ = _m['model'] model__lower = model_.lower() params = {'tableName': _m['table'], 'model': model_, 'lower_model': model__lower} file_content = self.__code_tpl__('code/model.java', params) if not os.path.exists(os.path.join(model_dir, model_ + '.java')): storage_file(model_dir, file_content, model_ + ".java") sql_params = {'model': model__lower, 'columns': _m['columns'], 'tableName': _m['table']} sql_conf_content = self.__code_tpl__('code/sql.xml', sql_params) if not os.path.exists(os.path.join(sql_conf_dir, model__lower + '-sql.xml')): storage_file(sql_conf_dir, sql_conf_content, model__lower + '-sql.xml') print 'sync db to model Success!'
def pom(self): params = {'group': self.application_name} file_content = self.__code_tpl__('ci/maven.project', params) storage_file(self.app_dir, file_content, 'pom.xml') print 'generate maven pom file Success!'