How to use template_dir method in molecule

Best Python code snippet using molecule_python

mobile_views.py

Source:mobile_views.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import absolute_import3import os4from django.http import HttpResponseRedirect5from webapp.modules.mall import request_util6template_path_items = os.path.dirname(__file__).split(os.sep)7TEMPLATE_DIR = '%s/templates/webapp' % template_path_items[-1]8def get_homepage(request):9 return request_util.get_homepage(request)10def list_products(request):11 """显示"商品列表"页面12 """13 # 2015-10-2014 # if request.user.is_weizoom_mall:15 # # 微众商城跳至微众商城首页16 # return __weshop_index(request)17 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)18 return request_util.list_products(request)19def get_product(request):20 """显示“商品详情”页面21 """22 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)23 return request_util.get_product(request)24########################################################################25# get_order_list: 获取订单列表26########################################################################27def get_order_list(request):28 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)29 return request_util.get_order_list(request)30########################################################################31# edit_order: 编辑订单32########################################################################33def edit_order(request):34 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)35 return request_util.edit_order(request)36 # if request.webapp_user.ship_info and request.webapp_user.ship_info.ship_name:37 # return request_util.edit_order(request)38 # else:39 # request.action = 'add'40 # return request_util.edit_address(request)41########################################################################42# pay_order: 支付订单页面43########################################################################44def pay_order(request):45 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)46 return request_util.pay_order(request)47########################################################################48# get_pay_result: 支付结果,在支付宝完成支付后支付宝访问49# 携带的参数中主要使用:50# out_trade_no 订单号51########################################################################52def get_pay_result(request):53 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)54 return request_util.get_pay_result(request)55########################################################################56# get_pay_notify_result : 支付宝异步 回调接口57########################################################################58def get_pay_notify_result(request):59 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)60 return request_util.get_pay_notify_result(request)61########################################################################62# get_order_pay_result_success : 实付金额为0元时,直接跳转63########################################################################64def get_pay_result_success(request):65 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)66 return request_util.get_pay_result_success(request)67########################################################################68# show_shopping_cart: 显示购物车详情69########################################################################70def show_shopping_cart(request):71 ''' 显示购物车详情72 '''73 # 微众商城代码74 # if request.user.is_weizoom_mall:75 # # 微众商城跳至微众商城首页76 # return __weshop_index(request)77 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)78 # product_groups, invalid_products = mall_api.get_shopping_cart_products(request.webapp_user, request.webapp_owner_id)79 # product_groups = utils.sorted_product_groups_by_promotioin(product_groups)80 # request.should_hide_footer = True81 # jsons = [{82 # "name": "productGroups",83 # "content": utils.format_product_group_price_factor(product_groups)84 # }]85 # c = RequestContext(request, {86 # 'is_hide_weixin_option_menu': True,87 # 'page_title': u'购物车',88 # 'product_groups': product_groups,89 # 'invalid_products': invalid_products,90 # 'jsons': jsons91 # })92 return request_util.show_shopping_cart(request)93def edit_shopping_cart_order(request):94 """编辑从购物车产生的订单95 """96 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)97 return request_util.edit_shopping_cart_order(request)98# jz 2015-10-0999# def pay_weizoompay_order(request):100# request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)101# return request_util.pay_weizoompay_order(request)102# jz 2015-10-09103# def get_weizoompay_confirm(request):104# request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)105# return request_util.get_weizoompay_confirm(request)106# def get_weizoomcard_change_intr(request):107# request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)108# return request_util.get_weizoomcard_change_intr(request)109# 功能迁移到js110# def _get_redirect_url_query_string(request):111# # 入口是图文112# sign = request.GET.get('sign', None)113# if sign == 'material_news':114# return u'woid={}&module=mall&model=address&action=list&sign=material_news'.format(request.webapp_owner_id)115#116# # 参数中包含117# redirect_url_query_string = request.GET.get('redirect_url_query_string', None)118# if redirect_url_query_string:119# if 'user_center' in redirect_url_query_string:120# return u'woid={}&module=mall&model=address&action=list&sign=material_news'.format(request.webapp_owner_id)121# return redirect_url_query_string122#123# # 当前页面的参数124# if 'product_ids' in request.REQUEST or 'product_id' in request.REQUEST:125# return request.META.get('QUERY_STRING', '')126#127# # 前一页的参数128# strs = request.META.get('HTTP_REFERER', '').split('/?')129# if len(strs) > 1:130# return strs[1]131#132# return '#'133########################################################################134# show_concern_shop_url: 点击关注店铺135########################################################################136def show_concern_shop_url(request):137 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)138 return request_util.show_concern_shop_url(request)139########################################################################140# list_address: 收货地址列表141########################################################################142def list_address(request):143 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)144 return request_util.list_address(request)145########################################################################146# add_address: 添加收货地址147########################################################################148def add_address(request):149 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)150 return request_util.edit_address(request)151########################################################################152# edit_address: 编辑收货地址153########################################################################154def edit_address(request):155 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)156 request.action = 'edit'157 return request_util.edit_address(request)158########################################################################159# success_alert: 成功提示页160########################################################################161def success_alert(request):162 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)163 return request_util.success_alert(request)164########################################################################165# success_alert: 成功提示页166########################################################################167def get_express_detail(request):168 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)169 return request_util.get_express_detail(request)170########################################################################171# create_goods_review: 创建商品评论172########################################################################173def create_product_review(request):174 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)175 return request_util.create_product_review(request)176########################################################################177# get_product_review_successful_page: 创建商品评论178########################################################################179def get_product_review_successful_page(request):180 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)181 return request_util.get_product_review_successful_page(request)182########################################################################183# get_order_review: 会员订单中未评价订单列表184########################################################################185def get_order_review_list(request):186 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)187 return request_util.get_order_review_list(request)188def get_product_review_list(request):189 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)190 return request_util.get_product_review_list(request)191def update_product_review_picture(request):192 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)193 return request_util.update_product_review_picture(request)194def redirect_product_review(request):195 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)196 return request_util.redirect_product_review(request)197#add by bert198def edit_refueling_order(request):199 request.template_dir = '%s/%s' % (TEMPLATE_DIR, request.template_name)200 return request_util.edit_refueling_order(request)201# 微众商城代码202# def __weshop_index(request):203# '''跳转至微众商城首页204# '''...

