[ostree] core: Split pull functionality into separate ostree-pull binary



commit e8865af09e4fa2f227f90d6688b41d8ef3bcb083
Author: Colin Walters <walters verbum org>
Date:   Wed Nov 30 09:21:14 2011 -0500

    core: Split pull functionality into separate ostree-pull binary
    
    This is to avoid everything depending on libsoup.

 Makefile-daemon.am                              |    4 +-
 Makefile-libostree.am                           |    4 +-
 Makefile-ostree.am                              |   19 +++-
 Makefile-otutil.am                              |    4 +-
 configure.ac                                    |   12 +-
 src/ostbuild/ostbuild-add-artifacts             |   49 +++++++
 src/ostbuild/ostbuild-chroot-compile-one        |   24 ++++
 src/ostbuild/ostbuild-chroot-compile-one-impl   |   53 +++++++
 src/ostree/main.c                               |  123 +-----------------
 src/ostree/{ot-builtin-pull.c => ostree-pull.c} |   22 +++-
 src/ostree/ot-builtins.h                        |   12 --
 src/ostree/ot-main.c                            |  166 +++++++++++++++++++++++
 src/ostree/ot-main.h                            |   37 +++++
 tests/t0010-pull.sh                             |    6 +-
 14 files changed, 378 insertions(+), 157 deletions(-)
---
diff --git a/Makefile-daemon.am b/Makefile-daemon.am
index c1d21e9..3b0a2b3 100644
--- a/Makefile-daemon.am
+++ b/Makefile-daemon.am
@@ -24,5 +24,5 @@ ostreed_SOURCES = src/daemon/ostreed.c \
 	src/daemon/ot-daemon.c \
 	$(NULL)
 
-ostreed_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/daemon -DLOCALEDIR=\"$(datadir)/locale\" $(OT_COREBIN_DEP_CFLAGS)
-ostreed_LDADD = libotutil.la libostree.la $(OT_COREBIN_DEP_LIBS)
+ostreed_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/daemon -DLOCALEDIR=\"$(datadir)/locale\" $(OT_DEP_GIO_UNIX_CFLAGS)
+ostreed_LDADD = libotutil.la libostree.la $(OT_DEP_GIO_UNIX_LIBS)
diff --git a/Makefile-libostree.am b/Makefile-libostree.am
index bf53cc3..98a2504 100644
--- a/Makefile-libostree.am
+++ b/Makefile-libostree.am
@@ -31,5 +31,5 @@ libostree_la_SOURCES = src/libostree/ostree.h \
 	src/libostree/ostree-checkout.c \
 	src/libostree/ostree-checkout.h \
 	$(NULL)
-libostree_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -DLOCALEDIR=\"$(datadir)/locale\" $(OT_COREBIN_DEP_CFLAGS)
-libostree_la_LIBADD = libotutil.la $(OT_COREBIN_DEP_LIBS)
+libostree_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -DLOCALEDIR=\"$(datadir)/locale\" $(OT_DEP_GIO_UNIX_CFLAGS)
+libostree_la_LIBADD = libotutil.la $(OT_DEP_GIO_UNIX_LIBS)
diff --git a/Makefile-ostree.am b/Makefile-ostree.am
index 20c0082..eb84940 100644
--- a/Makefile-ostree.am
+++ b/Makefile-ostree.am
@@ -35,10 +35,23 @@ ostree_SOURCES = src/ostree/main.c \
 	src/ostree/ot-builtin-remote.c \
 	src/ostree/ot-builtin-rev-parse.c \
 	src/ostree/ot-builtin-show.c \
+	src/ostree/ot-main.h \
+	src/ostree/ot-main.c \
 	$(NULL)
 
+ostree_bin_shared_cflags = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/ostree  -DLOCALEDIR=\"$(datadir)/locale\"
+ostree_bin_shared_ldadd = libotutil.la libostree.la
+
+ostree_CFLAGS = $(ostree_bin_shared_cflags) $(OT_DEP_GIO_UNIX_CFLAGS)
+ostree_LDADD = $(ostree_bin_shared_ldadd) $(OT_DEP_GIO_UNIX_LIBS)
+
 if USE_LIBSOUP_GNOME
