@@ -24,14 +24,14 @@ def get_commits(user, repository, force_refresh=False):
24
24
return commits
25
25
26
26
def create_repo_node (repo_name , image_url , count ):
27
- return {"name" : repo_name , "image" : image_url , "group" : count , "type" : "repo" }
27
+ return {"name" : repo_name , "image" : image_url , "group" : count , "type" : "repo" }
28
28
29
29
def create_contributor_node (contributor , group = 1 ):
30
30
return {"name" : contributor ["login" ], "image" : contributor ["avatar_url" ], "group" : group , "type" : "contributor" }
31
31
32
32
def create_center_node (image = CENTER_IMG ):
33
- return {"name" : "JUPYTER" , "image" : image , "group" : 0 , "type" : "center" }
34
-
33
+ return {"name" : "JUPYTER" , "image" : image , "group" : 0 , "type" : "center" }
34
+
35
35
def create_graph_repos (repos = REPOS , use_custom_images = USE_CUSTOM_IMAGES , repo_img_dir = REPO_IMG_DIR , img_type = IMG_TYPE ):
36
36
graph = {"nodes" : [], "links" : []}
37
37
center_id = 0
@@ -41,7 +41,7 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
41
41
commits = get_commits (user , repository )
42
42
url = CENTER_IMG
43
43
if use_custom_images :
44
- url = repo_img_dir + user + "_" + repository + "." + img_type
44
+ url = repo_img_dir + user + "_" + repository + "." + img_type
45
45
repo_node = create_repo_node (repository , url , len (repo_ids ))
46
46
graph ["nodes" ].append (repo_node )
47
47
repo_id = len (graph ["nodes" ]) - 1
@@ -58,36 +58,36 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
58
58
node = create_contributor_node (author , group = len (repo_ids )- 1 )
59
59
graph ["nodes" ].append (node )
60
60
contrib_id = len (graph ["nodes" ]) - 1
61
- graph ["links" ].append ({"source" : repo_id , "target" : contrib_id , "value" : 2 })
61
+ graph ["links" ].append ({"source" : repo_id , "target" : contrib_id , "value" : 2 })
62
62
graph ["links" ].append ({"source" : repo_ids [0 ], "target" : repo_ids [- 1 ], "value" : 1 })
63
63
return graph
64
64
65
65
def should_refresh (timestamp_file = TIMESTAMP_FILE , refresh_interval = REFRESH_INTERVAL ):
66
- now = time .time ()
67
- then = 0
68
- if os .path .isfile (timestamp_file ):
69
- with open (timestamp_file , 'r' ) as f :
70
- then = float (f .readline ().strip ())
71
- return now - then > refresh_interval
66
+ now = time .time ()
67
+ then = 0
68
+ if os .path .isfile (timestamp_file ):
69
+ with open (timestamp_file , 'r' ) as f :
70
+ then = float (f .readline ().strip ())
71
+ return now - then > refresh_interval
72
72
73
73
def update_timestamp (timestamp_file = TIMESTAMP_FILE ):
74
- now = time .time ()
75
- with open (timestamp_file , 'w' ) as f :
76
- f .write (str (now ))
74
+ now = time .time ()
75
+ with open (timestamp_file , 'w' ) as f :
76
+ f .write (str (now ))
77
77
78
78
def main (command = []):
79
- force_refresh = False
80
- if len (command ) > 0 and command [0 ] == "force-refresh" :
81
- force_refresh = True
82
- if force_refresh or should_refresh ():
83
- graph = create_graph_repos ()
84
- if graph is not None and len (graph ["nodes" ]) > 0 :
85
- with open (DATA_FILE , 'w' ) as f :
86
- json .dump (graph , f )
87
- else :
88
- raise ValueError ("Empty graph generated" )
89
- update_timestamp ()
90
-
79
+ force_refresh = False
80
+ if len (command ) > 0 and command [0 ] == "force-refresh" :
81
+ force_refresh = True
82
+ if force_refresh or should_refresh ():
83
+ graph = create_graph_repos ()
84
+ if graph is not None and len (graph ["nodes" ]) > 0 :
85
+ with open (DATA_FILE , 'w' ) as f :
86
+ json .dump (graph , f )
87
+ else :
88
+ raise ValueError ("Empty graph generated" )
89
+ update_timestamp ()
90
+
91
91
92
92
if __name__ == "__main__" :
93
- main (command = sys .argv [1 :])
93
+ main (command = sys .argv [1 :])
0 commit comments