updated sync, install to load install_docs
This commit is contained in:
parent
1e829dcfb5
commit
20f55e8e70
9 changed files with 90 additions and 207 deletions
|
|
@ -24,9 +24,10 @@ install_docs = [
|
|||
{'doctype':'Module Def', 'name': 'Core', 'module_name':'Core'},
|
||||
|
||||
# roles
|
||||
{'doctype':'Role', 'role_name': 'Administrator'},
|
||||
{'doctype':'Role', 'role_name': 'All'},
|
||||
{'doctype':'Role', 'role_name': 'Guest'},
|
||||
{'doctype':'Role', 'role_name': 'Administrator', 'name': 'Administrator'},
|
||||
{'doctype':'Role', 'role_name': 'All', 'name': 'All'},
|
||||
{'doctype':'Role', 'role_name': 'System Manager', 'name': 'System Manager'},
|
||||
{'doctype':'Role', 'role_name': 'Guest', 'name': 'Guest'},
|
||||
|
||||
# profiles
|
||||
{'doctype':'Profile', 'name':'Administrator', 'first_name':'Administrator',
|
||||
|
|
|
|||
|
|
@ -3,16 +3,15 @@
|
|||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-03-27 14:35:36',
|
||||
'creation': '2012-04-14 17:04:27',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-03-27 14:35:36',
|
||||
'modified': '2012-04-15 08:53:32',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all DocType
|
||||
{
|
||||
'_last_update': u'1311674341',
|
||||
'allow_copy': 0,
|
||||
'allow_email': 0,
|
||||
'allow_print': 0,
|
||||
|
|
@ -31,7 +30,7 @@
|
|||
'section_style': u'Simple',
|
||||
'server_code_error': u' ',
|
||||
'show_in_menu': 0,
|
||||
'version': 12
|
||||
'version': 13
|
||||
},
|
||||
|
||||
# These values are common for all DocField
|
||||
|
|
@ -126,29 +125,6 @@
|
|||
'reqd': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'version',
|
||||
'fieldtype': u'Int',
|
||||
'label': u'Version',
|
||||
'oldfieldname': u'version',
|
||||
'oldfieldtype': u'Int'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'name',
|
||||
'fieldtype': u'Data',
|
||||
'hidden': 1,
|
||||
'label': u'Name',
|
||||
'oldfieldname': u'name',
|
||||
'oldfieldtype': u'Data',
|
||||
'reqd': 0,
|
||||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
|
|
@ -162,19 +138,6 @@
|
|||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'owner',
|
||||
'fieldtype': u'Link',
|
||||
'hidden': 1,
|
||||
'label': u'Owner',
|
||||
'oldfieldname': u'owner',
|
||||
'oldfieldtype': u'Link',
|
||||
'reqd': 0,
|
||||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
|
|
@ -199,26 +162,6 @@
|
|||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'colour': u'White:FFF',
|
||||
'description': u'Subject will appear as a string in the docbrowser: eg.\n[%(status)s] %(description)s\nIf it is a JS Expression, use "eval:"',
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'subject',
|
||||
'fieldtype': u'Data',
|
||||
'label': u'Subject'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'colour': u'White:FFF',
|
||||
'description': u'Fields separated by (,) that will be set as tags',
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'tag_fields',
|
||||
'fieldtype': u'Data',
|
||||
'label': u'tag_fields'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
|
|
@ -287,16 +230,6 @@
|
|||
'oldfieldtype': u'Check'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'show_in_menu',
|
||||
'fieldtype': u'Check',
|
||||
'label': u'Show In Pages',
|
||||
'oldfieldname': u'show_in_menu',
|
||||
'oldfieldtype': u'Check'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
|
|
@ -331,30 +264,6 @@
|
|||
'oldfieldtype': u'Check'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'use_template',
|
||||
'fieldtype': u'Check',
|
||||
'label': u'Use Template',
|
||||
'oldfieldname': u'use_template',
|
||||
'oldfieldtype': u'Check'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'print_outline',
|
||||
'fieldtype': u'Select',
|
||||
'hidden': 0,
|
||||
'label': u'Print Outline',
|
||||
'oldfieldname': u'print_outline',
|
||||
'oldfieldtype': u'Select',
|
||||
'options': u'\nNo\nYes',
|
||||
'reqd': 0,
|
||||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
|
|
@ -462,45 +371,6 @@
|
|||
'oldfieldtype': u'Check'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'section_style',
|
||||
'fieldtype': u'Select',
|
||||
'label': u'Section Style',
|
||||
'oldfieldname': u'section_style',
|
||||
'oldfieldtype': u'Select',
|
||||
'options': u'Simple\nPaged\nTabbed\nTray'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'colour',
|
||||
'fieldtype': u'Select',
|
||||
'hidden': 0,
|
||||
'label': u'Colour',
|
||||
'oldfieldname': u'colour',
|
||||
'oldfieldtype': u'Select',
|
||||
'options': u'White:FFF\nLight Blue:DEF\nLight Green:DFE\nPeach:FEF3C5\nPink:FEF2EA\nLilac:FDEAFE\nAqua:EAFEFA',
|
||||
'reqd': 0,
|
||||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'smallicon',
|
||||
'fieldtype': u'Select',
|
||||
'hidden': 0,
|
||||
'label': u'Small Icon',
|
||||
'oldfieldname': u'smallicon',
|
||||
'oldfieldtype': u'Select',
|
||||
'options': u'\naccept.png\nadd.png\napplication.png\nbell.png\nbox.png\ncalendar.png\ncalculator.png\ncancel.png\ncart.png\ncd.png\nchart_bar.png\nclock.png\ncoins.png\ncomputer.png\ncontroller.png\ndisk.png\nemail.png\nerror.png\nfolder.png\ngroup.png\nhouse.png\nimages.png\nlock_open.png\nlock.png\nlorry.png\nmagnifier.png\nmap.png\nmoney.png\nnew.png\npage.png\nprinter.png\nreport.png\nserver.png\nshield.png\ntable.png\nuser.png',
|
||||
'reqd': 0,
|
||||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
|
|
@ -616,4 +486,4 @@
|
|||
'search_index': 0,
|
||||
'width': u'300px'
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
@ -45,7 +45,8 @@ class DocType:
|
|||
return webnotes.conn.sql("select name, fieldtype, label, fieldname from tabDocField where parent=%s", self.doc.doc_type, as_dict = 1)
|
||||
|
||||
def get_defaults(self):
|
||||
if self.doc.doc_type == self.doc.doc_name:
|
||||
return webnotes.conn.sql("select * from `tabDocType` where name=%s", self.doc.doc_name, as_dict = 1)[0]
|
||||
if not self.doc.field_name:
|
||||
return webnotes.conn.sql("select * from `tabDocType` where name=%s", self.doc.doc_type, as_dict = 1)[0]
|
||||
else:
|
||||
return webnotes.conn.sql("select * from `tabDocField` where name=%s", self.doc.doc_name, as_dict = 1)[0]
|
||||
return webnotes.conn.sql("select * from `tabDocField` where fieldname=%s and parent=%s",
|
||||
(self.doc.field_name, self.doc.doc_type), as_dict = 1)[0]
|
||||
|
|
@ -3,16 +3,15 @@
|
|||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-03-27 14:35:38',
|
||||
'creation': '2012-04-14 17:04:30',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-03-27 19:07:11',
|
||||
'modified': '2012-04-15 08:57:32',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all DocType
|
||||
{
|
||||
'_last_update': u'1308120990',
|
||||
'allow_print': 0,
|
||||
'allow_trash': 1,
|
||||
'autoname': u"eval:doc.select_doctype + '-' + (doc.select_item or doc.field_name) + '-' + doc.property",
|
||||
|
|
@ -26,7 +25,7 @@
|
|||
'show_in_menu': 0,
|
||||
'subject': u'<b>%(property)s</b> property of %(doc_type)s %(doc_name)s',
|
||||
'tag_fields': u'property',
|
||||
'version': 39
|
||||
'version': 1
|
||||
},
|
||||
|
||||
# These values are common for all DocField
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ class Installer:
|
|||
from webnotes.model.sync import sync_core_doctypes
|
||||
print "Building tables from core module..."
|
||||
sync_core_doctypes()
|
||||
self.install_core()
|
||||
|
||||
# framework cleanups
|
||||
self.framework_cleanups(target)
|
||||
|
|
@ -97,6 +96,7 @@ class Installer:
|
|||
self.create_scheduler_log()
|
||||
self.create_doctype_cache()
|
||||
self.create_session_cache()
|
||||
self.create_cache_item()
|
||||
|
||||
# set the basic passwords
|
||||
webnotes.conn.begin()
|
||||
|
|
@ -144,25 +144,14 @@ class Installer:
|
|||
country VARCHAR(120),
|
||||
cache LONGTEXT)""")
|
||||
|
||||
def install_core(self):
|
||||
"""create install docs"""
|
||||
def create_cache_item(self):
|
||||
import webnotes
|
||||
from core import install_docs
|
||||
from webnotes.model.doc import Document
|
||||
from webnotes.modules import reload_doc
|
||||
|
||||
webnotes.conn.begin()
|
||||
|
||||
for data in install_docs:
|
||||
d = Document(data['doctype'])
|
||||
d.fields.update(data)
|
||||
d.save()
|
||||
print 'Created %(doctype)s %(name)s' % d.fields
|
||||
|
||||
# login page
|
||||
reload_doc('core', 'page', 'login_page')
|
||||
print 'Loaded Login Page'
|
||||
|
||||
webnotes.conn.commit()
|
||||
self.dbman.drop_table('__CacheItem')
|
||||
webnotes.conn.sql("""create table __CacheItem(
|
||||
`key` VARCHAR(180) NOT NULL PRIMARY KEY,
|
||||
`value` TEXT,
|
||||
`expires_on` TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,28 +12,44 @@ def sync_all(force=0):
|
|||
def sync_core_doctypes(force=0):
|
||||
import os
|
||||
import core
|
||||
module_name = 'core'
|
||||
core_path = os.path.abspath(os.sep.join(core.__file__.split(os.sep)[:-1]
|
||||
+ ['doctype']))
|
||||
for path, folders, files in os.walk(core_path):
|
||||
for f in files:
|
||||
if f.endswith(".txt"):
|
||||
sync(module_name, f[:-4], force)
|
||||
# doctypes
|
||||
walk_and_sync(os.path.abspath(os.path.dirname(core.__file__)), force)
|
||||
|
||||
def sync_modules(force=0):
|
||||
import os
|
||||
import conf
|
||||
for path, folders, files in os.walk(conf.modules_path):
|
||||
if path == conf.modules_path:
|
||||
modules_list = folders
|
||||
walk_and_sync(conf.modules_path, force)
|
||||
|
||||
def walk_and_sync(start_path, force=0):
|
||||
"""walk and sync all doctypes and pages"""
|
||||
import os
|
||||
from webnotes.modules import reload_doc
|
||||
|
||||
modules = []
|
||||
|
||||
for path, folders, files in os.walk(start_path):
|
||||
for f in files:
|
||||
if f.endswith(".txt"):
|
||||
rel_path = os.path.relpath(path, conf.modules_path)
|
||||
path_tuple = rel_path.split(os.sep)
|
||||
if (len(path_tuple)==3 and path_tuple[0] in modules_list and
|
||||
path_tuple[1] == 'doctype'):
|
||||
#print (path_tuple[0], f[:-4])
|
||||
sync(path_tuple[0], f[:-4], force)
|
||||
# great grand-parent folder is module_name
|
||||
module_name = path.split(os.sep)[-3]
|
||||
if not module_name in modules:
|
||||
modules.append(module_name)
|
||||
|
||||
# grand parent folder is doctype
|
||||
doctype = path.split(os.sep)[-2]
|
||||
|
||||
# parent folder is the name
|
||||
name = path.split(os.sep)[-1]
|
||||
|
||||
if doctype == 'doctype':
|
||||
sync(module_name, name, force)
|
||||
elif doctype == 'page':
|
||||
reload_doc(module_name, 'page', name)
|
||||
print module_name + ' | ' + doctype + ' | ' + name
|
||||
|
||||
# load install docs
|
||||
load_install_docs(modules)
|
||||
|
||||
|
||||
|
||||
# docname in small letters with underscores
|
||||
def sync(module_name, docname, force=0):
|
||||
|
|
@ -43,14 +59,16 @@ def sync(module_name, docname, force=0):
|
|||
modified = doclist[0]['modified']
|
||||
if not doclist:
|
||||
raise Exception('DocList could not be evaluated')
|
||||
if modified == str(webnotes.conn.get_value('DocType', doclist[0].get('name'), 'modified')) and not force:
|
||||
if modified == str(webnotes.conn.get_value(doclist[0].get('doctype'),
|
||||
doclist[0].get('name'), 'modified')) and not force:
|
||||
return
|
||||
webnotes.conn.begin()
|
||||
|
||||
delete_doctype_docfields(doclist)
|
||||
save_doctype_docfields(doclist)
|
||||
save_perms_if_none_exist(doclist)
|
||||
webnotes.conn.sql('UPDATE `tabDocType` SET modified=%s WHERE name=%s',
|
||||
webnotes.conn.sql("""UPDATE `tab{doctype}`
|
||||
SET modified=%s WHERE name=%s""".format(doctype=doclist[0]['doctype']),
|
||||
(modified, doclist[0]['name']))
|
||||
|
||||
webnotes.conn.commit()
|
||||
|
|
@ -106,6 +124,24 @@ def save_perms_if_none_exist(doclist):
|
|||
if d.get('doctype') != 'DocPerm': continue
|
||||
Document(fielddata=d).save(1, check_links=0, ignore_fields=1)
|
||||
|
||||
def load_install_docs(modules):
|
||||
import os
|
||||
from webnotes.model.doc import Document
|
||||
|
||||
if isinstance(modules, basestring): modules = [modules]
|
||||
|
||||
for module_name in modules:
|
||||
module = __import__(module_name)
|
||||
if hasattr(module, 'install_docs'):
|
||||
webnotes.conn.begin()
|
||||
for data in module.install_docs:
|
||||
if data.get('name'):
|
||||
if not webnotes.conn.exists(data['doctype'], data.get('name')):
|
||||
d = Document(data['doctype'])
|
||||
d.fields.update(data)
|
||||
d.save()
|
||||
print 'Created %(doctype)s %(name)s' % d.fields
|
||||
webnotes.conn.commit()
|
||||
|
||||
import unittest
|
||||
class TestSync(unittest.TestCase):
|
||||
|
|
|
|||
|
|
@ -47,18 +47,13 @@ class CacheItem:
|
|||
|
||||
def set(self, value, interval=6000):
|
||||
"""set a new value, with interval"""
|
||||
try:
|
||||
self.clear()
|
||||
webnotes.conn.sql("""INSERT INTO
|
||||
__CacheItem (`key`, `value`, expires_on)
|
||||
VALUES
|
||||
(%s, %s, addtime(now(), sec_to_time(%s)))
|
||||
""", (self.key, str(value), interval))
|
||||
except Exception, e:
|
||||
if e.args[0]==1146:
|
||||
setup()
|
||||
self.set(value, interval)
|
||||
else: raise e
|
||||
self.clear()
|
||||
webnotes.conn.sql("""INSERT INTO
|
||||
__CacheItem (`key`, `value`, expires_on)
|
||||
VALUES
|
||||
(%s, %s, addtime(now(), sec_to_time(%s)))
|
||||
""", (self.key, str(value), interval))
|
||||
|
||||
|
||||
def clear(self):
|
||||
"""clear the item"""
|
||||
|
|
@ -67,13 +62,3 @@ class CacheItem:
|
|||
except Exception, e:
|
||||
if e.args[0]!=1146: # ignore table not existing
|
||||
raise e
|
||||
|
||||
def setup():
|
||||
webnotes.conn.commit()
|
||||
webnotes.conn.sql("""create table __CacheItem(
|
||||
`key` VARCHAR(180) NOT NULL PRIMARY KEY,
|
||||
`value` TEXT,
|
||||
`expires_on` TIMESTAMP
|
||||
)""")
|
||||
webnotes.conn.begin()
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ import webnotes
|
|||
def getsearchfields():
|
||||
sf = webnotes.conn.sql("""\
|
||||
SELECT value FROM `tabProperty Setter`
|
||||
WHERE doc_type=%s AND doc_name=%s AND property='search_fields'""", \
|
||||
(webnotes.form.getvalue("doctype"), webnotes.form.getvalue("doctype")))
|
||||
WHERE doc_type=%s AND property='search_fields'""", \
|
||||
(webnotes.form.getvalue("doctype")))
|
||||
if not (sf and len(sf)>0 and sf[0][0]):
|
||||
sf = webnotes.conn.sql("select search_fields from tabDocType where name=%s", webnotes.form.getvalue("doctype"))
|
||||
sf = sf and sf[0][0] or ''
|
||||
|
|
|
|||
2
wnf.py
2
wnf.py
|
|
@ -158,6 +158,8 @@ def run():
|
|||
# connect
|
||||
if options.db_name is not None:
|
||||
webnotes.connect(options.db_name)
|
||||
else:
|
||||
webnotes.connect(conf.db_name)
|
||||
|
||||
# build
|
||||
if options.build:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue