Skip to content

Commit

Permalink
Fixes to support landscape2 (#62)
Browse files Browse the repository at this point in the history
Signed-off-by: John Mertic <[email protected]>
  • Loading branch information
jmertic authored Nov 14, 2024
1 parent e543b9b commit e9e2ce7
Show file tree
Hide file tree
Showing 14 changed files with 528 additions and 361 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Similarly, you can use the command below to upgrade your local install.
pipx upgrade lfx-landscape-tools
```

You can then use the `lfxlandscape` command to run the various commands. Use `lfxlandscape --help` for the options.
You can then use the `lfx_landscape` command to run the various commands. Use `lfx_landscape --help` for the options.

## Contributing

Expand Down
30 changes: 10 additions & 20 deletions lfx_landscape_tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ def __init__(self):
maketextlogo_parser.add_argument("-o", "--output", dest="filename", help="Filename to save created logo to")
maketextlogo_parser.set_defaults(func=self.maketextlogo)

makelogo_parser = subparsers.add_parser("makelogo", help="Create a logo based off an existing log with name as a caption")
makelogo_parser.add_argument("-c", "--crunchbase", dest="crunchbase", required=True, help="Crunchbase entry to match")
makelogo_parser.add_argument("-l", "--baselogo", dest="baselogo", required=True, help="Base logo to add captions to")
makelogo_parser.add_argument("-x", "--excludecategory", dest="category", help="Categories to not look in")

args = parser.parse_args()

logging.basicConfig(
Expand All @@ -71,7 +66,11 @@ def __init__(self):
]
)

args.func(args)
try:
args.func(args)
except AttributeError:
parser.print_help()

logging.getLogger().info("This took {} seconds".format(datetime.now() - self._starttime))

@staticmethod
Expand All @@ -87,6 +86,7 @@ def _dir_path(self,path):
def buildmembers(self,args):
config = Config(args.configfile,view='members')
landscapeoutput = LandscapeOutput(config, resetCategory=True)
logging.getLogger().info("Adding LFX Members data")
landscapeoutput.addItems(LFXMembers(config=config))
landscapeoutput.save()

Expand All @@ -95,6 +95,7 @@ def buildmembers(self,args):
def buildprojects(self,args):
config = Config(args.configfile,view='projects')
landscapeoutput = LandscapeOutput(config, resetCategory=True)
logging.getLogger().info("Adding LFX Projects data")
landscapeoutput.addItems(LFXProjects(config=config))
landscapeoutput.save()

Expand All @@ -103,8 +104,10 @@ def buildprojects(self,args):
def syncprojects(self,args):
config = Config(args.configfile,view='projects')
landscapeoutput = LandscapeOutput(config=config, resetCategory=False)
landscapeoutput.syncItems(LFXProjects(config=config))
logging.getLogger().info("Syncing TAC Agenda Project data")
landscapeoutput.syncItems(TACAgendaProject(config=config))
logging.getLogger().info("Syncing LFX Projects data")
landscapeoutput.syncItems(LFXProjects(config=config))
landscapeoutput.save()

logging.getLogger().info("Successfully added {} projects, updated {} projects, and skipped {} projects".format(landscapeoutput.itemsAdded,landscapeoutput.itemsUpdated,landscapeoutput.itemsErrors))
Expand All @@ -121,16 +124,3 @@ def maketextlogo(self,args):
print(svglogo)

return True

def makelogo(self,args):
# TODO: create parser for all items in landscape, not just one category
landscapeoutput = LandscapeOutput(config=config, resetCategory=True, baseDir=args.basedir)

for item in items:
if os.file.exists(item.logo.filename()) and args.overwrite:
svglogo = SVGLogo(url=baselogo)
svglogo.caption(item.orgname)
item.logo = svglogo

landscapeoutput.updateLandscape()

67 changes: 42 additions & 25 deletions lfx_landscape_tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Config:
projectsAddIndustrySector = False
projectsAddPMOManagedStatus = False
projectsAddParentProject = False
projectsAddCategory = True
projectsDefaultCrunchbase = 'https://www.crunchbase.com/organization/linux-foundation'
projectsFilterByParentSlug = True
tacAgendaProjectUrl = None
Expand All @@ -54,31 +55,32 @@ 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['basedir'] if 'basedir' in data_loaded else os.path.dirname(os.path.normpath(config_file.name))
self.slug = data_loaded['slug'] if 'slug' in data_loaded else Config.slug
self.project = data_loaded['project'] if 'project' in data_loaded else self._lookupProjectFromSlug(self.slug)
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['landscapeProjectsCategory'] if 'landscapeProjectsCategory' in data_loaded else Config.landscapeProjectsCategory
self.landscapeProjectsSubcategories = data_loaded['landscapeProjectsSubcategories'] if 'landscapeProjectsSubcategories' in data_loaded else Config.landscapeProjectsSubcategories
self.landscapeProjectsLevels = data_loaded['landscapeProjectsLevels'] if 'landscapeProjectsLevels' in data_loaded else Config.landscapeProjectsLevels
self.landscapeMembersCategory = data_loaded['landscapeMembersCategory'] if 'landscapeMembersCategory' in data_loaded else Config.landscapeMembersCategory
self.landscapeMembersCategory = data_loaded['landscapeMemberCategory'] if 'landscapeMemberCategory' in data_loaded else Config.landscapeMembersCategory
self.landscapeMembersSubcategories = data_loaded['landscapeMembersSubcategories'] if 'landscapeMembersSubcategories' in data_loaded else Config.landscapeMembersSubcategories
self.landscapeMembersSubcategories = data_loaded['landscapeMemberClasses'] if 'landscapeMemberClasses' in data_loaded else Config.landscapeMembersSubcategories
self.landscapefile = data_loaded['landscapefile'] if 'landscapefile' in data_loaded else Config.landscapefile
self.missingcsvfile = data_loaded['missingcsvfile'] if 'missingcsvfile' in data_loaded else Config.missingcsvfile
self.hostedLogosDir = data_loaded['hostedLogosDir'] if 'hostedLogosDir' in data_loaded else Config.hostedLogosDir
self.memberSuffix = data_loaded['memberSuffix'] if 'memberSuffix' in data_loaded else Config.memberSuffix
self.memberUsePublicMembershipLogo = True if 'memberUsePublicMembershipLogo' in data_loaded and data_loaded['memberUsePublicMembershipLogo'] else Config.memberUsePublicMembershipLogo
self.projectsAddTechnologySector = data_loaded['projectsAddTechnologySector'] if 'projectsAddTechnologySector' in data_loaded else Config.projectsAddTechnologySector
self.projectsAddIndustrySector = data_loaded['projectsAddIndustrySector'] if 'projectsAddIndustrySector' in data_loaded else Config.projectsAddIndustrySector
self.projectsAddPMOManagedStatus = data_loaded['projectsAddPMOManagedStatus'] if 'projectsAddPMOManagedStatus' in data_loaded else Config.projectsAddPMOManagedStatus
self.projectsAddParentProject = data_loaded['projectsAddParentProject'] if 'projectsAddParentProject' in data_loaded else Config.projectsAddParentProject
self.projectsDefaultCrunchbase = data_loaded['projectsDefaultCrunchbase'] if 'projectsDefaultCrunchbase' in data_loaded else Config.projectsDefaultCrunchbase
self.projectsFilterByParentSlug = data_loaded['projectsFilterByParentSlug'] if 'projectsFilterByParentSlug' in data_loaded else Config.projectsFilterByParentSlug
self.tacAgendaProjectUrl = data_loaded['tacAgendaProjectUrl'] if 'tacAgendaProjectUrl' in data_loaded else Config.tacAgendaProjectUrl
self.artworkRepoUrl = data_loaded['artworkRepoUrl'] if 'artworkRepoUrl' in data_loaded else Config.artworkRepoUrl
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']
Expand All @@ -103,9 +105,24 @@ def _lookupProjectFromSlug(self, slug):
if slug:
with session.get(singleSlugEndpointURL.format(slug)) as endpointResponse:
parentProject = endpointResponse.json()
if len(parentProject['Data']) > 0:
return parentProject['Data'][0]["ProjectID"]
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


8 changes: 4 additions & 4 deletions lfx_landscape_tools/landscapemembers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def loadData(self):
with suppress(ValueError):
if key != 'enduser':
setattr(member, key, value)
member.orgname = item['name'] if 'name' in item else None
member.orgname = item.get('name')
member.membership = ''
with suppress(ValueError):
member.website = item['homepage_url']
member.logo = self.normalizeLogo(item['logo'],landscape['repo'])
member.crunchbase = item['crunchbase'] if 'crunchbase' in item else None
member.website = item.get('homepage_url')
member.logo = self.normalizeLogo(item.get('logo'),landscape.get('repo'))
member.crunchbase = item.get('crunchbase')
self.members.append(member)

def normalizeLogo(self, logo, landscapeRepo):
Expand Down
Loading

0 comments on commit e9e2ce7

Please sign in to comment.