# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 2014 Bitergium SLL
from utils import Configuration, Forges
from django.db import connections
class FSF():
@staticmethod
def search(name):
project_list = []
cursor = connections['local_flossmole'].cursor()
parameters = { 'limit': Configuration.max_number_of_records }
cursor.execute("SELECT proj_unixname, datasource_id, proj_long_name, desc_long FROM fsf_projects WHERE LOWER(proj_unixname) LIKE '%%" + name.lower() + "%%' LIMIT %(limit)s", parameters)
results = cursor.fetchall()
for record in results:
fp = FlossmoleProject()
fp.id = record[0]
fp.id_forge = Forges.FSF
fp.datasource_id = record[1]
fp.name = record[2]
fp.description = record[3]
project_list.append(fp)
return project_list
@staticmethod
def getProjectInfo(project_identifier):
info = {}
cursor = connections['local_flossmole'].cursor()
cursor.execute("SELECT max(datasource_id) FROM fsf_projects")
row = cursor.fetchone()
datasource_id = row[0]
parameters = { 'datasource_id': datasource_id, 'project_identifier': project_identifier }
cursor.execute("SELECT proj_long_name, desc_long, url, real_url, released_on, proj_num FROM fsf_projects WHERE proj_unixname=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
result = cursor.fetchone()
info['name'] = result[0]
info['desc_long'] = result[1]
info['url'] = result[2]
info['real_url'] = result[3]
info['released_on'] = result[4]
proj_num = result[5]
info['licenses'] = []
parameters = { 'datasource_id': datasource_id, 'proj_num': proj_num }
cursor.execute("SELECT license FROM fsf_project_licenses WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
info['licenses'].append(record[0])
info['developers'] = []
cursor.execute("SELECT person_name, role, email FROM fsf_developer_projects WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
developer = {}
developer['person_name'] = record[0]
developer['role'] = record[1]
developer['email'] = record[2]
info['developers'].append(developer)
info['categories'] = []
parameters = { 'datasource_id': datasource_id, 'proj_num': proj_num }
cursor.execute("SELECT project_category_title FROM fsf_project_categories WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
info['categories'].append(record[0])
info['requirements'] = []
cursor.execute("SELECT requirement, requirement_type FROM fsf_project_requirements WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
requirement = {}
requirement['requirement'] = record[0]
requirement['requirement_type'] = record[1]
info['requirements'].append(requirement)
return info
class FC():
@staticmethod
def search(name):
project_list = []
cursor = connections['local_flossmole'].cursor()
parameters = { 'name': name, 'limit': Configuration.max_number_of_records }
cursor.execute("SELECT project_id, datasource_id, projectname_full, desc_short FROM fm_projects WHERE LOWER(projectname_full) LIKE '%%" + name.lower() + "%%' LIMIT %(limit)s", parameters)
results = cursor.fetchall()
for record in results:
fp = FlossmoleProject()
fp.id = record[0]
fp.id_forge = Forges.FC
fp.datasource_id = record[1]
fp.name = record[2]
fp.description = record[3]
project_list.append(fp)
return project_list
@staticmethod
def getProjectInfo(project_identifier):
info = {}
cursor = connections['local_flossmole'].cursor()
cursor.execute("SELECT max(datasource_id) FROM fm_projects")
row = cursor.fetchone()
datasource_id = row[0]
parameters = { 'datasource_id': datasource_id, 'project_identifier': project_identifier }
cursor.execute('''SELECT date_added, date_updated, projectname_full, desc_short, desc_full, vitality_score,
popularity_score, rating, rating_count, subscriptions, url_homepage, url_tgz, url_changelog,
url_cvs, url_bugtracker, url_list, url_demo, url_project_page, license, latest_release_version,
latest_release_date, screenshot_thumb, calc_dev_count FROM fm_projects
WHERE project_id=%(project_identifier)s and datasource_id=%(datasource_id)s''', parameters)
result = cursor.fetchone()
info['date_added'] = result[0]
info['date_updated'] = result[1]
info['projectname_full'] = result[2]
info['desc_short'] = result[3]
info['desc_full'] = result[4]
info['vitality_score'] = result[5]
info['popularity_score'] = result[6]
info['rating'] = result[7]
info['rating_count'] = result[8]
info['subscriptions'] = result[9]
info['url_homepage'] = result[10]
info['url_tgz'] = result[11]
info['url_changelog'] = result[12]
info['url_cvs'] = result[13]
info['url_bugtracker'] = result[14]
info['url_list'] = result[15]
info['url_demo'] = result[16]
info['url_project_page'] = result[17]
info['license'] = result[18]
info['latest_release_version'] = result[19]
info['latest_release_date'] = result[20]
info['screenshot_thumb'] = result[21]
info['calc_dev_count'] = result[22]
parameters = { 'datasource_id': datasource_id, 'project_id': project_identifier }
info['authors'] = []
cursor.execute("SELECT author_name, author_url, author_role FROM fm_project_authors WHERE project_id=%(project_id)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
author = {}
author['author_name'] = record[0]
author['author_url'] = record[1]
author['author_role'] = record[2]
info['authors'].append(author)
info['dependencies'] = []
cursor.execute("SELECT dependency_project_id, dependency_project_title FROM fm_project_dependencies WHERE project_id=%(project_id)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
dependency = {}
dependency['dependency_project_id'] = record[0]
dependency['dependency_project_title'] = record[1]
info['dependencies'].append(dependency)
info['tags'] = []
cursor.execute("SELECT tag_name FROM fm_project_tags WHERE project_id=%(project_id)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
info['tags'].append(record[0])
return info
class GC():
@staticmethod
def search(name):
project_list = []
cursor = connections['local_flossmole'].cursor()
parameters = { 'name': name, 'limit': Configuration.max_number_of_records }
cursor.execute("SELECT proj_name, datasource_id, proj_name, project_summary FROM gc_projects WHERE LOWER(proj_name) LIKE '%%" + name.lower() + "%%' LIMIT %(limit)s", parameters)
results = cursor.fetchall()
for record in results:
fp = FlossmoleProject()
fp.id = record[0]
fp.id_forge = Forges.GC
fp.datasource_id = record[1]
fp.name = record[2]
fp.description = record[3]
project_list.append(fp)
return project_list
@staticmethod
def getProjectInfo(project_identifier):
info = {}
cursor = connections['local_flossmole'].cursor()
cursor.execute("SELECT max(datasource_id) FROM gc_projects")
row = cursor.fetchone()
datasource_id = row[0]
parameters = { 'datasource_id': datasource_id, 'project_identifier': project_identifier }
cursor.execute("SELECT last_updated, code_license, code_url, project_summary, project_description FROM gc_projects WHERE proj_name=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
result = cursor.fetchone()
info['last_updated'] = result[0]
info['code_license'] = result[1]
info['code_url'] = result[2]
info['project_summary'] = result[3]
info['project_description'] = result[4]
info['blogs'] = []
cursor.execute("SELECT blog_title, blog_link FROM gc_project_blogs WHERE proj_name=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
blog = {}
blog['blog_title'] = record[0]
blog['blog_link'] = record[1]
info['blogs'].append(blog)
info['groups'] = []
cursor.execute("SELECT group_name, group_url FROM gc_project_groups WHERE proj_name=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
group = {}
group['group_name'] = record[0]
group['group_url'] = record[1]
info['groups'].append(group)
info['labels'] = []
cursor.execute("SELECT label FROM gc_project_labels WHERE proj_name=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
info['labels'].append(record[0])
info['links'] = []
cursor.execute("SELECT link_title, link FROM gc_project_links WHERE proj_name=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
link = {}
link['link_title'] = record[0]
link['link'] = record[1]
info['links'].append(link)
info['people'] = []
cursor.execute("SELECT person_name, user_id, role FROM gc_project_people WHERE proj_name=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
results = cursor.fetchall()
for record in results:
person = {}
person['person_name'] = record[0]
person['user_id'] = record[1]
person['role'] = record[1]
info['people'].append(person)
return info
class GH():
@staticmethod
def search(name):
project_list = []
cursor = connections['local_flossmole'].cursor()
parameters = { 'name': name, 'limit': Configuration.max_number_of_records }
cursor.execute("SELECT project_name, datasource_id, project_name, description FROM gh_projects WHERE LOWER(project_name) LIKE '%%" + name.lower() + "%%' LIMIT %(limit)s", parameters)
results = cursor.fetchall()
for record in results:
fp = FlossmoleProject()
fp.id = record[0]
fp.id_forge = Forges.GH
fp.datasource_id = record[1]
fp.name = record[2]
fp.description = record[3]
project_list.append(fp)
return project_list
@staticmethod
def getProjectInfo(project_identifier):
info = {}
cursor = connections['local_flossmole'].cursor()
cursor.execute("SELECT max(datasource_id) FROM gh_projects")
row = cursor.fetchone()
datasource_id = row[0]
parameters = { 'datasource_id': datasource_id, 'project_identifier': project_identifier }
cursor.execute("SELECT developer_name, description FROM gh_projects WHERE project_name=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
result = cursor.fetchone()
info['developer_name'] = result[0]
info['description'] = result[1]
return info
class FlossmoleProject():
id = 0
id_forge = 0
datasource_id = 0
name = ""
description = ""