Skip to content

Commit 2e317e0

Browse files
authored
Merge pull request #24 from biojs/develop
Develop
2 parents c2f53ff + 86e8006 commit 2e317e0

11 files changed

+345
-10
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ install:
77
- pip install -r requirements.txt
88

99
script:
10+
- python manage.py makemigrations
1011
- python manage.py migrate
11-
- python manage.py test
12+
# - python manage.py test

main/admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
admin.site.register(Component)
55
admin.site.register(Tag)
66
admin.site.register(Contributor)
7-
admin.site.register(Contribution)
7+
admin.site.register(Contribution)
8+
admin.site.register(CSSDependency)
9+
admin.site.register(JSDependency)
10+
admin.site.register(Snippet)
11+
admin.site.register(SniperData)

main/management/commands/updatecomponents.py

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,109 @@
88
GITHUB_CLIENT_SECRET = ''
99
from datetime import datetime
1010
import pytz
11+
import ast
12+
13+
# Get sniper data
14+
'''
15+
https://rawgit.com/cytoscape/cytoscape.js/master/package.json
16+
"sniper" key, has "js" and "css". Search for "first"
17+
'''
18+
19+
def get_commit_hash(commits_url):
20+
commits_url = commits_url.split('{')[0] + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
21+
print (commits_url)
22+
response = urllib.urlopen(commits_url)
23+
data = json.loads(response.read())[0]
24+
return data['sha']
25+
26+
### store the dependency urls and snippet urls
27+
def update_visualizations(component, commit_hash):
28+
github_url_list = component.github_url.split('?')[0].split('/')
29+
owner = github_url_list[4]
30+
repo_name = github_url_list[5]
31+
try:
32+
sniper_data = json.load(urllib.urlopen("https://cdn.rawgit.com/" + str(owner) +
33+
'/' + str(repo_name) + "/" + commit_hash + "/package.json"))["sniper"]
34+
except:
35+
return
36+
try:
37+
buildJS = sniper_data["buildJS"]
38+
except:
39+
buildJS = []
40+
try:
41+
js = sniper_data["js"]
42+
except:
43+
js = []
44+
js_dependencies = buildJS + js
45+
try:
46+
buildCSS = sniper_data["buildCSS"]
47+
except:
48+
buildCSS = []
49+
try:
50+
css = sniper_data["css"]
51+
except:
52+
css = []
53+
css_dependencies = buildCSS + css
54+
for dependency in js_dependencies:
55+
if dependency.startswith('https://'):
56+
dependency, created = JSDependency.objects.get_or_create(component=component, js_url=dependency)
57+
elif dependency.startswith('/'):
58+
dependency = "https://cdn.rawgit.com/" + str(owner) + '/' + str(repo_name) + "/" + commit_hash + dependency
59+
dependency, created = JSDependency.objects.get_or_create(component=component, js_url=dependency)
60+
else:
61+
dependency = "https://cdn.rawgit.com/" + str(owner) + '/' + str(repo_name) + "/" + commit_hash + "/" + dependency
62+
dependency, created = JSDependency.objects.get_or_create(component=component, js_url=dependency)
63+
for dependency in css_dependencies:
64+
if dependency.startswith('https://'):
65+
dependency, created = CSSDependency.objects.get_or_create(component=component, css_url=dependency)
66+
elif dependency.startswith('/'):
67+
dependency = "https://cdn.rawgit.com/" + str(owner) + '/' + str(repo_name) + "/" + commit_hash + dependency
68+
dependency, created = CSSDependency.objects.get_or_create(component=component, css_url=dependency)
69+
else:
70+
dependency = "https://cdn.rawgit.com/" + str(owner) + '/' + str(repo_name) + "/" + commit_hash + "/" + dependency
71+
dependency, created = CSSDependency.objects.get_or_create(component=component, css_url=dependency)
72+
try:
73+
sniperData = SniperData.objects.get(component=component)
74+
except:
75+
sniperData = SniperData.objects.create(component=component)
76+
try:
77+
no_browserify = sniper_data['noBrowserify']
78+
sniperData.no_browserify = no_browserify
79+
except:
80+
pass
81+
try:
82+
if no_browserify:
83+
sniperData.wzrd_url = '#'
84+
else:
85+
sniperData.wzrd_url = "https://wzrd.in/bundle/" + component.name
86+
except:
87+
sniperData.wzrd_url = "https://wzrd.in/bundle/" + component.name
88+
try:
89+
snippets_dir_name = sniper_data['snippets'][0]
90+
sniperData.snippets_dir_name = snippets_dir_name
91+
except:
92+
pass
93+
sniperData.save()
94+
95+
### For Snippets URLs
96+
try:
97+
print ("https://api.github.com/repos/" + str(owner) + "/" + str(repo_name) + "/contents/" + sniperData.snippets_dir_name + "?ref=master&client_id="
98+
+ GITHUB_CLIENT_ID + "&client_secret=" + GITHUB_CLIENT_SECRET)
99+
snippets_data = urllib.urlopen("https://api.github.com/repos/" + str(owner) + "/" + str(repo_name) + "/contents/" + sniperData.snippets_dir_name + "?ref=master&client_id="
100+
+ GITHUB_CLIENT_ID + "&client_secret=" + GITHUB_CLIENT_SECRET)
101+
snippets = json.loads(snippets_data.read())
102+
for snippet in snippets:
103+
if not snippet['name'].endswith('.js'):
104+
continue
105+
url = "https://cdn.rawgit.com/" + str(owner) + '/' + str(repo_name) + "/" + commit_hash + "/" + sniperData.snippets_dir_name + "/" + snippet['name']
106+
try:
107+
req_snippet = Snippet.objects.get(name=snippet['name'], sniperData=sniperData)
108+
req_snippet.url = url
109+
req_snippet.save()
110+
except:
111+
Snippet.objects.create(name=snippet['name'], sniperData=sniperData, url=url)
112+
except:
113+
pass
11114

