-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path000_1st_run.py
83 lines (71 loc) · 3.06 KB
/
000_1st_run.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
# =============================================================================
# 1st RUN:
# - Run update_check if needed.
# - Import the S3 Framework Extensions
# - If needed, copy deployment templates to the live installation.
# =============================================================================
# Shortcut
appname = request.application
# -----------------------------------------------------------------------------
# Perform update checks - will happen in 1st_run or on those upgrades when new
# dependencies have been added.
#
from updatechk import UpdateCheck
update_check_needed = False
try:
if REQUIREMENTS_VERSION != UpdateCheck.REQUIREMENTS:
update_check_needed = True
except NameError:
update_check_needed = True
if update_check_needed:
# Run update checks
errors, warnings = UpdateCheck.check_all()
# Catch-all check for dependency errors.
# NB This does not satisfy the goal of calling out all the setup errors
# at once - it will die on the first fatal error encountered.
try:
import core as s3base
except Exception as e:
errors.append(e.message)
import sys
if warnings:
# Report (non-fatal) warnings.
prefix = "\n%s: " % T("WARNING")
sys.stderr.write("%s%s\n" % (prefix, prefix.join(warnings)))
if errors:
# Report errors and stop.
actionrequired = T("ACTION REQUIRED")
prefix = "\n%s: " % actionrequired
sys.stderr.write("%s%s\n" % (prefix, prefix.join(errors)))
htmlprefix = "\n<br /><b>%s</b>: " % actionrequired
html = "<errors>" + htmlprefix + htmlprefix.join(errors) + "\n</errors>"
raise HTTP(500, body=html)
# Create or update the canary file.
from s3dal import portalocker
canary = portalocker.LockedFile("applications/%s/models/0000_update_check.py" % appname, "w")
statement = "REQUIREMENTS_VERSION = %s" % UpdateCheck.REQUIREMENTS
canary.write(statement)
canary.close()
# -----------------------------------------------------------------------------
import os
from collections import OrderedDict
from functools import reduce
from gluon import current
from gluon.storage import Storage
# Keep all S3 framework-level elements stored in response.s3, so as to avoid
# polluting global namespace & to make it clear which part of the framework is
# being interacted with.
# Avoid using this where a method parameter could be used:
# http://en.wikipedia.org/wiki/Anti_pattern#Programming_anti-patterns
response.s3 = Storage()
s3 = response.s3
s3.gis = Storage() # Defined early for use by S3Config.
current.cache = cache
# Limit for filenames on filesystem:
# https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
# NB This takes effect during the file renaming algorithm - the length of uploaded filenames is unaffected
current.MAX_FILENAME_LENGTH = 255 # Defined early for use by S3Config.
# Import S3Config
import s3cfg
current.deployment_settings = deployment_settings = settings = s3cfg.S3Config()
# END =========================================================================