本文整理汇总了Python中webnotes.modules.get_module_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_module_path函数的具体用法?Python get_module_path怎么用?Python get_module_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_module_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy_file
def copy_file(self, path, old_name, extn):
import os
from webnotes.modules import get_module_path, scrub
if os.path.exists(os.path.join(path, old_name + extn)):
os.system('cp %s %s' % (os.path.join(path, old_name + extn), \
os.path.join(get_module_path(self.doc.module), 'search_criteria', scrub(self.doc.name), scrub(self.doc.name) + extn)))
示例2: get_code
def get_code(module, dt, dn, extn, is_static=None, fieldname=None):
from webnotes.modules import scrub, get_module_path
import os, webnotes
# get module (if required)
if not module:
module = webnotes.conn.sql("select module from `tab%s` where name=%s" % (dt,'%s'),dn)[0][0]
# no module, quit
if not module:
return ''
# file names
if scrub(dt) in ('page','doctype','search_criteria'):
dt, dn = scrub(dt), scrub(dn)
# get file name
fname = dn + '.' + extn
if is_static:
fname = dn + '_static.' + extn
# code
code = ''
try:
file = open(os.path.join(get_module_path(scrub(module)), dt, dn, fname), 'r')
code = file.read()
file.close()
except IOError, e:
# no file, try from db
if fieldname:
code = webnotes.conn.get_value(dt, dn, fieldname)
示例3: get_modules
def get_modules(for_module=None):
import importlib
docs = {
"_label": "Modules"
}
if for_module:
modules = [for_module]
else:
modules = webnotes.conn.sql_list("select name from `tabModule Def` order by name")
docs["_toc"] = ["docs.dev.modules." + d for d in modules]
for m in modules:
prefix = "docs.dev.modules." + m
mydocs = docs[m] = {
"_icon": "th",
"_label": m,
"_toc": [
prefix + ".doctype",
prefix + ".page",
prefix + ".py_modules"
],
"doctype": get_doctypes(m),
"page": get_pages(m),
#"report": {},
"py_modules": {
"_label": "Independent Python Modules for " + m,
"_toc": []
}
}
# add stand alone modules
module_path = get_module_path(m)
prefix = prefix + ".py_modules."
for basepath, folders, files in os.walk(module_path):
for f in files:
if f.endswith(".py") and \
(not f.split(".")[0] in os.path.split(basepath)) and \
(not f.startswith("__")):
module_name = ".".join(os.path.relpath(os.path.join(basepath, f),
"../app").split(os.path.sep))[:-3]
# import module
try:
module = importlib.import_module(module_name)
# create a new namespace for the module
module_docs = mydocs["py_modules"][f.split(".")[0]] = {}
# add to toc
mydocs["py_modules"]["_toc"].append(prefix + f.split(".")[0])
inspect_object_and_update_docs(module_docs, module)
except TypeError, e:
webnotes.errprint("TypeError in importing " + module_name)
module_docs["_label"] = module_name
module_docs["_function_namespace"] = module_name
update_readme(docs[m], m)
docs[m]["_gh_source"] = get_gh_url(module_path)
示例4: get_from_files
def get_from_files(self):
"""
Loads page info from files in module
"""
from webnotes.modules import get_module_path, scrub
import os
path = os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name))
# script
fpath = os.path.join(path, scrub(self.doc.name) + '.js')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
self.doc.script = f.read()
# css
fpath = os.path.join(path, scrub(self.doc.name) + '.css')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
self.doc.style = f.read()
# html
fpath = os.path.join(path, scrub(self.doc.name) + '.html')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
self.doc.content = f.read()
if webnotes.lang != 'en':
from webnotes.translate import update_lang_js
self.doc.script = update_lang_js(self.doc.script, path)
示例5: get_code
def get_code(module, dt, dn, extn, fieldname=None):
from webnotes.modules import scrub, get_module_path
import os, webnotes
# get module (if required)
if not module:
module = webnotes.conn.get_value(dt, dn, 'module')
# no module, quit
if not module:
return ''
# file names
if dt in ('Page','Doctype'):
dt, dn = scrub(dt), scrub(dn)
# get file name
fname = dn + '.' + extn
# code
code = ''
try:
file = open(os.path.join(get_module_path(scrub(module)), dt, dn, fname), 'r')
code = file.read()
file.close()
except IOError, e:
# no file, try from db
if fieldname:
code = webnotes.conn.get_value(dt, dn, fieldname)
示例6: on_update
def on_update(self):
"""
Writes the .txt for this page and if write_content is checked,
it will write out a .html file
"""
import conf
from webnotes.modules.import_file import in_import
if not in_import and getattr(conf,'developer_mode', 0) and self.doc.standard=='Yes':
from webnotes.modules.export_file import export_to_files
from webnotes.modules import get_module_path, scrub
import os
export_to_files(record_list=[['Page', self.doc.name]])
# write files
path = os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name), scrub(self.doc.name))
# js
if not os.path.exists(path + '.js'):
with open(path + '.js', 'w') as f:
f.write("""wn.pages['%s'].onload = function(wrapper) {
wn.ui.make_app_page({
parent: wrapper,
title: '%s',
single_column: true
});
}""" % (self.doc.name, self.doc.title))
示例7: get_page_js
def get_page_js(page, module=None):
"""
Returns the js code of a page. Will replace $import (page) or $import(module.page)
with the code from the file
"""
import webnotes, os
from webnotes.modules import scrub, get_module_path
if type(page)==str:
page_name = page
else:
page_name, module = page.name, page.module
code = get_js_code(os.path.join(get_module_path(module), 'page', scrub(page_name), scrub(page_name)))
if not code and type(page)!=str:
code = page.script
# compile for import
if code and code.strip():
import re
p = re.compile('\$import\( (?P<name> [^)]*) \)', re.VERBOSE)
code = p.sub(sub_get_page_js, code)
return code
示例8: get_from_files
def get_from_files(self, doc):
"""
Loads page info from files in module
"""
from webnotes.modules import get_module_path, scrub
import os
path = os.path.join(get_module_path(doc.module), 'page', scrub(doc.name))
# script
fpath = os.path.join(path, scrub(doc.name) + '.js')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
doc.fields['__script'] = f.read()
# css
fpath = os.path.join(path, scrub(doc.name) + '.css')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
doc.style = f.read()
# html
fpath = os.path.join(path, scrub(doc.name) + '.html')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
doc.content = f.read()
示例9: import_file
def import_file(module, dt, dn, force=False):
"""Sync a file from txt if modifed, return false if not updated"""
dt, dn = scrub_dt_dn(dt, dn)
path = os.path.join(get_module_path(module),
os.path.join(dt, dn, dn + '.txt'))
return import_file_by_path(path, force)
示例10: import_file
def import_file(module, dt, dn, force=False):
"""Sync a file from txt if modifed, return false if not updated"""
webnotes.flags.in_import = True
dt, dn = scrub_dt_dn(dt, dn)
path = os.path.join(get_module_path(module),
os.path.join(dt, dn, dn + '.txt'))
ret = import_file_by_path(path, force)
webnotes.flags.in_import = False
return ret
示例11: get_script
def get_script(report_name):
report = webnotes.doc("Report", report_name)
script_path = os.path.join(get_module_path(webnotes.conn.get_value("DocType", report.ref_doctype, "module")),
"report", scrub(report.name), scrub(report.name) + ".js")
if os.path.exists(script_path):
with open(script_path, "r") as script:
return script.read()
else:
return "wn.query_reports['%s']={}" % report_name
示例12: switch_module
def switch_module(dt, dn, to, frm=None, export=None):
"""
Change the module of the given doctype, if export is true, then also export txt and copy
code files from src
"""
webnotes.conn.sql("update `tab"+dt+"` set module=%s where name=%s", (to, dn))
if export:
export_doc(dt, dn)
# copy code files
if dt in ('DocType', 'Page', 'Report'):
from_path = os.path.join(get_module_path(frm), scrub(dt), scrub(dn), scrub(dn))
to_path = os.path.join(get_module_path(to), scrub(dt), scrub(dn), scrub(dn))
# make dire if exists
os.system('mkdir -p %s' % os.path.join(get_module_path(to), scrub(dt), scrub(dn)))
for ext in ('py','js','html','css'):
os.system('cp %s %s')
示例13: make_controller_template
def make_controller_template(self):
from webnotes.modules import get_doc_path, get_module_path, scrub
pypath = os.path.join(get_doc_path(self.doc.module,
self.doc.doctype, self.doc.name), scrub(self.doc.name) + '.py')
if not os.path.exists(pypath):
with open(pypath, 'w') as pyfile:
with open(os.path.join(get_module_path("core"), "doctype", "doctype",
"doctype_template.py"), 'r') as srcfile:
pyfile.write(srcfile.read())
示例14: onload
def onload(self):
import os
from webnotes.modules import get_module_path, scrub
# load content
try:
file = open(os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name) + '.html'), 'r')
self.doc.content = file.read() or ''
file.close()
except IOError, e: # no file / permission
if e.args[0]!=2:
raise e
示例15: update_readme
def update_readme(mydocs, module, doctype=None, name=None):
if doctype:
readme_path = os.path.join(get_doc_path(module, doctype, name), "README.md")
else:
readme_path = os.path.join(get_module_path(module), "README.md")
mydocs["_intro"] = ""
if os.path.exists(readme_path):
with open(readme_path, "r") as readmefile:
mydocs["_intro"] = readmefile.read()
mydocs["_modified"] = get_timestamp(readme_path)