PERFORCE change 124702 for review
Andrew Turner
andrew at FreeBSD.org
Sat Aug 4 19:12:11 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=124702
Change 124702 by andrew at andrew_hermies on 2007/08/05 02:12:07
Add facund_read_directory_patchlevel to read a directory/patch object
Add facund_run_update to execute freebsd-update. It dosn't run the command yet but echo's the command it would have run.
Update the install_patches handler to read the arguments and call facund_run_update
Start the rollback_patches handler
Fix the frontend to send the correct data to install_patches
Affected files ...
.. //depot/projects/soc2007/andrew-update/backend/facund-be.c#20 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/computer.py#8 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/controller.py#5 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/gui/main_window.py#9 edit
Differences ...
==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#20 (text+ko) ====
@@ -564,6 +564,7 @@
/*
* Takes a either facund array of string objects or a single string
* object and returns a C array of C strings of the objects
+ * TODO: Rename as it is a generic function to extract data from an array
*/
static const char **
facund_get_dir_list(const struct facund_object *obj)
@@ -791,31 +792,134 @@
}
static struct facund_response *
+facund_read_directory_patchlevel(const char *id,
+ const struct facund_object *obj, const char **base_dir,
+ const char ***patches)
+{
+ const struct facund_object *cur, *dir, *patch;
+
+ if (facund_object_get_type(obj) != FACUND_ARRAY) {
+ return facund_response_new(id, 1, "Bad data sent", NULL);
+ }
+
+ cur = facund_object_get_array_item(obj, 0);
+ if (cur == NULL) {
+ facund_response_new(id, 1, "Bad data sent", NULL);
+ }
+ if (facund_object_get_type(cur) == FACUND_STRING) {
+ /* Get the data for this directory */
+ dir = cur;
+ patch = facund_object_get_array_item(obj, 1);
+ if (patch == NULL) {
+ return facund_response_new(id, 1, "Bad data sent",NULL);
+ }
+
+ /* Get the directory and patch level */
+ *base_dir = facund_object_get_string(dir);
+ *patches = facund_get_dir_list(patch);
+
+ if (*base_dir == NULL || *patches == NULL) {
+ return facund_response_new(id, 1, "Malloc failed",NULL);
+ }
+ } else {
+ return facund_response_new(id, 1, "Bad data sent", NULL);
+ }
+
+ return NULL;
+}
+
+static int
+facund_run_update(const char *command, const char *basedir)
+{
+ char *cmd, *arg;
+ int ret;
+
+ assert(command != NULL);
+#define FREEBSD_COMMAND "/usr/sbin/freebsd-update"
+ arg = NULL;
+ if (basedir != NULL) {
+ asprintf(&arg, "-b %s", basedir);
+ if (arg == NULL)
+ return -1;
+ }
+ asprintf(&cmd, "echo " FREEBSD_COMMAND " %s %s",
+ (arg == NULL ? "" : arg), command);
+ //asprintf(&command, FREEBSD_COMMAND " install");
+
+ free(arg);
+ if (cmd == NULL) {
+ return -1;
+ }
+
+ ret = system(cmd);
+ free(cmd);
+
+ return ret;
+}
+
+static struct facund_response *
facund_call_install_patches(const char *id, struct facund_object *obj)
{
- const struct facund_object *cur;
+ const char *base_dir, **patches;
+ struct facund_response *ret;
unsigned int pos;
+ int failed;
if (obj == NULL) {
/* TODO: Don't use magic numbers */
return facund_response_new(id, 1, "No data sent", NULL);
}
- if (facund_object_get_type(obj) != FACUND_ARRAY) {
- return facund_response_new(id, 1, "Bad data sent", NULL);
+ base_dir = NULL;
+ patches = NULL;
+ ret = facund_read_directory_patchlevel(id, obj, &base_dir, &patches);
+ if (ret != NULL)
+ return ret;
+
+ /* Check the directory is being watched */
+ for (pos = 0; pos < watched_db_count; pos++) {
+ if (strcmp(watched_db[pos].db_base, base_dir) == 0) {
+ break;
+ }
+ }
+ if (pos == watched_db_count) {
+ return facund_response_new(id, 1, "Incorrect directory", NULL);
+ }
+
+ /* In the all case we will install all avaliable patches */
+ failed = 0;
+ if (strcmp(patches[0], "base") == 0) {
+ if (facund_run_update("install", base_dir) != 0) {
+ failed = 1;
+ }
+ } else {
+ return facund_response_new(id, 1, "Unsupported patch", NULL);
}
- for (pos = 0; (cur = facund_object_get_array_item(obj, pos)) != NULL;
- pos++) {
- facund_object_print(__DECONST(struct facund_object *, cur));
+ if (failed != 0) {
+ return facund_response_new(id, 1,
+ "Some updates failed to install", NULL);
}
- printf("STUB: %s\n", __func__);
- return NULL;
+ return facund_response_new(id, 0, "All updates installed", NULL);
}
static struct facund_response *
-facund_call_rollback_patches(const char *id __unused, struct facund_object *obj __unused)
+facund_call_rollback_patches(const char *id, struct facund_object *obj)
{
+ const char *base_dir, **patches;
+ struct facund_response *ret;
+
+ if (obj == NULL) {
+ /* TODO: Don't use magic numbers */
+ return facund_response_new(id, 1, "No data sent", NULL);
+ }
+
+ base_dir = NULL;
+ patches = NULL;
+ ret = facund_read_directory_patchlevel(id, obj, &base_dir, &patches);
+ if (ret != NULL)
+ return ret;
+
printf("STUB: %s\n", __func__);
return NULL;
}
==== //depot/projects/soc2007/andrew-update/frontend/facund/computer.py#8 (text+ko) ====
@@ -103,14 +103,7 @@
return arg
def installUpdates(self, isInstall, installTypes):
- args = facund.Array()
- if isinstance(installTypes, types.TupleType):
- args.append(self.buildInstallArg(installTypes[0],
- installTypes[1]))
- elif isinstance(installTypes, types.ListType):
- for item in installTypes:
- args.append(self.buildInstallArg(item[0],
- item[1]))
+ args = self.buildInstallArg(installTypes[0], installTypes[1])
if isInstall:
callType = "install_patches"
==== //depot/projects/soc2007/andrew-update/frontend/facund/controller.py#5 (text+ko) ====
@@ -31,6 +31,7 @@
self.__computersModel = computersModel
self.__view.setComputerTreeModel(self.__computersModel)
self.__currentComputer = None
+ self.__currentDirectory = None
self.__updateModel = updateModel
self.__view.setUpdateViewModel(self.__updateModel)
@@ -38,6 +39,8 @@
self.__view.run()
def onComputerTreeSelect(self, position):
+ self.__currentDirectory = None
+
computer = self.__computersModel.getComputer(position[0])
self.__view.setConnected(computer.getConnectionStatus())
if computer.getConnectionStatus() is not True:
@@ -49,6 +52,7 @@
return
dir = computer.getDirs()[position[1]]
+ self.__currentDirectory = dir
if len(position) == 2:
return
@@ -76,6 +80,9 @@
def getCurrentComputer(self):
return self.__currentComputer
+ def getCurrentDirectory(self):
+ return self.__currentDirectory
+
def installUpdates(self, updates):
computer = self.getCurrentComputer()
computer.installUpdates(True, updates)
==== //depot/projects/soc2007/andrew-update/frontend/facund/gui/main_window.py#9 (text+ko) ====
@@ -110,10 +110,11 @@
self.setInstallable(False, False)
def onInstallClick(self, widget):
- self.__controller.installUpdates(('base', 'all'))
+ dir = self.__controller.getCurrentDirectory()
+ self.__controller.installUpdates((dir.getName(), 'base'))
def onRemoveClick(self, widget):
- self.__controller.installUpdates(('base', 'all'))
+ self.__controller.installUpdates((dir.getName(), 'all'))
def onSelectComputer(self, widget):
'''Signal handler for when the selected item is changed'''
More information about the p4-projects
mailing list