From owner-p4-projects@FreeBSD.ORG Sun Aug 5 02:12:11 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id F39DA16A41F; Sun, 5 Aug 2007 02:12:10 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C8BBB16A417 for ; Sun, 5 Aug 2007 02:12:10 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CA7BC13C469 for ; Sun, 5 Aug 2007 02:12:10 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l752CAXg009539 for ; Sun, 5 Aug 2007 02:12:10 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l752CAgR009533 for perforce@freebsd.org; Sun, 5 Aug 2007 02:12:10 GMT (envelope-from andrew@freebsd.org) Date: Sun, 5 Aug 2007 02:12:10 GMT Message-Id: <200708050212.l752CAgR009533@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 124702 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Aug 2007 02:12:11 -0000 http://perforce.freebsd.org/chv.cgi?CH=124702 Change 124702 by andrew@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'''