Module and states code refactor

Change-Id: Ia1c468d0b55603b6274ca0d275b2720602e5319e
diff --git a/_states/jenkins_plugin.py b/_states/jenkins_plugin.py
index cb54633..d9fe8e9 100644
--- a/_states/jenkins_plugin.py
+++ b/_states/jenkins_plugin.py
@@ -1,4 +1,5 @@
 import logging
+
 logger = logging.getLogger(__name__)
 
 install_plugin_groovy = """\
@@ -8,43 +9,43 @@
 def logger = Logger.getLogger("")
 def installed = false
 def exists = false
-def pluginName="{plugin}"
+def pluginName="${plugin}"
 def instance = Jenkins.getInstance()
 def pm = instance.getPluginManager()
 def uc = instance.getUpdateCenter()
-def needUpdateSites(maxOldInSec = 1800){{
+def needUpdateSites(maxOldInSec = 1800){
   long oldestTs = 0
-  for (UpdateSite s : Jenkins.instance.updateCenter.siteList) {{
-    if(oldestTs == 0 || s.getDataTimestamp()<oldestTs){{
+  for (UpdateSite s : Jenkins.instance.updateCenter.siteList) {
+    if(oldestTs == 0 || s.getDataTimestamp()<oldestTs){
        oldestTs = s.getDataTimestamp()
-    }}
-  }}
+    }
+  }
    return (System.currentTimeMillis()-oldestTs)/1000 > maxOldInSec
-}}
+}
 
-if (!pm.getPlugin(pluginName)) {{
-  if(needUpdateSites()) {{
+if (!pm.getPlugin(pluginName)) {
+  if(needUpdateSites()) {
      uc.updateAllSites()
-  }}
+  }
   def plugin = uc.getPlugin(pluginName)
-  if (plugin) {{
+  if (plugin) {
     plugin.deploy()
     installed = true
-  }}
-}}else{{
+  }
+}else{
     exists = true
     print("EXISTS")
-}}
-if (installed) {{
+}
+if (installed) {
   instance.save()
-  if({restart}){{
+  if({restart}){
       instance.doSafeRestart()
-   }}
+   }
   print("INSTALLED")
-}}else if(!exists){{
+}else if(!exists){
   print("FAILED")
-}}
-""" # noqa
+}
+"""  # noqa
 
 remove_plugin_groovy = """
 import jenkins.model.*
@@ -54,27 +55,27 @@
 def installed = false
 def initialized = false
 
-def pluginName="{plugin}"
+def pluginName="${plugin}"
 def instance = Jenkins.getInstance()
 def pm = instance.getPluginManager()
 
 def actPlugin = pm.getPlugin(pluginName)
-if (!actPlugin) {{
+if (!actPlugin) {
    def pluginToInstall = Jenkins.instance.updateCenter.getPlugin(pluginName)
-   if(!pluginToInstall){{
+   if(!pluginToInstall){
       print("FAILED")
-   }}else{{
+   }else{
       print("NOT PRESENT")
-   }}
-}} else {{
+   }
+} else {
    actPlugin.disable()
    actPlugin.archive.delete()
-   if({restart}){{
+   if({restart}){
       instance.doSafeRestart()
-   }}
+   }
    print("REMOVED")
-}}
-""" # noqa
+}
+"""  # noqa
 
 
 def __virtual__():
@@ -97,7 +98,8 @@
     :param restart: do you want to restart jenkins after plugin install?
     :returns: salt-specified state dict
     """
-    return _plugin_call(name, restart, install_plugin_groovy, ["INSTALLED", "EXISTS"])
+    return _plugin_call(name, restart, install_plugin_groovy, [
+                        "INSTALLED", "EXISTS"])
 
 
 def absent(name, restart=False):
@@ -108,7 +110,8 @@
     :param restart: do you want to restart jenkins after plugin remove?
     :returns: salt-specified state dict
     """
-    return _plugin_call(name, restart, remove_plugin_groovy, ["REMOVED", "NOT PRESENT"])
+    return _plugin_call(name, restart, remove_plugin_groovy, [
+                        "REMOVED", "NOT PRESENT"])
 
 
 def _plugin_call(name, restart, template, success_msgs):
@@ -131,13 +134,14 @@
             status = call_result["msg"]
             if status == success_msgs[0]:
                 ret['changes'][name] = status
-            ret['comment'] = 'Jenkins plugin %s %s%s' % (name, status.lower(), ", jenkins restarted" if status == success_msgs[0] and restart else "")
+            ret['comment'] = 'Jenkins plugin %s %s%s' % (name, status.lower(
+            ), ", jenkins restarted" if status == success_msgs[0] and restart else "")
             result = True
         else:
             status = 'FAILED'
             logger.error(
                 "Jenkins plugin API call failure: %s", call_result["msg"])
             ret['comment'] = 'Jenkins plugin API call failure: %s' % (call_result[
-                                                                           "msg"])
+                "msg"])
     ret['result'] = None if test else result
     return ret