core: Split pull functionality into separate ostree-pull binary
This is to avoid everything depending on libsoup.
This commit is contained in:
1 parent
3ac841d931
commit
e8865af09e
14 files changed
+378
-157
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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 "$@"
|
||||
@@ -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)
|
||||
+2
-121
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user