12115
def get_github_data(github_url):
13116
response = urllib.urlopen(github_url)
@@ -18,6 +121,7 @@ def get_npm_data():
18121
# response = urllib2.urlopen()
19122
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'}
20123
req = urllib2.Request("http://registry.npmjs.com/-/v1/search?text=keywords:biojs,bionode&size=500", headers=hdr)
124+
# req = urllib2.Request("http://registry.npmjs.com/-/v1/search?text=biojs-vis-msa&size=1", headers=hdr)
21125
response = urllib2.urlopen(req)
22126
data = json.load(response)
23127
return data
@@ -28,8 +132,7 @@ def get_contributors_data(contributors_url):
28132
return data
29133

30134
def get_downloads(downloads_url):
31-
import ast
32-
print downloads_url
135+
print (downloads_url)
33136
response = urllib.urlopen(downloads_url)
34137
downloads = 0
35138
data = ast.literal_eval(response.read())
@@ -48,10 +151,10 @@ def handle(self, *args, **options):
48151
component_data = component['package']
49152
try:
50153
_component = Component.objects.get(name=component_data['name'])
51-
print 'exists'
154+
print ('exists')
52155
except:
53156
_component = Component.objects.create(name=component_data['name'])
54-
print _component.name
157+
print (_component.name)
55158
try:
56159
_component.version = component_data['version']
57160
except:
@@ -104,7 +207,7 @@ def handle(self, *args, **options):
104207
_component.save()
105208

