Skip to content

Commit eaafb5b

Browse files
committed
Add update mechanism for version aggregation
1 parent 227bd0f commit eaafb5b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

github2pandas/version.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import shutil
99
from pathlib import Path
1010
import stat
11+
import subprocess
1112
import numpy
1213
from .utility import Utility
1314

@@ -99,7 +100,7 @@ def handleError(func, path, exc_info):
99100
func(path)
100101

101102
@staticmethod
102-
def clone_repository(repo, data_root_dir, github_token=None):
103+
def clone_repository(repo, data_root_dir, github_token=None, new_clone=False):
103104
"""
104105
Clone_repository(repo, data_root_dir, github_token=None)
105106
@@ -113,6 +114,8 @@ def clone_repository(repo, data_root_dir, github_token=None):
113114
Repo dir of the project.
114115
github_token : str
115116
Token string.
117+
new_clone : bool
118+
Initiating a completely new clone of the repository
116119
117120
Notes
118121
-----
@@ -127,6 +130,13 @@ def clone_repository(repo, data_root_dir, github_token=None):
127130
version_folder.mkdir(parents=True, exist_ok=True)
128131

129132
repo_dir = version_folder.joinpath(Version.VERSION_REPOSITORY_DIR)
133+
if (repo_dir.exists ()) & (not new_clone):
134+
old_path = Path.cwd()
135+
os.chdir(repo_dir)
136+
subprocess.check_output(["git", "pull"])
137+
os.chdir(old_path)
138+
return
139+
130140
if repo_dir.exists ():
131141
shutil.rmtree(repo_dir.resolve(), onerror=Version.handleError)
132142

@@ -197,7 +207,7 @@ def mine_git_repo(git_repo_dir, sqlite_db_file, commits=[],
197207
max_modifications=1000)
198208

199209
@staticmethod
200-
def generate_version_pandas_tables(repo, data_root_dir):
210+
def generate_version_pandas_tables(repo, data_root_dir, check_for_updates=True):
201211
"""
202212
generate_version_pandas_tables(repo, data_root_dir)
203213
@@ -212,11 +222,16 @@ def generate_version_pandas_tables(repo, data_root_dir):
212222
213223
"""
214224

225+
if check_for_updates:
226+
commits = repo.get_commits()
227+
old_commits = Version.get_version(data_root_dir, filename=Version.VERSION_COMMITS)
228+
if not Utility.check_for_updates_paginated(commits, old_commits):
229+
return
230+
215231
Version.generate_data_base(data_root_dir)
216232

217233
version_folder = Path(data_root_dir, Version.VERSION_DIR)
218234
sqlite_db_file = version_folder.joinpath(Version.VERSION_DB)
219-
print("1")
220235
db = sqlite3.connect(sqlite_db_file)
221236
pd_commits = pd.read_sql_query("SELECT * FROM commits", db)
222237
pd_edits = pd.read_sql_query("SELECT * FROM edits", db)

0 commit comments

Comments
 (0)