seitime-frappe/webnotes/model/sync.py
2013-03-05 14:12:33 +05:30

43 lines
No EOL
1.2 KiB
Python

from __future__ import unicode_literals
"""
Sync's doctype and docfields from txt files to database
perms will get synced only if none exist
"""
import webnotes
import os
import conf
from webnotes.modules import reload_doc
def sync_all(force=0):
sync_for("lib", force)
sync_for("app", force)
webnotes.clear_cache()
def sync_for(folder, force=0, sync_everything = False):
return walk_and_sync(os.path.join(os.path.dirname(os.path.abspath(conf.__file__)),
folder), force, sync_everything)
def walk_and_sync(start_path, force=0, sync_everything = False):
"""walk and sync all doctypes and pages"""
modules = []
document_type = ['doctype', 'page', 'report']
for path, folders, files in os.walk(start_path):
if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
for f in files:
if f.endswith(".txt"):
doc_name = f.split(".txt")[0]
if doc_name == os.path.basename(path):
module_name = path.split(os.sep)[-3]
doctype = path.split(os.sep)[-2]
name = path.split(os.sep)[-1]
if reload_doc(module_name, doctype, name, force):
print module_name + ' | ' + doctype + ' | ' + name
webnotes.conn.commit()
return modules