1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * $Id: checkout_web.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19 inherit "pikewww/local/base/client_base";
20 inherit "base/xml_data";
25 class checkout_web : public client_base,xml_data{
32 string compose_scalar(mixed s)
36 if ( s->get_object_class() & CLASS_USER ) {
38 name = s->get_identifier();
40 else if ( s->get_object_class() & CLASS_GROUP ) {
42 name = s->get_identifier();
44 else if ( s->get_object_class() & CLASS_MODULE ) {
46 name = s->get_identifier();
50 int oid = set_object(mVariables["filepath:tree"]);
51 name = send_command(COAL_COMMAND, ({ "object_to_filename", ({ s }) }));
54 return "<object><type>"+type+"</type><id>"+name+"</id></object>";
57 return ::compose_scalar(s);
60 void update_content(object obj, string path)
62 string content = send_command(COAL_COMMAND, ({ "get_content" }));
65 if ( !stringp(content) )
67 // create the directory structure !
69 array tokens = (path/"/");
70 dir = tokens[..sizeof(tokens)-2]*"/";
73 Stdio.File f = Stdio.File(path, "wct");
78 void xmlize_object(object obj, object xml)
81 xml->write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"+
83 obj->get_object_class()+"\">\n");
85 mapping attributes = send_command(COAL_COMMAND, ({ "query_attributes" }));
87 xml->write("<attributes>\n"+compose_struct(attributes)+ "</attributes>\n");
88 mapping acquire_map = send_command(COAL_COMMAND,
89 ({ "get_acquired_attributes" }));
90 xml->write("<attributes-acquire>\n"+
91 compose_struct(acquire_map) + "\n</attributes-acquire>\n");
92 mapping sanction = send_command(COAL_COMMAND, ({ "get_sanction" }));
93 mapping msanction = send_command(COAL_COMMAND, ({ "get_meta_sanction" }));
95 xml->write("<sanction>\n"+compose_struct(sanction) + "</sanction>\n");
96 xml->write("<sanction-meta>\n"+compose_struct(msanction)+
97 "</sanction-meta>\n");
98 xml->write("<acquire>\n"+
99 compose(send_command(COAL_COMMAND,({ "get_acquire" })))+
101 xml->write("</Object>\n");
104 void object_from_server(object obj)
106 if ( obj->get_object_class() & CLASS_USER )
109 set_object(mVariables["filepath:tree"]);
110 string path = send_command(COAL_COMMAND,
111 ({ "object_to_filename", ({ obj }) }));
113 string id = send_command(COAL_COMMAND, ({ "get_identifier" }));
116 if ( obj->get_object_class() & CLASS_DOCUMENT )
117 update_content(obj, path);
120 // create the directory structure !
122 array tokens = (path/"/");
123 dir = tokens[..sizeof(tokens)-2]*"/";
124 Stdio.mkdirhier(dir);
126 werror("Checking out " + path + "... ok\n");
127 // now write xml for the object
128 Stdio.File xml = Stdio.File(path + ".xml", "wct");
129 xmlize_object(obj, xml);
132 if ( obj->get_object_class() & CLASS_CONTAINER &&
133 !(obj->get_object_class() & CLASS_MODULE) )
135 array inv = send_command(COAL_COMMAND, ({ "get_inventory" }));
136 foreach(inv, object o)
137 object_from_server(o);
142 int run(int argc, array argv)
145 string server= "localhost";
146 string directory = "/";
150 for ( i = 1; i < sizeof(argv); i++ ) {
152 if ( sscanf(argv[i], "--%s=%s", cmd, arg) == 2 ) {
167 werror(sprintf("Unknown parameter %s\n", argv[i]));
172 if ( connect_server(server, port) ) {
173 string user = "root";
177 Stdio.Readline rl = Stdio.Readline();
178 string iuser = rl->read("User ? ["+ user + "]: ");
179 string ipw = rl->read("Password ? ["+pw+"]: ");
180 if ( iuser != "" ) user = iuser;
181 if ( ipw != "" ) pw = ipw;
184 login(user, pw, CLIENT_STATUS_CONNECTED);
185 // now get the inventory from the root room
187 object start = mVariables["rootroom"];
188 if ( directory != "/" ) {
189 int oid = set_object(mVariables["filepath:tree"]);
190 start = send_command(COAL_COMMAND, ({ "path_to_object",
191 ({ directory }), }));
193 else if ( stringp(file) ) {
194 start = send_cmd(mVariables["filepath:tree"], "path_to_object",file);
197 object_from_server(start);
198 if ( !stringp(file) ) {
200 array modules = send_command(COAL_COMMAND, ({ "get_module_objs" }));
201 foreach( modules, object module ) {
202 string p = "modules-xml/"+module->get_identifier();
203 Stdio.mkdirhier(dirname(p));
205 write("Module: " + p + "\n");
206 object mf = Stdio.File(p,"wct");
207 xmlize_object(module, mf);