本文整理汇总了Python中unipath.Path.ancestor方法的典型用法代码示例。如果您正苦于以下问题:Python Path.ancestor方法的具体用法?Python Path.ancestor怎么用?Python Path.ancestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.ancestor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activate_env
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
def activate_env():
""" Activates the virtual environment for this project."""
error_msg = None
try:
virtualenv_dir = Path(os.environ['WORKON_HOME'])
except KeyError:
error_msg = "Error: 'WORKON_HOME' is not set."
if error_msg:
color_init()
sys.stderr.write(Fore.RED + Style.BRIGHT + error_msg + "\n")
sys.exit(1)
filepath = Path(__file__).absolute()
site_dir = filepath.ancestor(4).components()[-1]
repo_dir = filepath.ancestor(3).components()[-1]
# Add the app's directory to the PYTHONPATH
sys.path.append(filepath.ancestor(2))
sys.path.append(filepath.ancestor(1))
# Set manually in environment
#os.environ['DJANGO_SETTINGS_MODULE'] = 'settings.production'
if os.environ['DJANGO_SETTINGS_MODULE'] == 'settings.production':
bin_parent = site_dir
else:
bin_parent = repo_dir
# Activate the virtual env
activate_env = virtualenv_dir.child(bin_parent, "bin", "activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
示例2: get_closest_uid
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
def get_closest_uid(path):
path = Path(path)
while not path.isdir():
path = path.ancestor(1)
if path == '/':
return False
return path.stat().st_uid
示例3: write_config
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
def write_config(name, instance_name, config, config_type):
path = Path(config_type.format(
name=name,
instance=instance_name,
))
try:
os.makedirs(path.ancestor(1))
except OSError as (id, e):
if id != 17:
raise
示例4: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
GRAPPELLI_ADMIN_TITLE = 'Gestor de Proyectos Baética'
ROOT_URLCONF = 'base.urls'
WSGI_APPLICATION = 'base.wsgi.application'
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': Path(PROJECT_DIR.ancestor(1), 'bd/db.sqlite3'),
}
}
LANGUAGE_CODE = 'es-es'
TIME_ZONE = 'Europe/Madrid'
USE_I18N = True
USE_L10N = True
USE_TZ = True
示例5: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
"""
Django settings for galleria project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
import os
# Build paths inside the project like this: BASE_DIR.child("media")
from unipath import Path
SETTINGS_DIR = Path(__file__).expand_user().expand_vars().norm().absolute()
BASE_DIR = SETTINGS_DIR.ancestor(3) #Root of Django project
BASE_APP_DIR = SETTINGS_DIR.ancestor(2) #Root of main app of Django project
PROJECT_NAME = BASE_DIR.name # eg galleria
#The BASE_PRIVATE_DIR is the root of settings that should not be in the public GIT they are the information
# that will customise the application to a specific client. So for development this should be very little but possible
# if you like to have something a particular way and vital for production.
BASE_PRIVATE_DIR = SETTINGS_DIR.ancestor(5).child(PROJECT_NAME + '_private')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '5rg#+%$#&[email protected]#5r=u^ji0q9&&+5*v(r5wd)y(autnmz5n0bd%'
示例6: files
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
LANGUAGE_CODE = 'en-us'
# template search path
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
PROJECT_DIR.child("templates"),
)
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = PROJECT_DIR.ancestor(1).child("static")
STATICFILES_DIRS = (
('assets', PROJECT_DIR.child("assets")),
)
print PROJECT_DIR.child("assets")
示例7: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
from logging.handlers import SysLogHandler
import os
from django.core.urlresolvers import reverse_lazy
import getconf
from unipath import Path
# Build paths inside the project like this: BASE_DIR.child(...)
CONFIGURATION_APP_ROOT = Path(os.path.abspath(__file__)).ancestor(1)
BASE_DIR = CONFIGURATION_APP_ROOT.ancestor(1)
PROJECT_ROOT = BASE_DIR.ancestor(1)
SITE_NAME = os.path.basename(PROJECT_ROOT)
PUBLIC_ROOT = PROJECT_ROOT.child('public')
CONFIG = getconf.ConfigGetter(SITE_NAME, [
'/etc/%s/settings/' % SITE_NAME,
PROJECT_ROOT.child('local_settings.ini'),
])
ENVIRONMENT = CONFIG.getstr('environment', 'dev')
assert ENVIRONMENT in ('prod', 'dev', 'test')
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = CONFIG.getstr('django.secret_key', 'unsecure')
示例8:
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
LOGIN_URL = '/{app_name}/login/'.format(app_name=APP_NAME)
LOGIN_REDIRECT_URL = '/{app_name}/'.format(app_name=APP_NAME)
LOGOUT_URL = '/{app_name}/logout/'.format(app_name=APP_NAME)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
# edc.crytpo_fields encryption keys
# developers should set by catching their hostname instead of setting
# explicitly
GIT_DIR = BASE_DIR.ancestor(1)
STUDY_OPEN_DATETIME = timezone.datetime(2015, 10, 18, 0, 0, 0)
APP_LABEL = 'tshilo_dikotla'
LABEL_PRINTER_MAKE_AND_MODEL = ['Zebra ZPL Label Printer']
SUBJECT_APP_LIST = ['maternal', 'infant']
SUBJECT_TYPES = ['maternal', 'infant']
MAX_SUBJECTS = {'maternal': 559, 'infant': 559}
MINIMUM_AGE_OF_CONSENT = 18
MAXIMUM_AGE_OF_CONSENT = 64
AGE_IS_ADULT = 18
GENDER_OF_CONSENT = ['F']
DISPATCH_APP_LABELS = []
示例9: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
from unipath import Path
PROJECT_DIR = Path(__file__).ancestor(2)
print "PROJECT_DIR: %s" % PROJECT_DIR
# Django settings for demo project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
DB = PROJECT_DIR.ancestor(2) + '/d201305.db'
print "DB: %s" % DB
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': DB, # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
示例10: get_env_variable
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
# Can be used to attempt to access an environment variable, and if it is unavailable,
# gives a more useful error message and traceback so the variable can be set by a
# sysadmin.
def get_env_variable(var_name):
try:
return os.environ[var_name]
except KeyError:
error_msg = msg % var_name
raise ImproperlyConfigured(error_msg)
SECRET_KEY = get_env_variable("DJANGO_SECRET_KEY")
# Set this_file to '/path/to/electricemberwebsite/ElectricEmberWebsite/settings/base.py'
# so that other important directories can be defined relative to it.
this_file = Path(__file__).absolute()
PROJECT_DIR = this_file.ancestor(3) # PROJECT_DIR = '/path/to/electricemberwebsite/'
PROJECT_APPS_DIR = PROJECT_DIR.child("ElectricEmberWebsite")
MEDIA_ROOT = PROJECT_APPS_DIR.child("media")
STATIC_ROOT = PROJECT_APPS_DIR.child("static")
TEMPLATE_DIRS = (
PROJECT_APPS_DIR.child("templates"),
)
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
# (PROJECT_APPS_DIR.child("static").child("bootstrap").child("js")),
PROJECT_APPS_DIR.child("static"),
示例11: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
"""Common settings and globals."""
from os.path import basename, join, normpath
from sys import path
from unipath import Path
from logging.handlers import SysLogHandler
# ######### PATH CONFIGURATION
# Absolute filesystem path to the Django project directory:
DJANGO_ROOT = Path(__file__).ancestor(3)
# Absolute filesystem path to the top-level project folder:
SITE_ROOT = DJANGO_ROOT.ancestor(1)
# Site name:
SITE_NAME = basename(SITE_ROOT)
# Path to the project Configuration app
CONFIGURATION_APP_ROOT = Path(__file__).ancestor(2)
# Path to public files (served by the web server)
PUBLIC_ROOT = SITE_ROOT.child('public')
# Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths:
path.append(DJANGO_ROOT)
path.append(CONFIGURATION_APP_ROOT)
# ######### END PATH CONFIGURATION
示例12: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
# Django settings for adl_lrs project.
from unipath import Path
# Root of LRS
SETTINGS_PATH = Path(__file__)
PROJECT_ROOT = SETTINGS_PATH.ancestor(3)
# If you want to debug
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'lrs',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
示例13: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
from .base import *
from unipath import Path
PROJECT_DIR = Path(__file__).ancestor(2)
MEDIA_ROOT = PROJECT_DIR.ancestor(2).child("inoxtags_media")
STATIC_ROOT = PROJECT_DIR.ancestor(2).child("inoxtags_static")
STATICFILES_DIRS = (PROJECT_DIR.child("static"),)
TEMPLATE_DIRS = (PROJECT_DIR.child("templates"),)
# Path to the po|mo files
LOCALE_PATHS = PROJECT_DIR.child("locale")
CKEDITOR_UPLOAD_PATH = PROJECT_DIR.ancestor(2).child("inoxtags_media").child("ck_uploads")
DEBUG = False
TEMPLATE_DEBUG = DEBUG
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": get_env_variable("INOXTAGS_DB_NAME"),
"USER": get_env_variable("INOXTAGS_DB_USER"),
"PASSWORD": get_env_variable("INOXTAGS_DB_PASSWORD"),
}
}
ALLOWED_HOSTS = [".inoxtags.com"]
MEDIA_URL = "https://www.inoxtags.com/media/"
STATIC_URL = "https://www.inoxtags.com/static/"
示例14: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
# -*- coding: utf-8 -*-
from logging.handlers import SysLogHandler
from os.path import basename
from sys import path
from unipath import Path
########## PATH CONFIGURATION
# Absolute filesystem path to the Django project directory
DJANGO_ROOT = Path(__file__).ancestor(3)
# Absolute filesystem path to the top-level project folder
PROJECT_ROOT = DJANGO_ROOT.ancestor(1)
# Site name
SITE_NAME = basename(PROJECT_ROOT)
# Path to public files (served by the web server)
PUBLIC_ROOT = PROJECT_ROOT.child('public')
# Path to the project Configuration app
CONFIGURATION_APP_ROOT = Path(__file__).ancestor(2)
# Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths:
path.append(DJANGO_ROOT)
path.append(CONFIGURATION_APP_ROOT)
示例15: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import ancestor [as 别名]
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
import sys
from unipath import Path
from django.utils import timezone
from bcpp_interview.logging import LOGGING
from bcpp_interview.config import CORS_ORIGIN_WHITELIST, EDC_SYNC_ROLE
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
ETC_DIR = os.path.join(BASE_DIR.ancestor(1), 'etc')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
with open(os.path.join(ETC_DIR, 'secret_key.txt')) as f:
SECRET_KEY = f.read().strip()
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
# Application definition
INSTALLED_APPS = [