本文整理汇总了Python中webnotes.utils.get_base_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_base_path函数的具体用法?Python get_base_path怎么用?Python get_base_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_base_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: backup_to_dropbox
def backup_to_dropbox():
from dropbox import client, session
from conf import dropbox_access_key, dropbox_secret_key
from webnotes.utils.backups import new_backup
if not webnotes.conn:
webnotes.connect()
sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key, "app_folder")
sess.set_token(webnotes.conn.get_value("Backup Manager", None, "dropbox_access_key"),
webnotes.conn.get_value("Backup Manager", None, "dropbox_access_secret"))
dropbox_client = client.DropboxClient(sess)
# upload database
backup = new_backup()
filename = os.path.join(get_base_path(), "public", "backups",
os.path.basename(backup.backup_path_db))
upload_file_to_dropbox(filename, "database", dropbox_client)
response = dropbox_client.metadata("/files")
# upload files to files folder
path = os.path.join(get_base_path(), "public", "files")
for filename in os.listdir(path):
found = False
filepath = os.path.join(path, filename)
for file_metadata in response["contents"]:
if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(filepath).st_size == int(file_metadata["bytes"]):
found = True
break
if not found:
upload_file_to_dropbox(filepath, "files", dropbox_client)
示例2: on_update
def on_update(self):
webnotes.errprint("hiii")
if not (os.path.exists(os.path.join(get_base_path(), "sites"))):
self.make_primary_sites_settings()
if not (os.path.exists(os.path.join(get_base_path(), "sites", self.doc.site_name))):
self.create_new_site()
self.update_global_defaults()
webnotes.msgprint("Updated")
示例3: on_update
def on_update(self):
# webnotes.errprint("hiii")
# return "in update"
if not (os.path.exists(os.path.join(get_base_path(), "sites"))):
self.make_primary_sites_settings()
if not (os.path.exists(os.path.join(get_base_path(), "sites", self.doc.site_name))):
# webnotes.errprint("saurabh.p")
self.create_new_site()
示例4: update_db_name_pwd
def update_db_name_pwd(self):
os.path.join(get_base_path(), "sites", self.doc.site_name, 'site_config.json')
with open (os.path.join(get_base_path(), "sites", self.doc.site_name, 'site_config.json'), 'r') as site_config:
lines = site_config.readlines()
db_name = lines[1].split(':')[1].replace('"','')[:-3]
db_pwd = lines[2].split(':')[1].replace('"','')[:-1]
webnotes.conn.sql("update `tabSite Details` set database_name = LTRIM('%s'), database_password = LTRIM('%s') where name = '%s' "%(db_name, db_pwd, self.doc.name))
webnotes.conn.sql("commit")
示例5: execute
def execute():
# remove pyc files
utils_pyc = os.path.join(get_base_path(), "app", "selling", "utils.pyc")
if os.path.exists(utils_pyc):
os.remove(utils_pyc)
old_path = os.path.join(get_base_path(), "app", "website")
if os.path.exists(old_path):
shutil.rmtree(old_path)
示例6: create_new_site
def create_new_site(self):
root_password = webnotes.conn.get_value("Global Defaults", None, "mysql_root_password")
exec_in_shell("""{path}/lib/wnf.py --install {dbname} --root-password {root_password} --site {name}
""".format(path=get_base_path(), dbname=self.doc.site_name.replace('.', '_'), root_password=root_password, name=self.doc.site_name))
self.add_to_hosts()
exec_in_shell("{path}/lib/wnf.py --build".format(path=get_base_path()))
self.update_db_name_pwd()
示例7: backup_to_gdrive
def backup_to_gdrive():
from webnotes.utils.backups import new_backup
if not webnotes.conn:
webnotes.connect()
get_gdrive_flow()
credentials_json = webnotes.conn.get_value("Backup Manager", None, "gdrive_credentials")
credentials = oauth2client.client.Credentials.new_from_json(credentials_json)
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
# upload database
backup = new_backup()
path = os.path.join(get_base_path(), "public", "backups")
filename = os.path.join(path, os.path.basename(backup.backup_path_db))
# upload files to database folder
upload_files(filename, 'application/x-gzip', drive_service,
webnotes.conn.get_value("Backup Manager", None, "database_folder_id"))
# upload files to files folder
did_not_upload = []
error_log = []
files_folder_id = webnotes.conn.get_value("Backup Manager", None, "files_folder_id")
webnotes.conn.close()
path = os.path.join(get_base_path(), "public", "files")
for filename in os.listdir(path):
found = False
filepath = os.path.join(path, filename)
ext = filename.split('.')[-1]
size = os.path.getsize(filepath)
if ext == 'gz' or ext == 'gzip':
mimetype = 'application/x-gzip'
else:
mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream"
#Compare Local File with Server File
param = {}
children = drive_service.children().list(folderId=files_folder_id, **param).execute()
for child in children.get('items', []):
file = drive_service.files().get(fileId=child['id']).execute()
if filename == file['title'] and size == int(file['fileSize']):
found = True
break
if not found:
try:
upload_files(filepath, mimetype, drive_service, files_folder_id)
except Exception, e:
did_not_upload.append(filename)
error_log.append(cstr(e))
示例8: initiate_tenant_ctreation
def initiate_tenant_ctreation(self, root_password, site_name, is_parent=False):
exec_in_shell("""{path}/lib/wnf.py --install {dbname} --root-password {root_password} --site {name}
""".format(path=get_base_path(), dbname=site_name[:16].replace('.', '_'), root_password=root_password, name=site_name))
self.add_to_hosts(site_name)
exec_in_shell("{path}/lib/wnf.py --build".format(path=get_base_path()))
if is_parent:
self.update_db_name_pwd()
else:
self.update_child_details(site_name)
示例9: backup_to_dropbox
def backup_to_dropbox():
from dropbox import client, session
from conf import dropbox_access_key, dropbox_secret_key
from webnotes.utils.backups import new_backup
if not webnotes.conn:
webnotes.connect()
sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key, "app_folder")
sess.set_token(
webnotes.conn.get_value("Backup Manager", None, "dropbox_access_key"),
webnotes.conn.get_value("Backup Manager", None, "dropbox_access_secret"),
)
dropbox_client = client.DropboxClient(sess)
# upload database
backup = new_backup()
filename = os.path.join(get_base_path(), "public", "backups", os.path.basename(backup.backup_path_db))
upload_file_to_dropbox(filename, "/database", dropbox_client)
webnotes.conn.close()
response = dropbox_client.metadata("/files")
# upload files to files folder
did_not_upload = []
error_log = []
path = os.path.join(get_base_path(), "public", "files")
for filename in os.listdir(path):
filename = cstr(filename)
if filename in ignore_list:
continue
found = False
filepath = os.path.join(path, filename)
for file_metadata in response["contents"]:
if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(
filepath
).st_size == int(file_metadata["bytes"]):
found = True
break
if not found:
try:
upload_file_to_dropbox(filepath, "/files", dropbox_client)
except Exception:
did_not_upload.append(filename)
error_log.append(webnotes.getTraceback())
webnotes.connect()
return did_not_upload, list(set(error_log))
示例10: create_site
def create_site():
from webnotes.model.code import get_obj
webnotes.errprint('test')
sites = webnotes.conn.sql("""select name from `tabSite Details` where flag = 'False' """,as_list=1)
# webnotes.errprint(sites)
for site in sites:
"""For Primary site creation, checks site path exist or not"""
if not (os.path.exists(os.path.join(get_base_path(), "sites"))):
get_obj('Site Details', site[0]).make_primary_sites_settings()
"""For secondary sites"""
if not (os.path.exists(os.path.join(get_base_path(), "sites", site[0]))):
get_obj('Site Details', site[0]).create_new_site()
# webnotes.conn.sql("""update `tabSite Details` set flag = 'True' where name = '%s' """%(site[0]),as_list=1)
示例11: clear_pyc_files
def clear_pyc_files():
from webnotes.utils import get_base_path
for path, folders, files in os.walk(get_base_path()):
if 'locale' in folders: folders.remove('locale')
for f in files:
if f.decode("utf-8").endswith(".pyc"):
os.remove(os.path.join(path, f))
示例12: get_uuid
def get_uuid():
import xml.etree.ElementTree as ET
tree = ET.parse('{path}/hardware.xml'.format(path=os.path.join(get_base_path(), "public", "files")))
root = tree.getroot()
for child in root.iter('setting'):
if child.attrib['id'] == 'uuid':
return child.attrib['value']
示例13: setup_account
def setup_account(args=None):
# if webnotes.conn.sql("select name from tabCompany"):
# webnotes.throw(_("Setup Already Complete!!"))
if not args:
args = webnotes.local.form_dict
if isinstance(args, basestring):
args = json.loads(args)
args = webnotes._dict(args)
update_profile_name(args)
create_fiscal_year_and_company(args)
set_defaults(args)
create_territories()
# create_price_lists(args)
create_feed_and_todo()
import_core_docs()
# create_email_digest()
# create_letter_head(args)
# create_taxes(args)
# create_items(args)
# create_customers(args)
# create_suppliers(args)
webnotes.conn.set_value('Control Panel', None, 'home_page', 'desktop')
webnotes.clear_cache()
webnotes.conn.commit()
# suppress msgprints
webnotes.local.message_log = []
exec_in_shell("""cp -r {path}/lib/public/datatable {path}/public/files
""".format(path=get_base_path()))
webnotes.conn.sql("CREATE TABLE ack(ENCOUNTER_ID varchar(20),ACK varchar(20))")
webnotes.conn.sql("commit()")
return "okay"
示例14: store_stock_reco_json
def store_stock_reco_json():
import os
import json
from webnotes.utils.datautils import read_csv_content
from webnotes.utils import get_base_path
files_path = os.path.join(get_base_path(), "public", "files")
list_of_files = os.listdir(files_path)
replaced_list_of_files = [f.replace("-", "") for f in list_of_files]
for reco, file_list in webnotes.conn.sql("""select name, file_list
from `tabStock Reconciliation`"""):
if file_list:
file_list = file_list.split("\n")
stock_reco_file = file_list[0].split(",")[1]
stock_reco_file_path = os.path.join(files_path, stock_reco_file)
if not os.path.exists(stock_reco_file_path):
if stock_reco_file in replaced_list_of_files:
stock_reco_file_path = os.path.join(files_path,
list_of_files[replaced_list_of_files.index(stock_reco_file)])
else:
stock_reco_file_path = ""
if stock_reco_file_path:
with open(stock_reco_file_path, "r") as open_reco_file:
content = open_reco_file.read()
try:
content = read_csv_content(content)
reconciliation_json = json.dumps(content, separators=(',', ': '))
webnotes.conn.sql("""update `tabStock Reconciliation`
set reconciliation_json=%s where name=%s""",
(reconciliation_json, reco))
except Exception:
# if not a valid CSV file, do nothing
pass
示例15: generate_barcode
def generate_barcode(self):
webnotes.errprint([self.doc.naming_series])
# self.doc.patient_online_id=self.doc.name
# from barcode.writer import ImageWriter
# ean = barcode.get('code39','123322ABS232')
# webnotes.errprint(ean)
# path = os.path.join(get_base_path(), "public", "barcode_img")+"/"+self.doc.name
# fullname = ean.save(path)
# barcode_img = '<html>\
# <table style="width: 100%; table-layout: fixed;">\
# <tr>\
# <td style="width:510px">\
# <img src="'"/barcode_img/"+self.doc.name+".png"'" width="200px">\
# </td>\
# </tr>\
# </table>\
# </html>'
#s="23232ASA343222"
s=self.doc.name
import barcode
from barcode.writer import ImageWriter
ean = barcode.get('code39', s, writer=ImageWriter())
path = os.path.join(get_base_path(), "public", "barcode_img")+"/"+s
filename = ean.save(path)
barcode_img = '<html>\
<table style="width: 100%; table-layout: fixed;">\
<tr>\
<td style="width:510px">\
<img src="'"../barcode_img/"+s+".png"'" width="200px">\
</td>\
</tr>\
</table>\
</html>'
self.doc.barcode_image = barcode_img
self.doc.save()