Full Screen

Full Screen

globals.py

Source:globals.py Github

copy

Full Screen

1"""This module contains global variables used by various scripts within this project."""2import os3import sys4BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))5sys.path.append(BASE_DIR)6import config # noqa7BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))8LOG_DIR = os.path.join(BASE_DIR, "logs")9CLI_LOG_DIR = os.path.join(LOG_DIR, "cli")10WEB_SCRAPER_LOG_DIR = os.path.join(LOG_DIR, "webscraper")11IMAGE_LOG_DIR = os.path.join(LOG_DIR, "images")12COMMON_DIR = os.path.join(BASE_DIR, "common")13WEB_SCRAPER_DIR = os.path.join(BASE_DIR, "web_scraper")14WEB_SCRAPER_ENV_DIR = os.path.join(WEB_SCRAPER_DIR, "env")15DATA_DIR = os.path.join(BASE_DIR, "data")16INPUT_DIR = os.path.join(DATA_DIR, "input")17EMAIL_TEMPLATE_DIR = os.path.join(DATA_DIR, "email_templates")18TEMPLATE_DIR = os.path.join(INPUT_DIR, "templates")19SAMPLE_DATA_DIR = os.path.join(TEMPLATE_DIR, "sample_data")20OUTPUT_DIR = os.path.join(DATA_DIR, "output")21TREND_DIR = os.path.join(DATA_DIR, "trend_analysis")22IMAGE_DIR = os.path.join(BASE_DIR, "images")23NOTEBOOK_DIR = os.path.join(IMAGE_DIR, "notebook")24# Create directories not tracked by git25if not os.path.exists(OUTPUT_DIR):26 os.mkdir(OUTPUT_DIR)27if not os.path.exists(LOG_DIR):28 os.mkdir(LOG_DIR)29if not os.path.exists(CLI_LOG_DIR):30 os.mkdir(CLI_LOG_DIR)31if not os.path.exists(WEB_SCRAPER_LOG_DIR):32 os.mkdir(WEB_SCRAPER_LOG_DIR)33 with open("cron.log", "w") as f:34 pass35if not os.path.exists(IMAGE_LOG_DIR):36 os.mkdir(IMAGE_LOG_DIR)37# Elasticsearch38ES_URL = "http://localhost:9200"39ES_URL_DOCKER = "http://host.docker.internal:9200"40ES_DIR = os.path.join(DATA_DIR, "elasticsearch")41ES_MAPPINGS = os.path.join(ES_DIR, "mappings")42ES_INDEX_NAME = ["bookings", "sessions", "counters", "projects"]43ES_BULK_DATA = os.path.join(ES_DIR, "bulk_data")44# Kibana45KIBANA_URL = "http://localhost:5601"46KIBANA_URL_DOCKER = "http://host.docker.internal:5601"47# Weather data48WEATHER_DIR = os.path.join(DATA_DIR, "weather")49OTTAWA_WEATHER = os.path.join(WEATHER_DIR, "ottawa_weather.csv")50GATINEAU_WEATHER = os.path.join(WEATHER_DIR, "gatineau_weather.csv")51WEATHER_URL = "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/weatherdata/history" # noqa52# Generated ENV File53BOOKINGS_ENV = os.path.join(WEB_SCRAPER_ENV_DIR, "bookings.env")54# Paths to default templates for climbing logs55_altitude_kanata = (56 os.path.join(TEMPLATE_DIR, "indoor_bouldering_altitude_personal.yaml")57 if os.path.exists(58 os.path.join(TEMPLATE_DIR, "indoor_bouldering_altitude_personal.yaml")59 )60 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_altitude_kanata.yaml")61)62_altitude_gatineau = (63 os.path.join(TEMPLATE_DIR, "indoor_bouldering_altitude_personal.yaml")64 if os.path.exists(65 os.path.join(TEMPLATE_DIR, "indoor_bouldering_altitude_personal.yaml")66 )67 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_altitude_gatineau.yaml")68)69_coyote_rock_gym = (70 os.path.join(TEMPLATE_DIR, "indoor_bouldering_coyote_personal.yaml")71 if os.path.exists(72 os.path.join(TEMPLATE_DIR, "indoor_bouldering_coyote_personal.yaml")73 )74 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_coyote.yaml")75)76_klimat = (77 os.path.join(TEMPLATE_DIR, "indoor_bouldering_klimat_personal.yaml")78 if os.path.exists(79 os.path.join(TEMPLATE_DIR, "indoor_bouldering_klimat_personal.yaml")80 )81 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_klimat.yaml")82)83_calabogie = (84 os.path.join(TEMPLATE_DIR, "outdoor_bouldering_calabogie_personal.yaml")85 if os.path.exists(86 os.path.join(TEMPLATE_DIR, "outdoor_bouldering_calabogie_personal.yaml")87 )88 else os.path.join(TEMPLATE_DIR, "outdoor_bouldering_calabogie.yaml")89)90_up_the_bloc = (91 os.path.join(TEMPLATE_DIR, "indoor_bouldering_up_the_bloc_personal.yaml")92 if os.path.exists(93 os.path.join(TEMPLATE_DIR, "indoor_bouldering_up_the_bloc_personal.yaml")94 )95 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_up_the_bloc.yaml")96)97_cafe_bloc = (98 os.path.join(TEMPLATE_DIR, "indoor_bouldering_cafe_bloc_personal.yaml")99 if os.path.exists(100 os.path.join(TEMPLATE_DIR, "indoor_bouldering_cafe_bloc_personal.yaml")101 )102 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_cafe_bloc.yaml")103)104_allez_up = (105 os.path.join(TEMPLATE_DIR, "indoor_bouldering_allez_up_personal.yaml")106 if os.path.exists(107 os.path.join(TEMPLATE_DIR, "indoor_bouldering_allez_up_personal.yaml")108 )109 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_allez_up.yaml")110)111_bloc_shop_chabanel = (112 os.path.join(TEMPLATE_DIR, "indoor_bouldering_bloc_shop_chabanel_personal.yaml")113 if os.path.exists(114 os.path.join(TEMPLATE_DIR, "indoor_bouldering_bloc_shop_chabanel_personal.yaml")115 )116 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_bloc_shop_chabanel.yaml")117)118_bloc_shop_hochelaga = (119 os.path.join(TEMPLATE_DIR, "indoor_bouldering_bloc_shop_hochelaga_personal.yaml")120 if os.path.exists(121 os.path.join(122 TEMPLATE_DIR, "indoor_bouldering_bloc_shop_hochelaga_personal.yaml"123 )124 )125 else os.path.join(TEMPLATE_DIR, "indoor_bouldering_bloc_shop_hochelaga.yaml")126)127_hogs_back = (128 os.path.join(TEMPLATE_DIR, "outdoor_bouldering_personal.yaml")129 if os.path.exists(os.path.join(TEMPLATE_DIR, "outdoor_bouldering_personal.yaml"))130 else os.path.join(TEMPLATE_DIR, "outdoor_bouldering.yaml")131)132_default = (133 os.path.join(TEMPLATE_DIR, "indoor_bouldering_personal.yaml")134 if os.path.exists(os.path.join(TEMPLATE_DIR, "indoor_bouldering_personal.yaml"))135 else os.path.join(TEMPLATE_DIR, "indoor_bouldering.yaml")136)137_default = _altitude_kanata138GYM_TEMPLATE = {139 "kanata": _altitude_kanata,140 "altitude kanata": _altitude_kanata,141 "gatineau": _altitude_gatineau,142 "altitude gatineau": _altitude_gatineau,143 "coyote": _coyote_rock_gym,144 "coyote rock gym": _coyote_rock_gym,145 "klimat": _klimat,146 "calabogie": _calabogie,147 "up the bloc": _up_the_bloc,148 "hogs back": _hogs_back,149 "hog's back": _hogs_back,150 "cafe bloc": _cafe_bloc,151 "allez up": _allez_up,152 "bloc shop chabanel": _bloc_shop_chabanel,153 "bloc shop hochelaga": _bloc_shop_hochelaga,154 "default": _default,155}156if config.default_gym:157 default = config.default_gym.lower()158if isinstance(default, str) and default in GYM_TEMPLATE.keys():...

Full Screen

Full Screen

newtarget.py

Source:newtarget.py Github

copy

Full Screen

1#!/usr/bin/env python2#3# Create a new P4 program target in the p4model repository4import os5import sys6import argparse7VERBOSE = False8def die(msg):9 """10 Error occurred; report and exit11 """12 sys.stderr.write(msg + "\n")13 exit(1)14def apply_subs_map(line, map):15 """16 Do string replacements on line indicated by map17 """18 for key, val in map.items():19 line = line.replace(key, val)20 return line21def copy_template(template_dir, filename, dest_dir, map):22 """23 Copy template to file dest_name with indicated string substitutions24 Remove first level of template_dir to form subdirectory for dest25 """26 if VERBOSE:27 print("create: %s + %s => %s" % (template_dir, filename, dest_dir))28 with open(os.path.join(template_dir, filename)) as f:29 content = f.readlines()30 # Allow substitutions in the filename as well as content31 dest_filename = os.path.join(dest_dir, apply_subs_map(filename, map))32 dest_dir = os.path.dirname(dest_filename)33 if not os.path.exists(dest_dir):34 os.mkdir(dest_dir)35 with open(os.path.join(dest_dir, dest_filename), "w") as f:36 for line in content:37 f.write(apply_subs_map(line, map))38def create_files(template_dir, dest_dir, proj_name):39 """40 Generate the files needed for the new target41 @param template_dir Where templates and dir structure are42 @param p4_source The file or directory holding P4 source code43 The directory 'template_dir' is scanned and a new version of each44 file there is created in the target directory.45 If template_dir is a directory, get everything there;46 If template_dir is a file, just get that file.47 """48 # The map of string replacements49 repl_map = { "__PROJECT_NAME__": proj_name }50 if os.path.isdir(template_dir):51 if template_dir[-1] != "/":52 template_dir = template_dir + "/"53 template_files = []54 for subdir, dirs, files in os.walk(template_dir):55 for file in files:56 filename = os.path.join(subdir, file).split(template_dir)[1]57 template_files.append(filename)58 elif os.path.isfile(template_dir):59 template_files = [os.path.basename(template_dir)]60 template_dir = os.path.dirname(template_dir)61 else:62 die("Could not find template dir %s" % template_dir)63 for source in template_files:64 copy_template(template_dir, source, dest_dir, repl_map)65def update_gitignore(path, name):66 with open(os.path.join(path, ".gitignore"), "a") as f:67 f.write(name + "\n")68def main():69 tools_dir = os.path.dirname(os.path.realpath(__file__))70 template_dir = os.path.join(tools_dir, "new_target_template")71 targets_dir = os.path.join(tools_dir, "../targets")72 modules_dir = os.path.join(tools_dir, "../modules")73 default_p4_prog = os.path.join(tools_dir, "default_p4_source")74 parser = argparse.ArgumentParser(75 description='Generate a new target for a P4 program',76 usage="%(prog)s [options] project-name")77 parser.add_argument('proj_name', metavar='proj_name', type=str,78 help='The name of the project to generated')79 parser.add_argument('--p4_source', type=str,80 help='The file or directory with P4 source to use',81 default=os.path.join(tools_dir, default_p4_prog))82 parser.add_argument('--verbose', action="store_true",83 help="Turn on verbose debugging", default=False)84 args = parser.parse_args()85 VERBOSE = args.verbose86 proj_name = args.proj_name.strip("/")87 if os.path.exists(proj_name):88 die("Directory or file %s exists" % proj_name)89 try:90 os.mkdir(os.path.join(targets_dir, proj_name))91 os.mkdir(os.path.join(targets_dir, proj_name, "p4src"))92 os.mkdir(os.path.join(targets_dir, proj_name, "tests"))93 os.mkdir(os.path.join(targets_dir, proj_name, "tests", "ptf-tests"))94 os.mkdir(os.path.join(targets_dir, proj_name, "targets"))95 os.mkdir(os.path.join(targets_dir, proj_name, "targets", "libpd_thrift"))96 os.mkdir(os.path.join(targets_dir, proj_name, "targets", "libtbl_packing"))97 except:98 die("Could not create directories for %s" % proj_name)99 create_files(template_dir, os.path.join(targets_dir, proj_name), proj_name)100 create_files(args.p4_source, os.path.join(targets_dir, proj_name, "p4src"),101 proj_name)102 update_gitignore(modules_dir, "/%s_sim" % proj_name)103if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful