def test_checkout_master(self): if not select_tune_date_update(cnn): date_updated = create_tune_date_update(cnn) git_dir = os.path.join(config.git_folder, cnn.dsn) branch_name = '%s_%s' % ( db_name, date_updated.strftime('%d.%m.%Y_%H.%M') ) # %Y%m%d_%H%M%S repo = clone_or_open_repo(git_dir) past_branch = repo.create_head(branch_name, 'master') repo.head.reference = past_branch repo.head.reset(index=True, working_tree=True) logger.info("checkout new branch %s" % branch_name) # Сохраним тексты df = select_objects_in_folder_or_date_modified( cnn, git_dir, 1, 'd') dirs.write_object_from_df(df, git_dir) # Закомитим # repo.git.add(update=True) repo.git.add(A=True) index = repo.index from git import Actor author = Actor("An author", "*****@*****.**") committer = Actor("A committer", "*****@*****.**") index.commit("my commit message", author=author, committer=committer)
def test_update_git(self): git_dir = os.path.join(config.git_folder, cnn.dsn) repo = clone_or_open_repo(git_dir) # checkout_branch(repo, ) last_date_update = '27.09.2017 18:30:30' df = select_all_by_date_modified(cnn, last_date_update) df = df.sort_values('MODIFIED', ascending=False) prev_user = None i = 1 msg_template = "autosave" msg = msg_template for ids, row in df.iterrows(): current_user = row['USER_MODIFIED'] logger.debug("prev_user=%s, current_user=%s" % (prev_user, current_user)) if i == 1: i += 1 elif prev_user != current_user and repo.is_dirty(): logger.debug("commit") git_funcs.commit(repo, msg.rstrip(','), prev_user, (prev_user or '') + '@mail', 'sources_sync_job', '@mail') msg = msg_template msg += ' %s.%s,' % (row['CLASS_ID'], row['SHORT_NAME']) write_object_from_row(os.path.join(config.git_folder, cnn.dsn), row) prev_user = current_user git_funcs.commit(repo, msg.rstrip(','), prev_user, (prev_user or '') + '@mail', 'sources_sync_job', '@mail') print(df)
def test_commit_authorized_time(self): # repos_dir = r"C:\Users\BryzzhinIS\Documents\Хранилища\sync_script" # repo_dir = os.path.join(repos_dir, 'dbs', 'lw-abs-abs') # repo = clone_or_open_repo(repo_dir) # repo.git.add(A=True) # author = Actor('sources_sync_job', '@mail') # committer = Actor('sources_sync_job', '@mail') # time_str = "2012-07-24T23:14:29-07:00" # time_str = "2012-07-24T23:14:29" # repo.index.commit('test', author=author, committer=committer, author_date=time_str) last_date_update = '28.09.2017 18:30:30' df = select_all_by_date_modified(cnn, last_date_update) df = df.sort_values('MODIFIED', ascending=False) # localtz = pytz.timezone('Europe/Moscow') # time_str = localtz.localize(df.iloc[0]["MODIFIED"]).strftime('%d.%m.%YT%H:%M:%S%z') time_str = (df.iloc[0]["MODIFIED"] + datetime.timedelta(hours=-3)).strftime('%d.%m.%YT%H:%M:%S') print(time_str) repos_dir = r"C:\Users\BryzzhinIS\Documents\Хранилища\sync_script" # repo_dir = os.path.join(repos_dir, 'dbs', 'lw-abs-abs') repo_dir = os.path.join(repos_dir, 'dbs', 'mideveryday') repo = clone_or_open_repo(repo_dir) repo.git.add(A=True) author = Actor('sources_sync_job', '@mail') committer = Actor('sources_sync_job', '@mail') # time_str = "2012-07-24T23:14:29-07:00" # time_str = "2012-07-24T23:14:29" repo.index.commit('test', author=author, committer=committer, author_date=time_str)
def update(): global last_date_update df = None if not last_date_update: last_date_update = select_max_object_date_modified( cnn)["MODIFIED"][0] - datetime.timedelta(days=7) repo = clone_or_open_repo(os.path.join(config.git_folder, cnn.dsn)) if not select_tune_date_update(cnn): logger.debug("update init_git_db") create_tune_date_update(cnn) df = select_objects_in_folder_or_date_modified( cnn, last_date_update.strftime('%d.%m.%Y %H:%M:%S')) else: logger.debug("select object on date %s" % last_date_update.strftime('%d.%m.%Y %H:%M:%S')) df = select_all_by_date_modified( cnn, last_date_update.strftime('%d.%m.%Y %H:%M:%S')) if len(df) > 0: logger.debug("update by_time") branch_name = git_funcs.tune_branch_name(cnn) if branch_name in repo.branches: repo.heads[branch_name].checkout() else: repo.create_head(branch_name, 'master').checkout() git_funcs.commit_by_dataframe(repo, df, cnn.dsn) last_date_update = select_max_object_date_modified( cnn)["MODIFIED"][0] else: logger.debug("up-to-date")
def test_fetch_master(self): repos_dir = r"C:\Users\BryzzhinIS\Documents\Хранилища\sync_script" repo_dir = os.path.join(repos_dir, 'dbs', 'mideveryday') repo = clone_or_open_repo(repo_dir) # try: repo.heads['master'].checkout() repo.remotes['origin'].fetch(refspec='{}'.format('master')) repo.head.reset(commit=repo.refs['origin/master'], index=True, working_tree=True)
def test_push(self): repos_dir = r"C:\Users\BryzzhinIS\Documents\Хранилища\sync_script" # repo_dir = os.path.join(repos_dir, 'dbs', 'lw-abs-abs') repo_dir = os.path.join(repos_dir, 'dbs', 'mideveryday') repo = clone_or_open_repo(repo_dir) print(repo.remotes) local_branch = 'mideveryday_03.10.2017_15.26' remote_branch = local_branch repo.remotes['origin'].push( refspec='{}:{}'.format(local_branch, remote_branch))
def test_comit_by_date(self): git_dir = os.path.join(config.git_folder, cnn.dsn) repo = clone_or_open_repo(git_dir) if not select_tune_date_update(cnn): create_tune_date_update(cnn) # git_funcs.checkout_branch(repo, git_funcs.tune_branch_name(cnn)) repo.heads[git_funcs.tune_branch_name(cnn)].checkout() last_date_update = '27.09.2017 18:30:30' df = select_all_by_date_modified(cnn, last_date_update) git_funcs.commit_by_dataframe(repo, df, cnn.dsn) print(df)
def test_pull(self): repos_dir = r"C:\Users\BryzzhinIS\Documents\Хранилища\sync_script" repo_dir = os.path.join(repos_dir, 'dbs', 'lw-abs-abs') # repo_dir = os.path.join(repos_dir, 'dbs', 'mideveryday') repo = clone_or_open_repo(repo_dir) # print(repo.remotes) local_branch = 'lw-abs-abs_26.09.2017_13.17' remote_branch = 'origin/%s' % local_branch # print(repo.refs['origin/%s' % local_branch]) # print(repo.branches) try: repo.refs[remote_branch] except IndexError: pass
def test_update_git2(self): git_dir = os.path.join(config.git_folder, cnn.dsn) repo = clone_or_open_repo(git_dir) if not select_tune_date_update(cnn): create_tune_date_update(cnn) # git_funcs.checkout_branch(repo, git_funcs.tune_branch_name(cnn)) repo.heads[git_funcs.tune_branch_name(cnn)].checkout() last_date_update = '27.09.2017 18:30:30' df = select_all_by_date_modified(cnn, last_date_update) # df = df.sort_values('MODIFIED', ascending=True) prev_user = None i = 1 def commit_group(repo, group): dfg = pd.DataFrame(group) msg = "autosave " msg += ", ".join( "%s [%s]" % (class_id, ", ".join( name for name, rows in class_rows.groupby('SHORT_NAME'))) for class_id, class_rows in dfg.groupby('CLASS_ID')) if repo.is_dirty() or repo.untracked_files: repo.git.add(A=True) author = Actor(prev_user or 'Неизвестный автор', (prev_user or 'Неизвестный автор') + '@mail') committer = Actor('sources_sync_job', '@mail') repo.index.commit(msg, author=author, committer=committer) # git_funcs.commit(repo, msg, prev_user, (prev_user or '') + '@mail', 'sources_sync_job', '@mail') return msg group = [] for ids, row in df.iterrows(): current_user = row['USER_MODIFIED'] logger.debug("prev_user=%s, current_user=%s" % (prev_user, current_user)) if i == 1: i += 1 elif prev_user != current_user: logger.debug("commit") commit_group(repo, group) group = [] write_object_from_row(os.path.join(config.git_folder, cnn.dsn), row) prev_user = current_user group.append(row) commit_group(repo, group) print(df)
def test_clone_repo(self): repos_dir = r"C:\Users\BryzzhinIS\Documents\Хранилища\sync_script" repo_dir = os.path.join(repos_dir, 'dbs', db_name) clone_or_open_repo(repo_dir)
def test_discard_changes(self): repos_dir = r"C:\Users\BryzzhinIS\Documents\Хранилища\sync_script" repo_dir = os.path.join(repos_dir, 'dbs', 'midabs') repo = clone_or_open_repo(repo_dir) repo.head.reset(commit='HEAD', index=True, working_tree=True)