How to use abs_path method in molecule

Best Python code snippet using molecule_python

views.py

Source:views.py Github

copy

Full Screen

1from django.shortcuts import render_to_response2from django.shortcuts import render3from django.template.context import RequestContext4from django.template.loader import render_to_string5from django.core import serializers6from django.http import HttpResponse7from brixtondd.settings import ABS_PATH, AWS_STORAGE_BUCKET_NAME, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY8import tinys39from brixtondd.models import *10def home(request):11 events = Event.objects.select_related().order_by('start')12 artists = Artist.objects.all()13 zones = Zone.objects.all()14 venues = Venue.objects.all()15 artwork = Artwork.objects.all()16 homepage = Homepage.objects.reverse()17 data = list(events) + list(artists) + list(artwork) + list(zones) + list(venues) + list(homepage)18 payload = serializers.serialize("json", data)19 return HttpResponse(payload, content_type="application/json")20def list(request):21 events = Event.objects.select_related().order_by('start')22 for event in events:23 # event.artists = list(event.artists)24 print(repr(event.artists))25 context = {'events': events}26 content = render_to_string('list.html', context)27 with open(ABS_PATH('publish') + '/list.html', 'w') as static_file:28 static_file.write(content)29 return render(request, 'list.html', context)30 # return HttpResponse(payload)31def write_files(request):32 if request.user.is_authenticated():33 json_serializer = serializers.get_serializer('json')()34 conn = tinys3.Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, default_bucket=AWS_STORAGE_BUCKET_NAME, endpoint='s3-eu-west-1.amazonaws.com', tls=True)35 events = data = Event.objects.select_related().order_by('start')36 with open(ABS_PATH('publish') + '/events.json', 'w') as out:37 json_serializer.serialize(data, stream=out)38 content = render_to_string('list.html', {'events': events})39 with open(ABS_PATH('publish') + '/list.html', 'w') as static_file:40 static_file.write(content)41 artists = data = Artist.objects.all()42 with open(ABS_PATH('publish') + '/artists.json', 'w') as out:43 json_serializer.serialize(data, stream=out)44 data = Artwork.objects.all()45 with open(ABS_PATH('publish') + '/artworks.json', 'w') as out:46 json_serializer.serialize(data, stream=out)47 data = Zone.objects.all()48 with open(ABS_PATH('publish') + '/zones.json', 'w') as out:49 json_serializer.serialize(data, stream=out)50 venues = data = Venue.objects.all()51 with open(ABS_PATH('publish') + '/venues.json', 'w') as out:52 json_serializer.serialize(data, stream=out)53 data = Homepage.objects.reverse()54 with open(ABS_PATH('publish') + '/homepage.json', 'w') as out:55 json_serializer.serialize(data, stream=out)56 content = render_to_string('sitemap.xml', {'events': events, 'artists': artists, 'venues': venues})57 with open(ABS_PATH('publish') + '/sitemap.xml', 'w') as static_file:58 static_file.write(content)59 f = open(ABS_PATH('publish') + '/events.json','rb')60 conn.upload('publish/events.json',f)61 f = open(ABS_PATH('publish') + '/list.html','rb')62 conn.upload('publish/list.html',f)63 f = open(ABS_PATH('publish') + '/artists.json','rb')64 conn.upload('publish/artists.json',f)65 f = open(ABS_PATH('publish') + '/artworks.json','rb')66 conn.upload('publish/artworks.json',f)67 f = open(ABS_PATH('publish') + '/zones.json','rb')68 conn.upload('publish/zones.json',f)69 f = open(ABS_PATH('publish') + '/venues.json','rb')70 conn.upload('publish/venues.json',f)71 f = open(ABS_PATH('publish') + '/homepage.json','rb')72 conn.upload('publish/homepage.json',f)73 f = open(ABS_PATH('publish') + '/sitemap.xml','rb')74 conn.upload('publish/sitemap.xml',f)75 message = 'All data published successfully to the live site.'76 else :77 message = 'You are not signed in and no action has been taken. Please sign in to the admin interface and try again.'78 context = RequestContext(request,79 {'request': request,80 'user': request.user,81 'message': message})82 return render_to_response('admin/publish.html',...

Full Screen

Full Screen

excopy.py

Source:excopy.py Github

copy

Full Screen

