Browse Source

ffho-site-generate: fix module gluon/site_generate.lua

Karsten Böddeker 8 years ago
parent
commit
6b20fd5cdb
1 changed files with 16 additions and 10 deletions
  1. 16 10
      ffho/ffho-site-generate/files/usr/lib/lua/gluon/site_generate.lua

+ 16 - 10
ffho/ffho-site-generate/files/usr/lib/lua/gluon/site_generate.lua

@@ -1,9 +1,11 @@
 #!/usr/bin/lua
 
-module('gluon.site_generate')
-
+local tool = {}
 local uci = require('luci.model.uci').cursor()
 local json =  require 'luci.json'
+local sites_json = '/lib/gluon/site-select/sites.json'
+
+module('gluon.site_generate', package.seeall)
 
 function get_config(file)
   local f = io.open(file)
@@ -15,14 +17,8 @@ function get_config(file)
   return nil
 end
 
-function force_site_code(site_code)
-  uci:set('currentsite', 'current', 'name', site_code)
-  uci:save('currentsite')
-  uci:commit('currentsite')
-end
-
 function validate_site(site_code)
-  local sites = get_config('/lib/gluon/site-select/sites.json')
+  local sites = get_config(sites_json)
   for _, site in pairs(sites) do
     if site.site_code == site_code then
       return true
@@ -31,8 +27,18 @@ function validate_site(site_code)
   return false
 end
 
+function force_site_code(site_code)
+  if site_code then
+    uci:set('currentsite', 'current', 'name', site_code)
+    uci:save('currentsite')
+    uci:commit('currentsite')
+    return true
+  end
+  return false
+end
+
 function set_site_code(site_code)
-  if site_code and is_site_valid(site_code) then
+  if site_code and validate_site(site_code) then
     uci:set('currentsite', 'current', 'name', site_code)
     uci:save('currentsite')
     uci:commit('currentsite')