~ubuntu-branches/ubuntu/wily/steam/wily

« back to all changes in this revision

Viewing changes to tools/applauncher

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/lib/steam/steam
2
 
 
3
 
/* Copyright (C) 2000-2004  Thomas Bopp, Thorsten Hampel, Ludger Merkens
4
 
 * Copyright (C) 2003-2004  Martin Baehr
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
 
 * 
20
 
 * $Id: applauncher,v 1.1.1.1 2006/03/27 12:40:19 exodusd Exp $
21
 
 */
22
 
 
23
 
constant cvs_version="$Id: applauncher,v 1.1.1.1 2006/03/27 12:40:19 exodusd Exp $";
24
 
 
25
 
 
26
 
#include </usr/lib/steam/server/include/classes.h>
27
 
 
28
 
inherit "gtklogin";
29
 
inherit "/usr/lib/steam/config";
30
 
inherit "/usr/lib/steam/server/base/xml_parser";
31
 
 
32
 
// #include "/usr/lib/steam/server/include/attributes.h"
33
 
 
34
 
#define USER_WORKROOM      614
35
 
#define GROUP_WORKROOM      800
36
 
#define CLASS_EXIT          (1<<7)
37
 
 
38
 
static object oInstall;
39
 
 
40
 
object find_object(int id)
41
 
{
42
 
    if ( objectp(oInstall) )
43
 
        oInstall->find_object(id);
44
 
    return 0;
45
 
}
46
 
 
47
 
object get_xsl(object conn, object xslxml)
48
 
{
49
 
  string xslname=
50
 
    xslxml->get_identifier()[..sizeof(xslxml->get_identifier())-9]+
51
 
    ".xsl";
52
 
 
53
 
  object xsl;
54
 
 
55
 
  object env=conn->send_cmd(xslxml, "get_environment");
56
 
  array inv=conn->send_cmd(env, "get_inventory_by_class", CLASS_DOCXSL);
57
 
  map(inv, lambda(object obj)
58
 
           {
59
 
             if(obj->get_identifier()==xslname)
60
 
               xsl=obj;
61
 
           });
62
 
  return xsl;
63
 
}
64
 
 
65
 
void upload(object conn, object editor, string file, int last_mtime, object obj, object xslobj)
66
 
{
67
 
  int new_mtime=file_stat(file)->mtime;
68
 
  if(new_mtime > last_mtime)
69
 
  {
70
 
    last_mtime=new_mtime;
71
 
    mixed result=conn->send_cmd(obj, "set_content", Stdio.read_file(file));
72
 
    string message=sprintf("%s: upload: %O", file, result);
73
 
    Stdio.append_file("/tmp/applauncher.log", message+"\n");
74
 
    Process.create_process(({ "screen", "-X", "wall", message }));
75
 
    if(xslobj)
76
 
    {
77
 
      result=conn->send_cmd(xslobj, "load_xml_structure");
78
 
      message=sprintf("%s: load xml struct: %O", file, result);
79
 
      Stdio.append_file("/tmp/applauncher.log", message+"\n");
80
 
      Process.create_process(({ "screen", "-X", "wall", message }));
81
 
    }
82
 
  }
83
 
  if(!editor->status())
84
 
    call_out(upload, 1, conn, editor, file, new_mtime, obj, xslobj);
85
 
}
86
 
 
87
 
 
88
 
array edit(object conn, object obj)
89
 
