-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_get_alias_dict_for_repo.py
58 lines (44 loc) · 1.42 KB
/
04_get_alias_dict_for_repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Merge aliases and get dictionary
from multiprocessing import Pool
from alias_merge import resolve_aliases
import os
from os import path, mkdir
from os.path import isfile
import pandas as pd
import pickle
num_proc = 20
list_path = "../data/census/proj_lists/"
repo_path = "../data/census/commits_complete/"
output_path = "../data/census/alias_dicts/"
langs = ["NPM", "Packagist", "Go", "Pypi", "Rubygems", "NuGet", "Maven",
"Bower", "CocoaPods", "Cargo", "Clojars", "Atom", "CPAN", "Meteor", "Hackage",
"Hex", "Pub", "CRAN", "Puppet", "PlatformIO"]
if not path.isdir(output_path):
mkdir(output_path)
def call_resolve_alias(f):
pid = f[0]
lang = f[1]
if isfile(output_path+lang+"/"+pid):
return
try:
dat = pd.read_csv(repo_path+lang+"/"+pid+".csv", error_bad_lines=False, warn_bad_lines=False)
unmask = resolve_aliases(dat)
num_diff = sum([k != unmask[k] for k in unmask])
except:
return
if num_diff > 0:
pickle.dump(unmask, open(output_path+lang+"/"+pid, "wb"))
return
def process_projs(lang):
if not path.isdir(output_path+lang+"/"):
mkdir(output_path+lang+"/")
proj_list = open(list_path+lang+".list")
proj_repos = [[proj_repo.strip(),lang] for proj_repo in proj_list.readlines()]
proj_list.close()
print("Processing projects:", lang)
p = Pool(num_proc)
p.map(call_resolve_alias, proj_repos)
p.close()
p.join()
for lang in langs:
process_projs(lang)