]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-objectstore-tool: Remove --pretty-format and use new --format options
authorDavid Zafman <dzafman@redhat.com>
Fri, 19 Dec 2014 21:47:32 +0000 (13:47 -0800)
committerDavid Zafman <dzafman@redhat.com>
Tue, 3 Mar 2015 19:20:59 +0000 (11:20 -0800)
Call new_formatter() with --format specified argument

Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit 22b71744bb0cb56434d5f6214ccea7d81f771860)

Conflicts:
src/tools/ceph_objectstore_tool.cc

src/test/ceph_objectstore_tool.py
src/tools/ceph_objectstore_tool.cc

index 07c0574b623522f46b306a59c9f757318607c040..b76f873ae8e7243b6ab750a3dde0a4173899d8d8 100755 (executable)
@@ -464,7 +464,7 @@ def main(argv):
     osd = OSDS[0]
 
     # retrieve all objects from all PGs
-    cmd = (CFSD_PREFIX + "--op list --pretty-format=false").format(osd=osd)
+    cmd = (CFSD_PREFIX + "--op list --format json").format(osd=osd)
     logging.debug(cmd);
     tmpfd = open(TMPFILE, "a")
     logging.debug(cmd)
@@ -478,7 +478,7 @@ def main(argv):
     (pgid, jsondict) = json.loads(JSONOBJ[0])[0]
 
     # retrieve all objects in a given PG
-    cmd = (CFSD_PREFIX + "--op list --pgid {pg} --pretty-format=false").format(osd=osd, pg=pgid)
+    cmd = (CFSD_PREFIX + "--op list --pgid {pg} --format json").format(osd=osd, pg=pgid)
     logging.debug(cmd);
     tmpfd = open(OTHERFILE, "a")
     logging.debug(cmd)
@@ -497,7 +497,7 @@ def main(argv):
         ERRORS += 1
 
     # retrieve all objects with a given name in a given PG
-    cmd = (CFSD_PREFIX + "--op list --pgid {pg} {object} --pretty-format=false").format(osd=osd, pg=pgid, object=jsondict['oid'])
+    cmd = (CFSD_PREFIX + "--op list --pgid {pg} {object} --format json").format(osd=osd, pg=pgid, object=jsondict['oid'])
     logging.debug(cmd);
     tmpfd = open(OTHERFILE, "a")
     logging.debug(cmd)
index e7b243877bea1872dc32ed39fa5a2bd1556ddbde..0fb9ebcfca1add4e4abf94730c92a23eb920492c 100644 (file)
@@ -2021,12 +2021,18 @@ void usage(po::options_description &desc)
     exit(1);
 }
 
+bool ends_with(const string& check, const string& ending)
+{
+    return check.size() >= ending.size() && check.rfind(ending) == (check.size() - ending.size());
+}
+
 int main(int argc, char **argv)
 {
   string dpath, jpath, pgidstr, op, file, object, objcmd, arg1, arg2, type, format;
   spg_t pgid;
   ghobject_t ghobj;
-  bool pretty_format, human_readable;
+  bool human_readable;
+  Formatter *formatter;
 
   po::options_description desc("Allowed options");
   desc.add_options()
@@ -2043,10 +2049,8 @@ int main(int argc, char **argv)
      "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects]")
     ("file", po::value<string>(&file),
      "path of file to export or import")
-    ("pretty-format", po::value<bool>(&pretty_format)->default_value(true),
-     "Make json or xml output more readable")
-    ("format", po::value<string>(&format)->default_value("json"),
-     "Output format which may be xml or json")
+    ("format", po::value<string>(&format)->default_value("json-pretty"),
+     "Output format which may be json, json-pretty, xml, xml-pretty")
     ("debug", "Enable diagnostic output to stderr")
     ("skip-journal-replay", "Disable journal replay")
     ("skip-mount-omap", "Disable mounting of omap")
@@ -2528,17 +2532,14 @@ int main(int argc, char **argv)
 
   // Special list handling.  Treating pretty_format as human readable,
   // with one object per line and not an enclosing array.
-  human_readable = pretty_format;
-  if (op == "list") {
-    pretty_format = false;
+  human_readable = ends_with(format, "-pretty");
+  if (op == "list" && human_readable) {
+    // Remove -pretty from end of format which we know is there
+    format = format.substr(0, format.size() - strlen("-pretty"));
   }
 
-  Formatter *formatter;
-  if (format == "xml") {
-    formatter = new XMLFormatter(pretty_format);
-  } else if (format == "json") {
-    formatter = new JSONFormatter(pretty_format);
-  } else {
+  formatter = new_formatter(format);
+  if (formatter == NULL) {
     cerr << "unrecognized format: " << format << std::endl;
     ret = 1;
     goto out;