-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I forgot to add the cli_report.py to the patch yesterday, here is an
updated version. My bad.
AS
Anderson Silva wrote:
> This is my first patch, and I had limited resources for testing.
>
> Consider this a 'working in progress'
>
> Feel free to submit feedback. One thing I still would like to do is:
>
> cobbler report --what=system --list-all-fields
>
> Which would provide a list of all available fields to anyone who would
> like use customize the report with the --fields options.
>
> AS
- ------------------------------------------------------------------------
_______________________________________________
cobbler mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/cobbler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFItAFYECmX3C4JWKgRAjnRAKDDT5YLKNPhF7AJSVEO7NporxpsjwCgvY0M
vNb/5Jmoj5MSMQc6YO/zYuc=
=Hd8N
-----END PGP SIGNATURE-----
diff --git a/cobbler/action_report.py b/cobbler/action_report.py
index e69de29..506a3ee 100644
--- a/cobbler/action_report.py
+++ b/cobbler/action_report.py
@@ -0,0 +1,295 @@
+"""
+Report from a cobbler master.
+
+Copyright 2007-2008, Red Hat, Inc
+Anderson Silva <[EMAIL PROTECTED]>
+
+
+This software may be freely redistributed under the terms of the GNU
+general public license.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""
+
+import os
+import os.path
+import xmlrpclib
+import api as cobbler_api
+from utils import _
+
+
+class Report:
+
+ def __init__(self, config):
+ """
+ Constructor
+ """
+ self.config = config
+ self.settings = config.settings()
+ self.api = config.api
+ self.remote = None
+ self.uri = None
+
+ def reporting_csv(self, info, order):
+ """
+ Formats data on 'info' for csv output
+ """
+ outputheaders = ''
+ outputbody = ''
+ sep = ','
+
+ info_count = 0
+ for item in info:
+
+ item_count = 0
+ for key in order:
+
+ if info_count == 0:
+ outputheaders += str(key) + sep
+
+ outputbody += str(item[key]) + sep
+
+ item_count = item_count + 1
+
+ info_count = info_count + 1
+ outputbody += '\n'
+
+ outputheaders += '\n'
+ return outputheaders + outputbody
+
+ def reporting_trac(self, info, order):
+ """
+ Formats data on 'info' for trac wiki table output
+ """
+ outputheaders = ''
+ outputbody = ''
+ sep = '||'
+
+ info_count = 0
+ for item in info:
+
+ item_count = 0
+ for key in order:
+
+ if info_count == 0:
+ outputheaders += sep + str(key)
+
+ outputbody += sep + str(item[key])
+
+ item_count = item_count + 1
+
+ info_count = info_count + 1
+ outputbody += '||\n'
+
+ outputheaders += '||\n'
+ return outputheaders + outputbody
+
+ def reporting_doku(self, info, order):
+ """
+ Formats data on 'info' for doku wiki table output
+ """
+ outputheaders = ''
+ outputbody = ''
+ sep1 = '^'
+ sep2 = '|'
+
+
+ info_count = 0
+ for item in info:
+
+ item_count = 0
+ for key in order:
+
+ if info_count == 0:
+ outputheaders += sep1 + key
+
+ outputbody += sep2 + item[key]
+
+ item_count = item_count + 1
+
+ info_count = info_count + 1
+ outputbody += sep2 + '\n'
+
+ outputheaders += sep1 + '\n'
+ return outputheaders + outputbody
+
+
+ def reporting_mediawiki(self, info, order):
+ """
+ Formats data on 'info' for mediawiki table output
+ """
+ outputheaders = ''
+ outputbody = ''
+ opentable = '{| border="1"\n'
+ closetable = '|}\n'
+ sep1 = '||'
+ sep2 = '|'
+ sep3 = '|-'
+
+
+ info_count = 0
+ for item in info:
+
+ item_count = 0
+ for key in order:
+
+ if info_count == 0 and item_count == 0:
+ outputheaders += sep2 + key
+ elif info_count == 0:
+ outputheaders += sep1 + key
+
+ if item_count == 0:
+ outputbody += sep2 + item[key]
+ else:
+ outputbody += sep1 + item[key]
+
+ item_count = item_count + 1
+
+ info_count = info_count + 1
+ outputbody += '\n' + sep3 + '\n'
+
+ outputheaders += '\n' + sep3 + '\n'
+ return opentable + outputheaders + outputbody + closetable
+
+ def print_formatted_data(self, data, order, report_type):
+ """
+ Used for picking the correct format to output data as
+ """
+ if report_type == "csv":
+ print self.reporting_csv(data, order)
+ if report_type == "mediawiki":
+ print self.reporting_mediawiki(data, order)
+ if report_type == "trac":
+ print self.reporting_trac(data, order)
+ if report_type == "doku":
+ print self.reporting_doku(data, order)
+
+ return True
+
+ def reporting_sorter(self, a, b):
+ """
+ Used for sorting cobbler objects for report commands
+ """
+ return cmp(a.name, b.name)
+
+ def reporting_print_sorted(self, collection):
+ """
+ Prints all objects in a collection sorted by name
+ """
+ collection = [x for x in collection]
+ collection.sort(self.reporting_sorter)
+ for x in collection:
+ print x.printable()
+ return True
+
+ def reporting_list_names2(self, collection, name):
+ """
+ Prints a specific object in a collection.
+ """
+ obj = collection.find(name=name)
+ if obj is not None:
+ print obj.printable()
+ return True
+
+ def reporting_print_all_fields(self, collection, report_type):
+ """
+ Prints all fields in a collection as a table given the report type
+ """
+ collection = [x for x in collection]
+ collection.sort(self.reporting_sorter)
+ data = []
+ for x in collection:
+ structure = x.to_datastruct()
+ data.append(structure)
+
+ self.print_formatted_data(data = data, order = None, report_type = report_type)
+
+ return True
+
+ def reporting_print_x_fields(self, collection, report_type, report_fields):
+ """
+ Prints specific fields in a collection as a table given the report type
+ """
+ collection = [x for x in collection]
+ collection.sort(self.reporting_sorter)
+ data = []
+ for x in collection:
+ structure = x.to_datastruct()
+ item = {}
+ for field in report_fields:
+ if field in structure.keys():
+ item[field] = structure[field]
+ data.append(item)
+
+ self.print_formatted_data(data = data, order = report_fields, report_type = report_type)
+
+ return True
+
+ # -------------------------------------------------------
+
+ def run(self, report_what = None, report_name = None, report_type = None, report_fields = None):
+ """
+ Get remote profiles and distros and sync them locally
+ """
+
+ """
+ 1. Handles original report output
+ 2. Handles all fields of report outputs as table given a format
+ 3. Handles specific fields of report outputs as table given a format
+ """
+
+ if report_type is "text" and report_fields is "all":
+
+ if report_what in [ "all", "distros" ]:
+ if report_name:
+ self.reporting_list_names2(self.api.distros(), report_name)
+ else:
+ self.reporting_print_sorted(self.api.distros())
+
+ if report_what in [ "all", "profiles" ]:
+ if report_name:
+ self.reporting_list_names2(self.api.profiles(), report_name)
+ else:
+ self.reporting_print_sorted(self.api.profiles())
+
+ if report_what in [ "all", "systems" ]:
+ if report_name:
+ self.reporting_list_names2(self.api.systems(), report_name)
+ else:
+ self.reporting_print_sorted(self.api.systems())
+
+ if report_what in [ "all", "repos" ]:
+ if report_name:
+ self.reporting_list_names2(self.api.repos(), report_name)
+ else:
+ self.reporting_print_sorted(self.api.repos())
+
+ elif report_type is not "text" and report_fields is "all":
+
+ if report_what in [ "all", "distros" ]:
+ self.reporting_print_all_fields(self.api.distros(), report_type)
+
+ if report_what in [ "all", "profiles" ]:
+ self.reporting_print_all_fields(self.api.profiles(), report_type)
+
+ if report_what in [ "all", "systems" ]:
+ self.reporting_print_all_fields(self.api.systems(), report_type)
+
+ if report_what in [ "all", "repos" ]:
+ self.reporting_print_all_fields(self.api.repos(), report_type)
+
+ else:
+
+ if report_what in [ "all", "distros" ]:
+ self.reporting_print_x_fields(self.api.distros(), report_type, report_fields)
+
+ if report_what in [ "all", "profiles" ]:
+ self.reporting_print_x_fields(self.api.profiles(), report_type, report_fields)
+
+ if report_what in [ "all", "systems" ]:
+ self.reporting_print_x_fields(self.api.systems(), report_type, report_fields)
+
+ if report_what in [ "all", "repos" ]:
+ self.reporting_print_x_fields(self.api.repos(), report_type, report_fields)
diff --git a/cobbler/api.py b/cobbler/api.py
index 70cc73b..316057a 100644
--- a/cobbler/api.py
+++ b/cobbler/api.py
@@ -24,6 +24,7 @@ import action_status
import action_validate
import action_buildiso
import action_replicate
+import action_report
from cexceptions import *
import sub_process
import module_loader
@@ -431,6 +432,11 @@ class BootAPI:
def replicate(self, cobbler_master = None):
replicator = action_replicate.Replicate(self._config)
return replicator.run(cobbler_master = cobbler_master)
+
+ def report(self, report_what = None, report_name = None, report_type = None, report_fields = None):
+ reporter = action_report.Report(self._config)
+ return reporter.run(report_what = report_what, report_name = report_name,\
+ report_type = report_type, report_fields = report_fields)
def get_kickstart_templates(self):
return utils.get_kickstar_templates(self)
diff --git a/cobbler/modules/cli_misc.py b/cobbler/modules/cli_misc.py
index c72b11d..d211442 100644
--- a/cobbler/modules/cli_misc.py
+++ b/cobbler/modules/cli_misc.py
@@ -141,48 +141,6 @@ class ListFunction(commands.CobblerFunction):
if self.options.what in [ "repos"]:
self.list_list(self.api.repos())
-########################################################
-
-class ReportFunction(commands.CobblerFunction):
-
- def help_me(self):
- return HELP_FORMAT % ("cobbler report","[ARGS|--help]")
-
- def command_name(self):
- return "report"
-
- def add_options(self, p, args):
- p.add_option("--what", dest="what", default="all", help="distros/profiles/systems/repos")
- p.add_option("--name", dest="name", help="report on just this object")
-
- def run(self):
- if self.options.what not in [ "all", "distros", "profiles", "systems", "repos" ]:
- raise CX(_("Invalid value for --what"))
-
- if self.options.what in [ "all", "distros" ]:
- if self.options.name:
- self.reporting_list_names2(self.api.distros(),self.options.name)
- else:
- self.reporting_print_sorted(self.api.distros())
-
- if self.options.what in [ "all", "profiles" ]:
- if self.options.name:
- self.reporting_list_names2(self.api.profiles(),self.options.name)
- else:
- self.reporting_print_sorted(self.api.profiles())
-
- if self.options.what in [ "all", "systems" ]:
- if self.options.name:
- self.reporting_list_names2(self.api.systems(),self.options.name)
- else:
- self.reporting_print_sorted(self.api.systems())
-
- if self.options.what in [ "all", "repos" ]:
- if self.options.name:
- self.reporting_list_names2(self.api.repos(),self.options.name)
- else:
- self.reporting_print_sorted(self.api.repos())
- return True
########################################################
@@ -292,7 +250,8 @@ def cli_functions(api):
return [
BuildIsoFunction(api),
CheckFunction(api), ImportFunction(api), ReserializeFunction(api),
- ListFunction(api), ReportFunction(api), StatusFunction(api),
+ ListFunction(api),
+ StatusFunction(api),
SyncFunction(api), RepoSyncFunction(api), ValidateKsFunction(api),
ReplicateFunction(api)
]
diff --git a/cobbler/modules/cli_report.py b/cobbler/modules/cli_report.py
index e69de29..204584a 100644
--- a/cobbler/modules/cli_report.py
+++ b/cobbler/modules/cli_report.py
@@ -0,0 +1,66 @@
+"""
+Report CLI module.
+
+Copyright 2008, Red Hat, Inc
+Anderson Silva <[EMAIL PROTECTED]
+
+This software may be freely redistributed under the terms of the GNU
+general public license.:
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""
+
+import distutils.sysconfig
+import sys
+
+plib = distutils.sysconfig.get_python_lib()
+mod_path="%s/cobbler" % plib
+sys.path.insert(0, mod_path)
+
+from utils import _, get_random_mac
+import commands
+from cexceptions import *
+HELP_FORMAT = commands.HELP_FORMAT
+
+
+class ReportFunction(commands.CobblerFunction):
+
+ def help_me(self):
+ return HELP_FORMAT % ("cobbler report","[ARGS|--help]")
+
+ def command_name(self):
+ return "report"
+
+ def add_options(self, p, args):
+ p.add_option("--what", dest="what", default="all", help="distros/profiles/systems/repos")
+ p.add_option("--name", dest="name", help="report on just this object")
+ p.add_option("--type", dest="type", default="text", help="text/csv/trac/doku/mediawiki")
+ p.add_option("--fields", dest="fields", default="all" , help="what fields to display")
+
+
+ def run(self):
+ if self.options.what not in [ "all", "distros", "profiles", "systems", "repos" ]:
+ raise CX(_("Invalid value for --what"))
+ if self.options.type not in ["text", "csv", "trac", "doku", "mediawiki" ]:
+ raise CX(_("Invalid vavlue for --type"))
+
+ return self.api.report(report_what = self.options.what, report_name = self.options.name, \
+ report_type = self.options.type, report_fields = self.options.fields.replace(' ', '').split(','))
+
+########################################################
+# MODULE HOOKS
+
+def register():
+ """
+ The mandatory cobbler module registration hook.
+ """
+ return "cli"
+
+def cli_functions(api):
+ return [
+ ReportFunction(api)
+ ]
+
+
_______________________________________________
cobbler mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/cobbler