-ostree_SOURCES += src/ostree/ot-builtin-pull.c
+bin_PROGRAMS += ostree-pull
+ostree_pull_SOURCES = src/ostree/ot-main.h \
+	src/ostree/ot-main.c \
+	src/ostree/ostree-pull.c
+
+ostree_pull_CFLAGS = $(ostree_bin_shared_cflags) $(OT_DEP_SOUP_CFLAGS)
+ostree_pull_LDADD = $(ostree_bin_shared_ldadd) $(OT_DEP_SOUP_LIBS)
 endif
-ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/ostree  -DLOCALEDIR=\"$(datadir)/locale\" $(OT_COREBIN_DEP_CFLAGS)
-ostree_LDADD = libotutil.la libostree.la $(OT_COREBIN_DEP_LIBS)
+
diff --git a/Makefile-otutil.am b/Makefile-otutil.am
index 6d4e492..dbe1763 100644
--- a/Makefile-otutil.am
+++ b/Makefile-otutil.am
@@ -32,5 +32,5 @@ libotutil_la_SOURCES = \
 	src/libotutil/ot-glib-compat.h \
 	src/libotutil/otutil.h \
 	$(NULL)
-libotutil_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -DLOCALEDIR=\"$(datadir)/locale\" $(GIO_UNIX_CFLAGS)
-libotutil_la_LIBADD = $(GIO_UNIX_LIBS)
+libotutil_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -DLOCALEDIR=\"$(datadir)/locale\" $(OT_DEP_GIO_UNIX_CFLAGS)
+libotutil_la_LIBADD = $(OT_DEP_GIO_UNIX_LIBS)
diff --git a/configure.ac b/configure.ac
index 839abea..36a3cc3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,23 +25,23 @@ LT_INIT([disable-static])
 PKG_PROG_PKG_CONFIG
 
 GIO_DEPENDENCY="gio-unix-2.0 >= 2.28"
-PKG_CHECK_MODULES(GIO_UNIX, [gio-unix-2.0 >= 2.28])
+SOUP_DEPENDENCY="libsoup-gnome-2.4 >= 2.34.0"
+
+PKG_CHECK_MODULES(OT_DEP_GIO_UNIX, $GIO_DEPENDENCY)
+
 AC_ARG_WITH(soup-gnome,
 	    AS_HELP_STRING([--without-soup-gnome], [Do not use libsoup-gnome (implies no pull support)]),
 	    :, with_soup_gnome=maybe)
 if test x$with_soup_gnome != xno; then
-    PKG_CHECK_MODULES(OT_COREBIN_DEP, [libsoup-gnome-2.4 >= 2.34.0 $GIO_DEPENDENCY], have_soup_gnome=yes, have_soup_gnome=no)
+    PKG_CHECK_EXISTS($SOUP_DEPENDENCY, have_soup_gnome=yes, have_soup_gnome=no)
     if test x$have_soup_gnome = xno && test x$with_soup_gnome != xmaybe; then
        AC_MSG_ERROR([libsoup-gnome is enabled but could not be found])
     fi
     if test x$have_soup_gnome = xyes; then
-        AC_DEFINE([HAVE_LIBSOUP_GNOME], [1], [Define if we have libsoup-gnome])
+	PKG_CHECK_MODULES(OT_DEP_SOUP, $SOUP_DEPENDENCY)
     else
-	PKG_CHECK_MODULES(OT_COREBIN_DEP, [$GIO_DEPENDENCY])
 	with_soup_gnome=no
     fi		
-else
-    PKG_CHECK_MODULES(OT_COREBIN_DEP, [$GIO_DEPENDENCY])
 fi
 
 AM_CONDITIONAL(USE_LIBSOUP_GNOME, test $with_soup_gnome != no)
