Skip to content

Commit e184e76

Browse files
authored
Merge pull request #6 from sanjana091001/new
Enable support to run it in repos
2 parents 79af3ab + e858852 commit e184e76

File tree

1 file changed

+75
-37
lines changed

1 file changed

+75
-37
lines changed

reparo.py

+75-37
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,95 @@
2222

2323
import requests
2424
import json
25-
25+
import os
2626
from string import Template
2727

28-
REPO = "chaoss/grimoirelab-perceval/"
29-
PATH_TO_FILE = "perceval/backend.py"
28+
years = "2015-2020"
29+
owner = "Bitergia"
3030

31-
data = requests.get("https://api.github.com/repos/" + REPO + "commits?path=" + PATH_TO_FILE)
32-
data = json.loads(data.content)
3331

34-
authors_data = {}
32+
def getlistoffiles(dirname):
33+
listoffile = os.listdir(dirname)
34+
allfiles = list()
35+
for entry in listoffile:
36+
fullpath = os.path.join(dirname, entry)
37+
if os.path.isdir(fullpath):
38+
allfiles = allfiles+getlistoffiles(fullpath)
39+
else:
40+
allfiles.append(fullpath)
41+
return(allfiles)
3542

36-
for item in reversed(data):
37-
data = item['commit']['author']
38-
if data['name'] not in authors_data.keys():
39-
authors_data[data['name']] = data['email']
4043

41-
authors = [key + " <" + value + ">" for key, value in authors_data.items()]
44+
REPO = input("repo name: ")
45+
dirname = input("path to repo: ")
4246

43-
# print(authors)
47+
listoffiles = getlistoffiles(dirname)
4448

45-
template_file = open("gpl-v3.tmpl")
49+
FILES = []
4650

47-
src = Template(template_file.read())
51+
for f in listoffiles:
52+
count = 0
53+
try:
54+
for line in open(f):
55+
if "Copyright (C)" and "Authors" in line:
56+
count = count+1
57+
if(count > 0):
58+
FILES.append(f)
59+
except UnicodeDecodeError:
60+
pass
4861

49-
years = "2015-2020"
50-
owner = "Bitergia"
5162

52-
sub_dict = {
53-
'years': years,
54-
'owner': owner,
55-
'authors': '\n# '.join(authors)
56-
}
63+
for items2 in FILES:
64+
65+
PATH_TO_FILE2 = items2.replace(dirname, '')
66+
PATH_TO_FILE = PATH_TO_FILE2.strip('/')
67+
CHAOSS_HTTP = "https://api.github.com/repos/chaoss/"
68+
69+
data = requests.get(CHAOSS_HTTP + REPO + "/commits?path=" + PATH_TO_FILE)
70+
71+
data = json.loads(data.content)
72+
73+
authors_data = {}
74+
75+
try:
76+
for item in reversed(data):
77+
data = item['commit']['author']
78+
if data['name'] not in authors_data.keys():
79+
authors_data[data['name']] = data['email']
80+
except TypeError:
81+
pass
82+
83+
authors = [key + " <" + value + ">" for key, value in authors_data.items()]
84+
authors.append('')
85+
86+
# print(authors)
87+
88+
template_file = open("gpl-v3.tmpl")
89+
90+
src = Template(template_file.read())
5791

58-
result = src.substitute(sub_dict)
92+
sub_dict = {
93+
'years': years,
94+
'owner': owner,
95+
'authors': '\n# '.join(authors)
96+
}
5997

60-
# print(result)
98+
result = src.substitute(sub_dict)
6199

62-
with open('./backend.py', 'r') as f:
63-
contents = f.readlines()
64-
i = 0
65-
for item in contents:
66-
if item.startswith('#'):
67-
i += 1
100+
with open(items2, 'r') as f:
101+
contents = f.readlines()
102+
i = 0
103+
for item in contents:
104+
if item.startswith('#'):
105+
i += 1
68106

69-
with open('./backend.py', 'w') as f:
70-
f.writelines(contents[i:])
107+
with open(items2, 'w') as f:
108+
f.writelines(contents[i:])
71109

72-
with open('./backend.py', 'r') as f:
73-
contents = f.readlines()
74-
contents.insert(0, result+"\n")
110+
with open(items2, 'r') as f:
111+
contents = f.readlines()
112+
contents.insert(0, result+"\n")
75113

76-
with open('./backend.py', 'w') as f:
77-
contents = "".join(contents)
78-
f.write(contents)
114+
with open(items2, 'w') as f:
115+
contents = "".join(contents)
116+
f.write(contents)

0 commit comments

Comments
 (0)