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

Refactor/plugins #3

Merged
merged 9 commits into from
Oct 27, 2017
Merged

Refactor/plugins #3

merged 9 commits into from
Oct 27, 2017

Conversation

ndcampbell
Copy link
Member

@ndcampbell ndcampbell commented Oct 26, 2017

refactored the plugins to use pluginbase and apply a default if not found.

LOG.info("Done.")

exit(0)


def setup_pluginbase(plugin_path):
Copy link
Contributor

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.

Copy link
Member Author

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')
Copy link
Contributor

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?

Copy link
Member Author

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])
Copy link
Contributor

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:
Copy link
Contributor

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.

@ndcampbell
Copy link
Member Author

@sijis I made policies-path optional, and I also renamed the arguement to policies-path instead of plugin-path so that it is more clear what it is searching for. I am going to refer to the plugins as "policies" throughout the code so that their function is clear

@ndcampbell ndcampbell changed the title [WIP] Refactor/plugins Refactor/plugins Oct 27, 2017
artifactory_policy = plugin_source.load_plugin(policy_name)
except ModuleNotFoundError:
if default:
LOG.info("No plugin found for %s. Applying Default", repo)
Copy link
Contributor

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)
Copy link
Contributor

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))
Copy link
Contributor

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:
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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:
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Member Author

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():
Copy link
Contributor

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.

Copy link
Member Author

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))
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, agreed

@ndcampbell ndcampbell merged commit b4151fe into master Oct 27, 2017
@ndcampbell ndcampbell deleted the refactor/plugins branch October 27, 2017 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants