Skip to content

Commit

Permalink
Adds a new main configuration file key: "config". It holds information
Browse files Browse the repository at this point in the history
about the configuration file itself. It will allow cherokee-admin to
migrate configuration automatically whenever the configuration file
format changes in a new server version. Target: the user should not
even know the configuration file format can evolve between versions.


git-svn-id: svn://cherokee-project.com/cherokee/trunk@3782 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Nov 5, 2009
1 parent 67eb21c commit f8705da
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions admin/Makefile.am
Expand Up @@ -104,6 +104,7 @@ ModuleTargetIp.py \
ModuleEvhost.py \
ModuleRrd.py \
config.py \
config_version.py \
pyscgi.py \
validations.py \
CherokeeManagement.py \
Expand Down
2 changes: 1 addition & 1 deletion admin/config.py
Expand Up @@ -260,7 +260,7 @@ def pop (self, key):
# Serialization
def serialize (self):
def sorter(x,y):
order = ['server', 'vserver', 'source', 'icons', 'mime']
order = ['config', 'server', 'vserver', 'source', 'icons', 'mime']
a = x.split('!')
b = y.split('!')
try:
Expand Down
47 changes: 47 additions & 0 deletions admin/config_version.py
@@ -0,0 +1,47 @@
import configured

def config_version_get_current():
ver = configured.VERSION.split ('b')[0]
v1,v2,v3 = ver.split (".")

major = int(v1)
minor = int(v2)
micro = int(v3)

return "%03d%03d%03d" %(major, minor, micro)


def config_version_cfg_is_up_to_date (cfg):
# Cherokee's version
ver_cherokee = config_version_get_current()

# Configuration file version
ver_config = cfg.get_val("config!version")
if not ver_config:
cfg["config!version"] = ver_cherokee
return True

# Compare both of them
if int(ver_config) > int(ver_cherokee):
print "WARNING!! Running a new configuration file (version %s)" % (ver_config)
print "with anolder version of Cherokee (version %s)" % (ver_cherokee)
return True

elif int(ver_config) == int(ver_cherokee):
return True

else:
return False


def config_version_update_cfg (cfg):
# Update only when it's outdated
if config_version_cfg_is_up_to_date (cfg):
return

# Update..
ver_config_s = cfg.get_val("config!version")
ver_config_i = int(ver_config_s)

print "Updating configuration.."
None
5 changes: 5 additions & 0 deletions admin/server.py
Expand Up @@ -30,6 +30,7 @@
from PageAjaxUpdate import *
from PageInfoSource import *
from CherokeeManagement import *
from config_version import *

# Constants
#
Expand Down Expand Up @@ -234,6 +235,10 @@ def main():
global cfg
cfg = Config(cfg_file)

# Update the configuration file if needed
config_version_update_cfg (cfg)

# Let the user know what is going on
version = VERSION
pid = os.getpid()

Expand Down

0 comments on commit f8705da

Please sign in to comment.