-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
128 lines (112 loc) · 6.25 KB
/
config.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
#
# Copyright this project and it's contributors
# SPDX-License-Identifier: Apache-2.0
#
# encoding=utf8
## built in modules
import sys
import os
import io
import logging
## third party modules
import ruamel.yaml
import requests
import requests_cache
class Config:
project = None
view = 'members'
slug = None
landscapeMembersCategory = 'Members'
landscapeMembersSubcategories = [
{"name": "Premier Membership", "category": "Premier"},
{"name": "General Membership", "category": "General"},
]
landscapeProjectsLevels = [
{"name": "Active", "level": "active"},
{"name": "Incubation", "level": "incubation"},
{"name": "Sandbox", "level": "sandbox"},
]
landscapeProjectsCategory = 'Projects'
landscapeProjectsSubcategories = [
{"name": "All", "category": "All"}
]
basedir = "."
landscapefile = 'landscape.yml'
missingcsvfile = 'missing.csv'
hostedLogosDir = 'hosted_logos'
memberSuffix = None
memberUsePublicMembershipLogo = False
projectsAddTechnologySector = False
projectsAddIndustrySector = False
projectsAddPMOManagedStatus = False
projectsAddParentProject = False
projectsAddCategory = True
projectsDefaultCrunchbase = 'https://www.crunchbase.com/organization/linux-foundation'
projectsFilterByParentSlug = True
tacAgendaProjectUrl = None
artworkRepoUrl = None
def __init__(self, config_file: io.TextIOWrapper = None, view = None):
if config_file:
data_loaded = ruamel.yaml.YAML(typ='safe', pure=True).load(config_file)
self.view = view if self._isValidViewOption(view) else Config.view
self.basedir = data_loaded.get('basedir',os.path.dirname(os.path.normpath(config_file.name)))
self.slug = data_loaded.get('slug',self._lookupSlugFromProject(data_loaded.get('project')))
self.project = data_loaded.get('project',self._lookupProjectFromSlug(self.slug))
if not self.slug or not self.project:
raise ValueError("Invalid project specification in config file")
self.landscapeProjectsCategory = data_loaded.get('landscapeProjectsCategory',Config.landscapeProjectsCategory)
self.landscapeProjectsSubcategories = data_loaded.get('landscapeProjectsSubcategories',Config.landscapeProjectsSubcategories)
self.landscapeProjectsLevels = data_loaded.get('landscapeProjectsLevels',Config.landscapeProjectsLevels)
self.landscapeMembersCategory = data_loaded.get('landscapeMembersCategory',Config.landscapeMembersCategory)
self.landscapeMembersCategory = data_loaded.get('landscapeMemberCategory',Config.landscapeMembersCategory)
self.landscapeMembersSubcategories = data_loaded.get('landscapeMembersSubcategories',Config.landscapeMembersSubcategories)
self.landscapeMembersSubcategories = data_loaded.get('landscapeMemberClasses',Config.landscapeMembersSubcategories)
self.landscapefile = data_loaded.get('landscapefile',Config.landscapefile)
self.missingcsvfile = data_loaded.get('missingcsvfile',Config.missingcsvfile)
self.hostedLogosDir = data_loaded.get('hostedLogosDir',Config.hostedLogosDir)
self.memberSuffix = data_loaded.get('memberSuffix',Config.memberSuffix)
self.memberUsePublicMembershipLogo = data_loaded.get('memberUsePublicMembershipLogo',Config.memberUsePublicMembershipLogo)
self.projectsAddTechnologySector = data_loaded.get('projectsAddTechnologySector',Config.projectsAddTechnologySector)
self.projectsAddIndustrySector = data_loaded.get('projectsAddIndustrySector',Config.projectsAddIndustrySector)
self.projectsAddPMOManagedStatus = data_loaded.get('projectsAddPMOManagedStatus',Config.projectsAddPMOManagedStatus)
self.projectsAddParentProject = data_loaded.get('projectsAddParentProject',Config.projectsAddParentProject)
self.projectsAddCategory = data_loaded.get('projectsAddCategory',Config.projectsAddCategory)
self.projectsDefaultCrunchbase = data_loaded.get('projectsDefaultCrunchbase',Config.projectsDefaultCrunchbase)
self.projectsFilterByParentSlug = data_loaded.get('projectsFilterByParentSlug',Config.projectsFilterByParentSlug)
self.tacAgendaProjectUrl = data_loaded.get('tacAgendaProjectUrl',Config.tacAgendaProjectUrl)
self.artworkRepoUrl = data_loaded.get('artworkRepoUrl',Config.artworkRepoUrl)
def _isValidViewOption(self,view):
return view in ['projects','members']
@property
def landscapeCategory(self):
if self.view == 'projects':
return self.landscapeProjectsCategory
elif self.view == 'members':
return self.landscapeMembersCategory
@property
def landscapeSubcategories(self):
if self.view == 'projects':
return self.landscapeProjectsSubcategories
elif self.view == 'members':
return self.landscapeMembersSubcategories
def _lookupProjectFromSlug(self, slug):
singleSlugEndpointURL = 'https://api-gw.platform.linuxfoundation.org/project-service/v1/public/projects?slug={}'
session = requests_cache.CachedSession()
if slug:
with session.get(singleSlugEndpointURL.format(slug)) as endpointResponse:
parentProject = endpointResponse.json()
if len(parentProject.get('Data')) > 0:
return parentProject.get('Data')[0].get("ProjectID")
logging.getLogger().warning("Couldn't find project for slug '{}'".format(slug))
return None
def _lookupSlugFromProject(self,project):
singleProjectEndpointURL = 'https://api-gw.platform.linuxfoundation.org/project-service/v1/public/projects?$filter=projectId%20eq%20{}'
session = requests_cache.CachedSession()
if project:
with session.get(singleProjectEndpointURL.format(project)) as endpointResponse:
parentProject = endpointResponse.json()
if len(parentProject.get('Data')) > 0:
return parentProject.get('Data',[])[0].get("Slug")
logging.getLogger().warning("Couldn't find slug for project '{}'".format(project))
return None