-
Notifications
You must be signed in to change notification settings - Fork 14
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
Refactor/plugins #3
Conversation
LOG.info("Done.") | ||
|
||
exit(0) | ||
|
||
|
||
def setup_pluginbase(plugin_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called extra_plugin_path
and probably have a default value.
I also think this should be optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
@click.option('--project', default=None, help='Operate on single project') | ||
@click.option( | ||
'--dryrun/--nodryrun', default=True, is_flag=True, help='Dryrun does not delete any artifacts. On by default') | ||
@click.option('--plugin-path', required=True, help='Path to plugin directory') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be optional. I should just be able to run it.
A normal person may not care about the plugins. What if they don't have any custom ones? What would they enter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. I will update that
default_path = "{}/plugins".format(here) | ||
LOG.info("Searching for plugins in %s and %s", plugin_path, default_path) | ||
plugin_base = PluginBase(package='artifactorypurge.plugins') | ||
plugin_source = plugin_base.make_plugin_source(searchpath=[plugin_path, default_path]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once extra_plugin_path
is optional, you'll have to adjust this.
Maybe soemthing like this:
+ all_paths = [default_path]
+ if plugin_path:
+ all_paths.append(plugin_path)
for repo, info in before.items(): | ||
fp = 0 | ||
plugin_name = repo.replace("-", "_") | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to look at this tomorrow and give more feedback then.
@sijis I made |
artifactory_policy = plugin_source.load_plugin(policy_name) | ||
except ModuleNotFoundError: | ||
if default: | ||
LOG.info("No plugin found for %s. Applying Default", repo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change name to policy
.
LOG.info("No plugin found for %s. Applying Default", repo) | ||
artifactory_policy = plugin_source.load_plugin('default') | ||
else: | ||
LOG.info("No plugin found for %s. Skipping Default", repo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to policy
.
None, | ||
) | ||
count = artifactory.purge(repo, dryrun, artifacts) | ||
LOG.info("processed {}, purged {}".format(repo, count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use capital P's.
here = os.path.dirname(os.path.realpath(__file__)) | ||
default_path = "{}/policies".format(here) | ||
all_paths = [default_path] | ||
if extra_policies_path: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably validate that path provided exists too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this, added exception
finally: | ||
if fp: | ||
fp.close() | ||
artifactory_policy = plugin_source.load_plugin(policy_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think thre's a need to sprinkle 'artifactory' in the variable on everything. Its just a policy.
It's also a little hard to do searches if everything is 'artifactory_'...
if fp: | ||
fp.close() | ||
artifactory_policy = plugin_source.load_plugin(policy_name) | ||
except ModuleNotFoundError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic is sound.
I would maybe move the No plugin found for ...
stuff outside the if/else and add a second entry for appying the default policy or not.
credentials['artifactory_password']) | ||
|
||
before = artifactory.list(reponame) | ||
plugin_source = setup_pluginbase(extra_policies_path=policies_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'd probably want to add a LOG.debug
to show you all the plugins found. I'm sure we will need this later when troubleshooting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
|
||
LOG.info("") | ||
LOG.info("Purging Performance:") | ||
after = artifactory.list(reponame) | ||
after = artifactory.list(None) | ||
for repo, info in after.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not specific to actual changes, but moving this to a separate function may make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
completely agree, this was Alex code that I just had not refactored yet.
all_paths = [default_path] | ||
if extra_policies_path: | ||
all_paths.append(extra_policies_path) | ||
LOG.info("Searching for policies in %s", str(all_paths)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if str(all_paths)
should be ', '.join(all_paths)
. it seems to look better locally. More cosmetic'ish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, agreed
refactored the plugins to use pluginbase and apply a default if not found.