-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.py
377 lines (342 loc) · 13.8 KB
/
Command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2015 Mag. Christian Tanzer All rights reserved
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
# #*** <License> ************************************************************#
# This module is part of the program FFW.
#
# This module is licensed under the terms of the BSD 3-Clause License
# <http://www.c-tanzer.at/license/bsd_3c.html>.
# #*** </License> ***********************************************************#
#
#++
# Name
# Command
#
# Purpose
# Application and command handler for FFW
#
# Revision Dates
# 26-Mar-2012 (CT) Creation
# 14-May-2012 (CT) Change `-config` to auto-split, `default_db_name` to `ffw`
# 17-May-2012 (CT) Derive from `GTW.Werkzeug.Command` instead of `.Scaffold`,
# rename `Scaffold` to `Command`
# 30-May-2012 (CT) Fix `opts`
# 31-May-2012 (CT) Add `"../../.ffw.config"` to `_config_defaults`
# 2-Jun-2012 (CT) Replace `config_defaults` by `Config`
# 3-Jun-2012 (CT) Factor `_Base_Command_`
# 11-Jun-2012 (CT) Correct `Auth` and `L10N`
# 29-Jul-2012 (CT) Change to use `GTW.RST.TOP` instead of `GTW.NAV`
# 11-Aug-2012 (CT) Add `GTW.RST.TOP.MOM.Doc` documentation
# 13-Sep-2012 (CT) Remove `GTW.AFS.MOM.Spec.setup_defaults`
# 2-Oct-2012 (CT) Add REST API to `create_top`
# 5-Oct-2012 (CT) Pass `json_indent` to `GTW.RST.MOM.Scope`
# 10-Oct-2012 (CT) Add `NET` to `PNS_Aliases`
# 7-Dec-2012 (CT) Add `User_Node`
# 17-Dec-2012 (CT) Add `User_Net_Device`, ...
# 17-Dec-2012 (CT) Wrap `User_...` resources in `TOP.Dir`
# 15-Apr-2013 (CT) Add `exclude_robots` to resource `/api`
# 3-May-2013 (CT) Rename `login_required` to `auth_required`
# 4-May-2013 (CT) Add `auth_required` to `RST.MOM.Scope`
# 20-May-2013 (CT) Import `_FFW.RST_Api_addons`
# 13-Jun-2013 (CT) Remove `PNS_Aliases`
# 23-Aug-2013 (CT) Add `-auth_required`, use it in `create_top`
# 7-Oct-2013 (CT) Add `RST_addons.User_Antenna`
# 1-Apr-2014 (CT) Add resource for `GTW.RST.MOM.Doc.App_Type`
# 14-Apr-2014 (CT) Add `pid="RESTful"` to resource `/api`
# 14-Apr-2014 (CT) Add `RST_addons.User_Net_Interface`
# 18-Apr-2014 (CT) Add `RST_addons.User_Person*`
# 5-May-2014 (CT) Replace `landing_page` bei `/about`; add `/impressum`
# 12-Jun-2014 (CT) DRY startup message
# 29-Aug-2014 (CT) Remove import for `AFS`
# 5-Sep-2014 (CT) Add `RST_addons.User_Net_Interface_in_IP_Network`
# 13-Sep-2014 (CT) Add `RST_addons.User_Wireless_Interface_uses_Antenna`
# 26-Sep-2014 (CT) Add Alias for `/Doc/FFW`
# 29-Jul-2015 (CT) Adapt to name change of PAP.Phone attributes
# ««revision-date»»···
#--
from _CNDB import CNDB
from _FFW import FFW
from _GTW import GTW
from _JNJ import JNJ
from _MOM import MOM
from _ReST import ReST
from _TFL import TFL
from _Base_Command_ import _Base_Command_
from _CNDB._GTW import RST_addons
import _CNDB.Command
from _MOM.Product_Version import Product_Version, IV_Number
from _TFL import sos
from _TFL.I18N import _, _T, _Tn
from _TFL.Regexp import Re_Replacer
from _TFL._Meta.Once_Property import Once_Property
from _TFL._Meta.Property import Class_Property
import _TFL.CAO
GTW.OMP.PAP.Phone.change_attribute_default ("cc", "+43")
FFW.Version = Product_Version \
( productid = u"FFW node data base"
, productnick = u"FFW"
, productdesc = u"Web application for FFW node data base"
, date = "29-Jul-2012 "
, major = 0
, minor = 2
, patchlevel = 0
, author = u"Christian Tanzer, Ralf Schlatterbeck"
, copyright_start = 2012
, db_version = IV_Number
( "db_version"
, ("FFW", )
, ("FFW", )
, program_version = 1
, comp_min = 0
, db_extension = ".ffw"
)
)
impressum_contents = """
Name des Vereins
----------------
:email:`FunkFeuer Wien <[email protected]>` — Verein zur Förderung freier
Netze
`ZVR-Zahl`_: 814804682
Vereinssitz
-----------
1010 Wien, Gonzagagasse 11/25
.. _`ZVR-Zahl`: http://zvr.bmi.gv.at/Start
"""
impressum_contents_add = """
Copyright
---------
Die Inhalte dieser Seiten sind urheberrechtlich geschützt.
Haftungsausschluss
------------------
Jede Haftung für unmittelbare, mittelbare oder sonstige Schäden, unabhängig
von deren Ursachen, die aus der Benutzung oder Nichtverfügbarkeit der Daten
und Informationen dieser Homepage erwachsen, wird, soweit rechtlich zulässig,
ausgeschlossen.
"""
class Command (_Base_Command_, CNDB.Command) :
"""Manage database, run server or WSGI app."""
ANS = FFW
SALT = b"fa89356c-0af1-4644-80d7-92702e4fd524"
_default_db_name = "ffw"
_defaults = dict \
( copyright_start = 2012
)
@Once_Property
def src_dir (self) :
import rst_top
return rst_top.src_dir
# end def src_dir
@Once_Property
def web_src_root (self) :
import rst_top
return rst_top.web_src_root
# end def web_src_root
def create_rst (self, cmd, ** kw) :
return GTW.RST.Root \
( language = "en"
, entries =
[ GTW.RST.MOM.Scope (name = "v1")
, GTW.RST.MOM.Doc.App_Type (name = "v1-doc")
]
, ** kw
)
# end def create_rst
def create_top (self, cmd, ** kw) :
import _GTW._RST._TOP.import_TOP
import rst_top
RST = GTW.RST
TOP = RST.TOP
auth_r \
= TOP.MOM.Admin.E_Type._auth_required \
= TOP.MOM.Admin.Group._auth_required \
= cmd.auth_required
result = rst_top.create (cmd, ** kw)
result.add_entries \
( RST_addons.Dashboard
( auth_required = auth_r
, pid = "DB"
)
, TOP.Page_ReST
( name = "about"
, short_title = "Über Funkfeuer"
, title = "Über Funkfeuer"
, page_template_name = "html/dashboard/about.jnj"
)
, TOP.Dir
( name = "My-Funkfeuer"
, short_title = "My Funkfeuer"
, auth_required = auth_r
, permission = RST_addons.Login_has_Person
, entries =
[ RST_addons.User_Node
( name = "node"
)
, RST_addons.User_Net_Device
( name = "device"
, short_title = _T ("Device")
)
, RST_addons.User_Net_Interface
( name = "interface"
, short_title = _T ("Interface")
)
, RST_addons.User_Net_Interface_in_IP_Network
( name = "interface_in_ip_network"
, short_title = _T ("Interface in Network")
, hidden = True
)
, RST_addons.User_Wired_Interface
( name = "wired-interface"
, short_title = _T ("Wired_Interface")
)
, RST_addons.User_Wireless_Interface
( name = "wireless-interface"
, short_title = _T ("Wireless_Interface")
)
, RST_addons.User_Wireless_Interface_uses_Antenna
( name = "wireless-interface-uses-antenna"
, hidden = True
)
, RST_addons.User_Antenna
( name = "antenna"
, short_title = _T ("Antenna")
)
, RST_addons.User_Person
( name = "person"
, hidden = True
)
, RST_addons.User_Person_has_Address
( name = "has_address"
, hidden = True
)
, RST_addons.User_Person_has_Account
( name = "has_account"
, hidden = True
)
, RST_addons.User_Person_has_Email
( name = "has_email"
, hidden = True
)
, RST_addons.User_Person_has_IM_Handle
( name = "has_im_handle"
, hidden = True
)
, RST_addons.User_Person_has_Phone
( name = "has_phone"
, hidden = True
)
]
)
, TOP.MOM.Doc.App_Type
( name = "Doc"
, short_title = _ ("Model doc")
, title = _ ("Documentation for FFW object model")
)
, TOP.Alias \
( name = "/Doc/FFW"
, target = "/Doc/CNDB"
, hidden = True
)
, TOP.MOM.Admin.Site
( name = "Admin"
, short_title = "Admin"
, pid = "Admin"
, title = _ ("Administration of FFW node database")
, head_line = _ ("Administration of FFW node database")
, auth_required = auth_r
, entries =
[ self.nav_admin_group
( "FFW"
, _ ("Administration of node database")
, "CNDB"
, permission = RST.In_Group ("FFW-admin")
if auth_r else None
)
, self.nav_admin_group
( "PAP"
, _ ("Administration of persons/addresses...")
, "GTW.OMP.PAP"
, permission = RST.In_Group ("FFW-admin")
if auth_r else None
)
, self.nav_admin_group
( _ ("Users")
, _ ("Administration of user accounts and groups")
, "GTW.OMP.Auth"
, permission = RST.Is_Superuser ()
)
]
)
, GTW.RST.MOM.Scope
( name = "api"
, auth_required = auth_r
, exclude_robots = True
, json_indent = 2
, pid = "RESTful"
)
, TOP.Page_ReST
( name = "impressum"
, short_title = "Impressum"
, title = "Impressum"
, page_template_name = "html/dashboard/static.jnj"
, src_contents = impressum_contents
)
, GTW.RST.MOM.Doc.App_Type
( name = "api-doc"
, hidden = True
)
, TOP.Auth
( name = _ ("Auth")
, pid = "Auth"
, short_title = _ (u"Authorization and Account handling")
, hidden = True
)
, TOP.L10N
( name = _ ("L10N")
, short_title =
_ (u"Choice of language used for localization")
, country_map = dict (de = "AT")
)
, TOP.Robot_Excluder ()
)
if cmd.debug :
result.add_entries \
( TOP.Console
( name = "Console"
, short_title = _ ("Console")
, title = _ ("Interactive Python interpreter")
, permission = RST.Is_Superuser ()
)
, RST.Raiser
( name = "RAISE"
, hidden = True
)
)
if result.DEBUG :
scope = result.__dict__.get ("scope", "*not yet created*")
print ("RST.TOP root created,", scope)
return result
# end def create_nav
def fixtures (self, scope) :
import fixtures
return fixtures.create (scope)
# end def fixtures
def _create_templateer (self, cmd, ** kw) :
if cmd.UTP.use_templateer :
import rst_top
return self.__super._create_templateer \
( cmd
, load_path = rst_top.template_dirs
, Media_Parameters = rst_top.Media_Parameters
, ** kw
)
# end def _create_templateer
# end class Scaffold
command = Command ()
opts = command.opts + command ["run_server"].opts
def scope (cmd = None) :
args = (cmd.db_url, cmd.db_name, cmd.create) if cmd else ()
return command.scope (* args)
# end def scope
if __name__ == "__main__" :
command ()
### __END__ Command