{
90
 
  string dir="/tmp/"+(MIME.encode_base64(Crypto.randomness.pike_random()->read(10), 1)-("/"))+System.getpid();
91
 
  string filename=obj->get_object_id()+"-"+obj->get_identifier();
92
 
 
93
 
  mkdir(dir, 0700);
94
 
  string content=conn->send_cmd(obj, "get_content");
95
 
  //werror("%O\n", content);
96
 
  Stdio.write_file(dir+"/"+filename, content, 0600);
97
 
  
98
 
  //array command=({ "screen", "-X", "screen", "vi", dir+"/"+filename });
99
 
  array command=({ "vim", "--servername", "VIM", "--remote-wait", dir+"/"+filename });
100
 
  object editor=Process.create_process(command,
101
 
                                     ([ "cwd":dir, "env":getenv() ]));
102
 
  return ({ editor, dir+"/"+filename });
103
 
104
 
 
105
 
int main(int argc, array argv)
106
 
{
107
 
  if(!sizeof(argv))
108
 
  {
109
 
    write("need a sal file\n");
110
 
    return 0;
111
 
  }
112
 
 
113
 
  mapping sal=init_file(argv[1]);
114
 
  werror("%O\n", sal);
115
 
  if(getenv()->DISPLAY)
116
 
    return gtkmain(argv, sal);
117
 
  else
118
 
    return consolemain(argv, sal);
119
 
}
120
 
 
121
 
int consolemain(array (string) argv, mapping sal)
122
 
{
123
 
 
124
 
  Stdio.Readline readln = Stdio.Readline(Stdio.stdin);
125
 
  write("%s@%s:%s\n", sal->userName, sal->hostname, sal->fileName);
126
 
  readln->set_echo( 0 );
127
 
  string pw=readln->read("enter passwd: ");
128
 
  readln->set_echo( 1 );
129
 
  return main2(sal->userName, pw, sal);
130
 
}
131
 
 
132
 
int gtkmain(array (string) argv, mapping sal)
133
 
{
134
 
  GTK.setup_gtk(argv);
135
 
  get_login(sprintf("%s: %s", sal->hostname, sal->fileName), sal->userName, main2, sal);
136
 
  return -1;
137
 
}
138
 
 
139
 
int main2(string username, string passwd, mapping sal)
140
 
{
141
 
  object conn=init_steam(username, passwd, sal);
142
 
  if(!conn)
143
 
    return 0;
144
 
 
145
 
  object obj = conn->find_object((int)sal->objectID);
146
 
 
147
 
  object xslobj;
148
 
  if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml")
149
 
    xslobj=get_xsl(conn, obj);
150
 
 
151
 
  object editor;
152
 
  string file;
153
 
  [editor, file]=edit(conn, obj);
154
 
  mixed status;
155
 
  //while(!(status=editor->status()))
156
 
 
157
 
  if(!editor->status())
158
 
    call_out(upload, 1, conn, editor, file, file_stat(file)->mtime, obj, xslobj);
159
 
 
160
 
//  signal(signum("SIGINT"), prompt);
161
 
  return -1;
162
 
}
163
 
 
164
 
mapping init_file(string file)
165
 
{
166
 
 
167
 
  mapping sal = ([]);
168
 
  foreach(Stdio.read_file(file)/"\n"-({""}), string option)
169
 
  {
170
 
    sal[(option/" = ")[0]]=(option/" = ")[1];
171
 
  }
172
 
  return sal;
173
 
}
174
 
 
175
 
object init_steam(string username, string passwd, mapping sal)
176
 
{
177
 
  object conn;
178
 
 
179
 
  string server_path = "/usr/lib/steam";
180
 
  string config_path = "/etc/steam/";
181
 
 
182
 
  master()->add_include_path(server_path+"/server/include");
183
 
  master()->add_program_path(server_path+"/server/");
184
 
  master()->add_program_path(server_path+"/conf/");
185
 
  master()->add_program_path(server_path+"/server/net/coal/");
186
 
  add_constant("find_object", find_object);
187
 
  read_configs(config_path+"/config.txt");
188
 
 
189
 
  conn = ((program)"connection.pike")();
190
 
 
191
 
  mixed error=
192
 
    catch
193
 
    { 
194
 
      conn->start(sal->hostname, (int)sal->usedPort, username, passwd); 
195
 
    };
196
 
  if(error)
197
 
  {
198
 
    werror("Login failed: %s\n", error[0]);
199
 
    return 0;
200
 
  }
201
 
  return conn;
202
 
}
203