106209
if _component.github_url:
107-
print _component.github_url
210+
print (_component.github_url)
108211
try:
109212
github_data = get_github_data(_component.github_url)
110213
except:
@@ -126,8 +229,25 @@ def handle(self, *args, **options):
126229
_component.created_time = aware_date
127230
except:
128231
pass
232+
# try:
233+
str_date = github_data['updated_at']
234+
req_date = datetime.strptime(str_date, "%Y-%m-%dT%H:%M:%SZ") #This object is timezone unaware
235+
aware_date = pytz.utc.localize(req_date) #This object is now timezone aware
236+
# if _component.github_update_time:
237+
# if aware_date > _component.github_update_time:
238+
# _component.github_updated_time = aware_date
239+
# latest_commit_hash = get_commit_hash(github_data['commits_url'])
240+
# _component.latest_commit_hash = latest_commit_hash
241+
# update_visualizations(_component, latest_commit_hash)
242+
# else:
243+
_component.github_update_time = aware_date
244+
latest_commit_hash = get_commit_hash(github_data['commits_url'])
245+
_component.latest_commit_hash = latest_commit_hash
246+
update_visualizations(_component, latest_commit_hash)
247+
# except:
248+
# pass
129249
_component.save()
130-
print str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
250+
print (str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
131251
try:
132252
contributors_data = get_contributors_data(str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
133253
except:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.13 on 2018-06-20 22:34
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('main', '0010_auto_20180616_1659'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='CSSDependency',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('css_url', models.URLField(null=True)),
21+
('component', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.Component')),
22+
],
23+
),
24+
migrations.CreateModel(
25+
name='JSDependency',
26+
fields=[
27+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
28+
('js_url', models.URLField(null=True)),
29+
('component', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.Component')),
30+
],
31+
),
32+
migrations.CreateModel(
33+
name='Visualization',
34+
fields=[
35+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
36+
('name', models.CharField(max_length=50)),
37+
('url', models.URLField(null=True)),
38+
('component', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.Component')),
39+
],
40+
),
41+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.13 on 2018-06-24 09:30
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('main', '0011_cssdependency_jsdependency_visualization'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='component',
17+
name='github_update_time',
18+
field=models.DateTimeField(null=True),
19+
),
20+
migrations.AddField(
21+
model_name='component',
22+
name='latest_commit_hash',
23+
field=models.CharField(max_length=40, null=True),
24+
),
25+
]

main/migrations/0013_sniperdata.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.13 on 2018-06-25 07:32
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('main', '0012_auto_20180624_0930'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='SniperData',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('no_browserify', models.BooleanField(default=False)),
21+
('wzrd_url', models.URLField(null=True)),
22+
('component', models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.Component')),
23+
],
24+
),
25+
]

main/migrations/0014_snippet.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.13 on 2018-06-26 06:32
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('main', '0013_sniperdata'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='Snippet',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('url', models.URLField()),
21+
('name', models.CharField(max_length=50)),
22+
('sniperData', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.SniperData')),
23+
],
24+
),
25+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.13 on 2018-06-26 06:54
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('main', '0014_snippet'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='sniperdata',
17+
name='snippets_dir_name',
18+
field=models.CharField(default='snippets', max_length=50),
19+
),
20+
]

main/models.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Component(models.Model):
4141
npm_url = models.URLField(null=True)
4242
homepage_url = models.URLField(null=True)
4343
license = models.CharField(max_length=50, null=True)
44+
github_update_time = models.DateTimeField(null=True)
45+
latest_commit_hash = models.CharField(max_length=40, null=True)
4446

4547
def save(self, *args, **kwargs):
4648
if not self.url_name:
@@ -67,4 +69,43 @@ def __unicode__(self):
6769
class Contribution(models.Model):
6870
contributor = models.ForeignKey(Contributor, on_delete=models.SET_NULL, null=True)
6971
component = models.ForeignKey(Component, on_delete=models.SET_NULL, null=True, related_name='contributions')
70-
contributions = models.IntegerField(default=0)
72+
contributions = models.IntegerField(default=0)
73+
74+
class Visualization(models.Model):
75+
name = models.CharField(max_length=50)
76+
component = models.ForeignKey(Component, null=True, on_delete=models.SET_NULL)
77+
url = models.URLField(null=True)
78+
79+
def __unicode__(self):
80+
return self.name + '-' + str(self.component.name)
81+
82+
class JSDependency(models.Model):
83+
js_url = models.URLField(null=True)
84+
component = models.ForeignKey(Component, null=True, on_delete=models.SET_NULL)
85+
86+
def __unicode__(self):
87+
return str(self.component)
88+
89+
class CSSDependency(models.Model):
90+
css_url = models.URLField(null=True)
91+
component = models.ForeignKey(Component, null=True, on_delete=models.SET_NULL)
92+
93+
def __unicode__(self):
94+
return str(self.component)
95+
96+
class SniperData(models.Model):
97+
no_browserify = models.BooleanField(default=False)
98+
wzrd_url = models.URLField(null=True)
99+
component = models.OneToOneField(Component, on_delete=models.SET_NULL, null=True)
100+
snippets_dir_name = models.CharField(max_length=50, default='snippets')
101+
102+
def __unicode__(self):
103+
return str(self.component)
104+
105+
class Snippet(models.Model):
106+
url = models.URLField()
107+
name = models.CharField(max_length=50)
108+
sniperData = models.ForeignKey(SniperData, null=True, on_delete=models.SET_NULL)
109+
110+
def __unicode__(self):
111+
return str(self.sniperData.component)

0 commit comments

Comments
 (0)