1#!/usr/bin/python2# ----------------------------------------------------------------------------3# extend methods for copy files/dirs4#5# Copyright 2014 (C) zhangbin6#7# License: MIT8# ----------------------------------------------------------------------------9import os10import shutil11def copy_files_in_dir(src, dst):12 for item in os.listdir(src):13 path = os.path.join(src, item)14 if os.path.isfile(path):15 shutil.copy(path, dst)16 if os.path.isdir(path):17 new_dst = os.path.join(dst, item)18 if not os.path.isdir(new_dst):19 os.makedirs(new_dst)20 copy_files_in_dir(path, new_dst)21def copy_files_with_config(config, src_root, dst_root):22 src_dir = config["from"]23 dst_dir = config["to"]24 src_dir = os.path.join(src_root, src_dir)25 dst_dir = os.path.join(dst_root, dst_dir)26 include_rules = None27 if config.has_key("include"):28 include_rules = config["include"]29 include_rules = convert_rules(include_rules)30 exclude_rules = None31 if config.has_key("exclude"):32 exclude_rules = config["exclude"]33 exclude_rules = convert_rules(exclude_rules)34 copy_files_with_rules(src_dir, src_dir, dst_dir, include_rules, exclude_rules)35def copy_files_with_rules(src_rootDir, src, dst, include = None, exclude = None):36 if os.path.isfile(src):37 if not os.path.exists(dst):38 os.makedirs(dst)39 shutil.copy(src, dst)40 return41 if (include is None) and (exclude is None):42 if not os.path.exists(dst):43 os.makedirs(dst)44 copy_files_in_dir(src, dst)45 elif (include is not None):46 # have include47 for name in os.listdir(src):48 abs_path = os.path.join(src, name)49 rel_path = os.path.relpath(abs_path, src_rootDir)50 if os.path.isdir(abs_path):51 sub_dst = os.path.join(dst, name)52 copy_files_with_rules(src_rootDir, abs_path, sub_dst, include = include)53 elif os.path.isfile(abs_path):54 if _in_rules(rel_path, include):55 if not os.path.exists(dst):56 os.makedirs(dst)57 shutil.copy(abs_path, dst)58 elif (exclude is not None):59 # have exclude60 for name in os.listdir(src):61 abs_path = os.path.join(src, name)62 rel_path = os.path.relpath(abs_path, src_rootDir)63 if os.path.isdir(abs_path):64 sub_dst = os.path.join(dst, name)65 copy_files_with_rules(src_rootDir, abs_path, sub_dst, exclude = exclude)66 elif os.path.isfile(abs_path):67 if not _in_rules(rel_path, exclude):68 if not os.path.exists(dst):69 os.makedirs(dst)70 shutil.copy(abs_path, dst)71def _in_rules(rel_path, rules):72 import re73 ret = False74 path_str = rel_path.replace("\\", "/")75 for rule in rules:76 if re.match(rule, path_str):77 ret = True78 return ret79def convert_rules(rules):80 ret_rules = []81 for rule in rules:82 ret = rule.replace('.', '\\.')83 ret = ret.replace('*', '.*')84 ret = "%s" % ret85 ret_rules.append(ret)...

Full Screen

Full Screen

localizations.py

Source:localizations.py Github

copy

Full Screen

...5__license__ = 'WTFPL2.0'6import os7import json8'''Localization keys and files'''9def abs_path(relative_path: list) -> str:10 ''' given an array of localizations (relative path) 11 returns and absolute path starting from cwd '''12 abs_path = os.getcwd()13 for p in relative_path:14 abs_path = os.path.join(abs_path, p)15 if os.path.isdir(abs_path) and not os.path.exists(abs_path):16 os.mkdir(abs_path)17 return abs_path18# String Localizations19MINIZINC = 'minizinc'20CLINGO = 'clingo'21# Files Localizations22ASSETS = 'assets'23RUNS = 'runs'24LOGS = 'logs'25ASP = 'asp'26CLINGO_MODEL = "knights_tour.lp"27CLINGO_DATABASE = "database.lp"28MINIZINC_MODEL = "knights_tour.mzn"29MINIZINC_DATABASE = "database.dzn"30CLINGO_CMD = 'clingo.sh'31MINIZINC_CMD = 'minizinc.sh'32RUNS_PATH = abs_path([ASSETS, RUNS])33LOGS_PATH = abs_path([ASSETS, LOGS])34CLINGO_MODEL_PATH = abs_path([ASP, CLINGO_MODEL])35CLINGO_DATABASE_PATH = abs_path([ASP, CLINGO_DATABASE])36MINIZINC_MODEL_PATH = abs_path([MINIZINC, MINIZINC_MODEL])37MINIZINC_DATABASE_PATH = abs_path([MINIZINC, MINIZINC_DATABASE])38CLINGO_CMD_PATH = abs_path([ASP, CLINGO_CMD])...

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