diff --git a/update/utils/git_util.py b/update/utils/git_util.py index cd8a406..0a014ab 100644 --- a/update/utils/git_util.py +++ b/update/utils/git_util.py @@ -113,6 +113,24 @@ class GitUtil: # print('create_cine_sql', output) return True + # 查看对应的服务器上是否有对应的库 + def template_db_exist(self): + if self.target_ip.startswith('10.'): + db = self.db_config['10'] + else: + db = self.db_config['172'] + db_conn = pymysql.connect(host=db['host'], user=db['user'], passwd=db['password']) + db_cur = db_conn.cursor() + print('template_db_exist', self.db_name) + db_cur.execute('select 1 from information_schema.schemata where schema_name=%s', (self.db_name,)) + result = db_cur.fetchone() + print('template_db_exist', result) + db_cur.close() + db_conn.close() + if result: + return False + return True + # 将生成的cine.sql写入数据库 def write_cine_sql_by_mysql(self): print('开始将cine.sql写入数据库') @@ -167,7 +185,7 @@ class GitUtil: # 写入cine.sql def handle_create_cine(self): # 如果生成了新的文件则写库,如果sql没有变化则跳过 - if self.create_cine_sql(): + if self.create_cine_sql() and self.template_db_exist(): self.write_cine_sql_by_mysql() return '成功' @@ -208,6 +226,7 @@ class GitDbUtil: # 从git中获取版本列表后和数据库对比,添加新的版本到数据库 def set_release_to_db(self): + print('local_repo = Repo(self.local_code_path)', self.local_code_path) local_repo = Repo(self.local_code_path) local_repo.git.execute(command='git remote update origin --prune', shell=True) # 更新远程列表 local_repo.git.execute(command='git fetch --all', shell=True)