diff --git a/src/ostbuild/ostbuild-add-artifacts b/src/ostbuild/ostbuild-add-artifacts
new file mode 100644
index 0000000..f5069ec
--- /dev/null
+++ b/src/ostbuild/ostbuild-add-artifacts
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+
+# Copyright (C) 2011 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# ostbuild-compile-one-make wraps systems that implement the GNOME build API:
+# http://people.gnome.org/~walters/docs/build-api.txt
+
+import os,sys,subprocess,tempfile,re
+
+i=1
+repo=sys.argv[i]
+
+artifact_re = re.compile(r'^artifact-([^,]+)-([^,]+),(.+).tar.gz$')
+
+if os.getuid() != 0:
+    print "This program must be run as root."
+    sys.exit(1)
+
+def call_ostree_sync(*args):
+    subprocess.check_call(['ostree', '--repo=' + repo] + args)
+
+for arg in sys.argv[1:]:
+    match = artifact_re.match(arg)
+    if match is None
+        print "Invalid artifact name: %s" % (arg, )
+        sys.exit(1)
+    arch = match.group(1)
+    name = match.group(2)
+    version = match.group(3)
+    
+    branch_name = 'artifact-%s-%s' % (arch, name)
+
+    call_ostree_sync('commit', '-b', branch_name, '-s', version, 
+                     
diff --git a/src/ostbuild/ostbuild-chroot-compile-one b/src/ostbuild/ostbuild-chroot-compile-one
new file mode 100644
index 0000000..2d9a8a8
--- /dev/null
+++ b/src/ostbuild/ostbuild-chroot-compile-one
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# Copyright (C) 2011 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# Author: Colin Walters <walters verbum org>
+
+
+bn=$(basename $(pwd))
+ostbuild-nice-and-log-output "compile-${bn}.log" ostbuild-chroot-compile-one-impl "$@"
diff --git a/src/ostbuild/ostbuild-chroot-compile-one-impl b/src/ostbuild/ostbuild-chroot-compile-one-impl
new file mode 100644
index 0000000..9c253ea
--- /dev/null
+++ b/src/ostbuild/ostbuild-chroot-compile-one-impl
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+
+# Copyright (C) 2011 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,re,subprocess
+
+i=1
+repo=sys.argv[i]
+i += 1
+chroot_path=sys.argv[i]
+i += 1
+args=sys.argv[i:]
+
+if os.getuid() != 0:
+    print "This program must be run as root."
+    sys.exit(1)
+
+rootdir=os.path.join(chroot_path, 'root')
+
+if not os.path.isdir(rootdir):
+    print "Not a directory: %s" % (rootdir, )
+    sys.exit(1)
+
+builddir = os.path.join(rootdir, 'ostree-build')
+if not os.path.isdir(builddir):
+    os.mkdir(builddir)
+
+
+def run_in_chroot(args):
+    proc_path=os.path.join(chroot_path, 'proc')
+    subprocess.check_call(['mount', '-t', 'proc', 'proc', proc_path])
+
+    try:
+        subprocess.check_call(['chroot', chroot_path])
+    finally:
+        subprocess.call(['umount', proc_path])
+
+run_in_chroot(args)
diff --git a/src/ostree/main.c b/src/ostree/main.c
index 5aea6c0..301a512 100644
--- a/src/ostree/main.c
+++ b/src/ostree/main.c
@@ -26,6 +26,7 @@
 
 #include <string.h>
 
+#include "ot-main.h"
 #include "ot-builtins.h"
 
 static OstreeBuiltin builtins[] = {
@@ -38,9 +39,6 @@ static OstreeBuiltin builtins[] = {
   { "local-clone", ostree_builtin_local_clone, 0 },
   { "log", ostree_builtin_log, 0 },
   { "ls", ostree_builtin_ls, 0 },
-#ifdef HAVE_LIBSOUP_GNOME
-  { "pull", ostree_builtin_pull, 0 },
-#endif
   { "fsck", ostree_builtin_fsck, 0 },
   { "remote", ostree_builtin_remote, 0 },
   { "rev-parse", ostree_builtin_rev_parse, 0 },
@@ -50,126 +48,9 @@ static OstreeBuiltin builtins[] = {
   { NULL }
 };
 
-static int
-usage (char **argv, gboolean is_error)
-{
-  OstreeBuiltin *builtin = builtins;
-  void (*print_func) (const gchar *format, ...);
-
-  if (is_error)
-    print_func = g_printerr;
-  else
-    print_func = g_print;
-
-  print_func ("usage: %s --repo=PATH COMMAND [options]\n",
-              argv[0]);
-  print_func ("Builtin commands:\n");
-
-  while (builtin->name)
-    {
-      print_func ("  %s\n", builtin->name);
-      builtin++;
-    }
-  return (is_error ? 1 : 0);
-}
-
-static void
-prep_builtin_argv (const char *builtin,
-                   int argc,
-                   char **argv,
-                   int *out_argc,
-                   char ***out_argv)
-{
-  int i;
-  char **cmd_argv;
-  
-  cmd_argv = g_new0 (char *, argc + 2);
-  
-  cmd_argv[0] = (char*)builtin;
-  for (i = 0; i < argc; i++)
-    cmd_argv[i+1] = argv[i];
-  cmd_argv[i+1] = NULL;
-  *out_argc = argc+1;
-  *out_argv = cmd_argv;
-}
-
-static void
-set_error_print_usage (GError **error, const char *msg, char **argv)
-{
-  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg);
-  usage (argv, TRUE);
-}
-
 int
 main (int    argc,
       char **argv)
 {
-  OstreeBuiltin *builtin;
-  GError *error = NULL;
-  int cmd_argc;
-  char **cmd_argv = NULL;
-  gboolean am_root;
-  gboolean have_repo_arg;
-  const char *cmd = NULL;
-  const char *repo = NULL;
-
-  g_type_init ();
-
-  g_set_prgname (argv[0]);
-
-  if (argc < 2)
-    return usage (argv, 1);
-
-  am_root = getuid () == 0;
-  have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
-
-  if (!have_repo_arg && am_root)
-    repo = "/sysroot/ostree/repo";
-  else if (have_repo_arg)
-    repo = argv[1] + strlen ("--repo=");
-  else
-    repo = NULL;
-
-  if (!have_repo_arg)
-    cmd = argv[1];
-  else
-    cmd = argv[2];
-
-  builtin = builtins;
-  while (builtin->name)
-    {
-      if (strcmp (cmd, builtin->name) == 0)
-        break;
-      builtin++;
-    }
-
-  if (!builtin)
-    {
-      set_error_print_usage (&error, "Unknown command", argv);
-      goto out;
-    }
-
-  if (repo == NULL && !(builtin->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
-    {
-      set_error_print_usage (&error, "Command requires a --repo argument", argv);
-      goto out;
-    }
-  
-  if (!have_repo_arg)
-    prep_builtin_argv (cmd, argc-2, argv+2, &cmd_argc, &cmd_argv);
-  else
-    prep_builtin_argv (cmd, argc-3, argv+3, &cmd_argc, &cmd_argv);
-
-  if (!builtin->fn (cmd_argc, cmd_argv, repo, &error))
-    goto out;
-
- out:
-  g_free (cmd_argv);
-  if (error)
-    {
-      g_printerr ("%s\n", error->message);
-      g_clear_error (&error);
-      return 1;
-    }
-  return 0;
+  return ostree_main (argc, argv, builtins);
 }
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ostree-pull.c
similarity index 98%
rename from src/ostree/ot-builtin-pull.c
rename to src/ostree/ostree-pull.c
index 012c094..3c9cecf 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ostree-pull.c
@@ -22,13 +22,11 @@
 
 #include "config.h"
 
-#include "ot-builtins.h"
-#include "ostree.h"
-
-#include <glib/gi18n.h>
-
 #include <libsoup/soup-gnome.h>
 
+#include "ostree.h"
+#include "ot-main.h"
+
 gboolean verbose;
 
 static GOptionEntry options[] = {
@@ -275,7 +273,7 @@ store_commit_recurse (OstreeRepo   *repo,
   return ret;
 }
                       
-gboolean
+static gboolean
 ostree_builtin_pull (int argc, char **argv, const char *repo_path, GError **error)
 {
   GOptionContext *context;
@@ -393,3 +391,15 @@ ostree_builtin_pull (int argc, char **argv, const char *repo_path, GError **erro
   g_clear_object (&soup);
   return ret;
 }
+
+static OstreeBuiltin builtins[] = {
+  { "pull", ostree_builtin_pull, 0 },
+  { NULL }
+};
+
+int
+main (int    argc,
+      char **argv)
+{
+  return ostree_main (argc, argv, builtins);
+}
diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h
index afef91f..cfacaad 100644
--- a/src/ostree/ot-builtins.h
+++ b/src/ostree/ot-builtins.h
@@ -27,17 +27,6 @@
 
 G_BEGIN_DECLS
 
-typedef enum {
-  OSTREE_BUILTIN_FLAG_NONE = 0,
-  OSTREE_BUILTIN_FLAG_NO_REPO = 1,
-} OstreeBuiltinFlags;
-
-typedef struct {
-  const char *name;
-  gboolean (*fn) (int argc, char **argv, const char *repo, GError **error);
-  int flags; /* OstreeBuiltinFlags */
-} OstreeBuiltin;
-
 gboolean ostree_builtin_checkout (int argc, char **argv, const char *repo, GError **error);
 gboolean ostree_builtin_checksum (int argc, char **argv, const char *repo, GError **error);
 gboolean ostree_builtin_commit (int argc, char **argv, const char *repo, GError **error);
@@ -47,7 +36,6 @@ gboolean ostree_builtin_init (int argc, char **argv, const char *repo, GError **
 gboolean ostree_builtin_local_clone (int argc, char **argv, const char *repo, GError **error);
 gboolean ostree_builtin_log (int argc, char **argv, const char *repo, GError **error);
 gboolean ostree_builtin_ls (int argc, char **argv, const char *repo, GError **error);
-gboolean ostree_builtin_pull (int argc, char **argv, const char *repo, GError **error);
 gboolean ostree_builtin_run_triggers (int argc, char **argv, const char *repo, GError **error);
 gboolean ostree_builtin_fsck (int argc, char **argv, const char *repo, GError **error);
 gboolean ostree_builtin_show (int argc, char **argv, const char *repo, GError **error);
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c
new file mode 100644
index 0000000..e951252
--- /dev/null
+++ b/src/ostree/ot-main.c
@@ -0,0 +1,166 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters verbum org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters verbum org>
+ */
+
+#include "config.h"
+
+#include <gio/gio.h>
+
+#include <string.h>
+
+#include "ot-main.h"
+
+static int
+usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
+{
+  OstreeBuiltin *builtin = builtins;
+  void (*print_func) (const gchar *format, ...);
+
+  if (is_error)
+    print_func = g_printerr;
+  else
+    print_func = g_print;
+
+  print_func ("usage: %s --repo=PATH COMMAND [options]\n",
+              argv[0]);
+  print_func ("Builtin commands:\n");
+
+  while (builtin->name)
+    {
+      print_func ("  %s\n", builtin->name);
+      builtin++;
+    }
+  return (is_error ? 1 : 0);
+}
+
+static void
+prep_builtin_argv (const char *builtin,
+                   int argc,
+                   char **argv,
+                   int *out_argc,
+                   char ***out_argv)
+{
+  int i;
+  char **cmd_argv;
+  
+  cmd_argv = g_new0 (char *, argc + 2);
+  
+  cmd_argv[0] = (char*)builtin;
+  for (i = 0; i < argc; i++)
+    cmd_argv[i+1] = argv[i];
+  cmd_argv[i+1] = NULL;
+  *out_argc = argc+1;
+  *out_argv = cmd_argv;
+}
+
+static void
+set_error_print_usage (GError **error, OstreeBuiltin *builtins, const char *msg, char **argv)
+{
+  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg);
+  usage (argv, builtins, TRUE);
+}
+
+int
+ostree_main (int    argc,
+             char **argv,
+             OstreeBuiltin  *builtins)
+{
+  OstreeBuiltin *builtin;
+  GError *error = NULL;
+  int cmd_argc;
+  char **cmd_argv = NULL;
+  gboolean am_root;
+  gboolean have_repo_arg;
+  const char *cmd = NULL;
+  const char *repo = NULL;
+  int arg_off;
+
+  g_type_init ();
+
+  g_set_prgname (argv[0]);
+
+  if (argc < 2)
+    return usage (argv, builtins, 1);
+
+  am_root = getuid () == 0;
+  have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
+
+  if (!have_repo_arg && am_root)
+    repo = "/sysroot/ostree/repo";
+  else if (have_repo_arg)
+    repo = argv[1] + strlen ("--repo=");
+  else
+    repo = NULL;
+
+  cmd = strchr (argv[0], '-');
+  if (cmd)
+    {
+      cmd += 1;
+      arg_off = 1;
+      if (have_repo_arg)
+        arg_off += 1;
+    }
+  else if (!have_repo_arg)
+    {
+      arg_off = 2;
+      cmd = argv[arg_off-1];
+    }
+  else
+    {
+      arg_off = 3;
+      cmd = argv[arg_off-1];
+    }
+
+  builtin = builtins;
+  while (builtin->name)
+    {
+      if (strcmp (cmd, builtin->name) == 0)
+        break;
+      builtin++;
+    }
+
+  if (!builtin->name)
+    {
+      set_error_print_usage (&error, builtins, "Unknown command", argv);
+      goto out;
+    }
+
+  if (repo == NULL && !(builtin->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
+    {
+      set_error_print_usage (&error, builtins, "Command requires a --repo argument", argv);
+      goto out;
+    }
+  
+  prep_builtin_argv (cmd, argc-arg_off, argv+arg_off, &cmd_argc, &cmd_argv);
+
+  if (!builtin->fn (cmd_argc, cmd_argv, repo, &error))
+    goto out;
+
+ out:
+  g_free (cmd_argv);
+  if (error)
+    {
+      g_printerr ("%s\n", error->message);
+      g_clear_error (&error);
+      return 1;
+    }
+  return 0;
+}
diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h
new file mode 100644
index 0000000..2fb54cd
--- /dev/null
+++ b/src/ostree/ot-main.h
@@ -0,0 +1,37 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters verbum org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters verbum org>
+ */
+
+#include <gio/gio.h>
+
+typedef enum {
+  OSTREE_BUILTIN_FLAG_NONE = 0,
+  OSTREE_BUILTIN_FLAG_NO_REPO = 1,
+} OstreeBuiltinFlags;
+
+typedef struct {
+  const char *name;
+  gboolean (*fn) (int argc, char **argv, const char *repo, GError **error);
+  int flags; /* OstreeBuiltinFlags */
+} OstreeBuiltin;
+
+int ostree_main (int    argc, char **argv, OstreeBuiltin  *builtins);
+
diff --git a/tests/t0010-pull.sh b/tests/t0010-pull.sh
index 6bc7ff6..53c85b2 100755
--- a/tests/t0010-pull.sh
+++ b/tests/t0010-pull.sh
@@ -26,9 +26,9 @@ echo '1..2'
 setup_fake_remote_repo1
 cd ${test_tmpdir}
 mkdir repo
-$OSTREE init
-$OSTREE remote add origin $(cat httpd-address)/ostree/gnomerepo
-$OSTREE pull origin main
+ostree --repo=repo init
+ostree --repo=repo remote add origin $(cat httpd-address)/ostree/gnomerepo
+ostree-pull --repo=repo origin main
 echo "ok pull"
 
 cd ${test_tmpdir}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]