Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add analyze-mod command #319

Merged
merged 3 commits into from
Dec 12, 2023
Merged

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Nov 21, 2023

Motivation

The SpaceDockAdder uses a ModAnalyzer component to auto-generate netkans for a mod given its identifier and download URL. I've occasionally had reason to use this myself, but it's cumbersome because I have to run a command prompt, cd to NetKAN-Infra/netkan, run python, import netkan, etc., and the output is in Python object format unless I also run a bunch of YAML related commands.

As I've gotten more at home in VSCode, I remembered that the NetKAN-Infra repo had some kind of dev container thing set up for easy development and usage of its commands. This would be a great way to access the mod analyzer.

Changes

All existing services and utilities now have short_help to fill out the main command's help output:

$ netkan 
Usage: netkan [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  analyze-mod                Autogenerate a mod's .netkan properties
  auto-freezer               Submit or update a PR freezing idle mods
  clean-cache                Purge old downloads from the bot's download cache
  download-counter           Update download counts in a given repo
  dump-status                Print the mod status JSON
  export-status-s3           Update the JSON status file on s3
  indexer                    The Indexer service
  mirror-purge-epochs        Remove epoch strings from archive.org entries
  mirrorer                   The Mirrorer service
  recover-status-timestamps  Set status timestamps based on git repo
  redeploy-service           Update and restart one of the bot's containers
  restore-status             Normalize status database entries
  scheduler                  The Scheduler service
  spacedock-adder            The SpaceDockAdder service
  ticket-closer              Close inactive issues on GitHub

All existing services and utilities now have a doc string for the netkan <command> --help output:

$ netkan auto-freezer --help
Usage: netkan auto-freezer [OPTIONS]

  Scan the given NetKAN repo for mods that haven't updated in a given number
  of days and submit or update a pull request to freeze them

Options:
  --days-limit INTEGER        Number of days to wait before freezing a mod as
                              idle
  --days-till-ignore INTEGER  Mods idle this many days will be ignored
  --debug                     Enable debug logging
  --queue TEXT                SQS Queue to poll for metadata
  --inflation-queues TEXT     SQS Queues to publish inflation tasks
  --ssh-key TEXT              SSH key for accessing repositories
  --deep-clone                Perform a deep clone of the git repos
  --ckanmeta-remotes TEXT     game=Path/URL/SSH to Metadata Repos, ie
                              ksp=http://gihub.com
  --netkan-remotes TEXT       game=Path/URL/SSH to the Stub Metadata Repos, ie
                              [email protected]
  --token TEXT                GitHub Token for PRs
  --repos TEXT                GitHub repos to raise PR against (Org Repo:
                              ksp=CKAN-meta/NetKAN)
  --user TEXT                 GitHub user/org repo resides under (Org User:
                              KSP-CKAN)
  --timeout INTEGER           Reduce message visibility timeout for testing
  --dev                       Disable Production Checks
  --ia-access TEXT            Credentials for Internet Archive
  --ia-secret TEXT            Credentials for Internet Archive
  --ia-collections TEXT       game=Collection, for mirroring mods in on
                              Internet Archive
  --game-id TEXT              Game ID for this task
  --help                      Show this message and exit.

A new netkan analyze-mod command runs the mod analyzer and prints its output in YAML format. Note that it will exclude some fields that are known to the SpaceDockAdder based on other sources of info, such as $kref and license:

$ netkan analyze-mod RationalResourcesJetFamily https://spacedock.info/mod/2201/Rational%20Resources/download/1.60.1
spec_version: v1.18
identifier: RationalResourcesJetFamily
$vref: '#/ckan/ksp-avc'
tags:
  - parts
depends:
  - name: ModuleManager
  - name: B9PartSwitch
install:
  - find: ''
    install_to: GameData

To make this conveniently usable, the --game-id parameter now defaults to KSP. In addition, two pieces of superfluous output are suppressed; the first is changed from INFO to DEBUG (so hidden by default), and the second no longer appears when you don't pass --ssh-key, which many commands do not need:

[2023-11-21 20:53:03,850] [INFO    ] Logging started for 'analyze-mod' at log level 20
[2023-11-21 20:53:03,850] [WARNING ] Private Key required for SSH Git

@HebaruSan HebaruSan added Documentation Improvements or additions to documentation Enhancement New feature or request labels Nov 21, 2023
@HebaruSan
Copy link
Member Author

This is pretty small, low-risk, and nice to have. Self-reviewing...

@HebaruSan HebaruSan merged commit 05fc3d7 into KSP-CKAN:master Dec 12, 2023
3 checks passed
@HebaruSan HebaruSan deleted the feature/cli-analyze-mod branch December 12, 2023 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant