本文整理汇总了Python中turbulenz_local.tools.get_absolute_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_absolute_path函数的具体用法?Python get_absolute_path怎么用?Python get_absolute_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_absolute_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, user, game):
self.lock = Lock()
self.game = game
self.user = user
try:
path = config['gameprofile_db']
except KeyError:
LOG.error('gameprofile_db path config variable not set')
return
# Create gameprofile folder and user folder on the game path
path = join_path(path, game.slug)
if not create_dir(path):
error_msg = 'User GameProfile path \"%s\" could not be created.' % path
LOG.error(error_msg)
raise GameProfileError(error_msg)
self.path = get_absolute_path(path)
self.defaults = {}
default_yaml_path = unicode(get_absolute_path(join_path(game.path, 'defaultgameprofiles.yaml')))
if path_exists(default_yaml_path):
with open(default_yaml_path, 'r') as f:
try:
file_defaults = yaml.load(f)
self.defaults = dict((v['user'], v['value']) for v in file_defaults['profiles'])
except (yaml.YAMLError, KeyError, TypeError) as e:
LOG.error('Failed loading default game profiles: %s', str(e))
示例2: __init__
def __init__(self, game, hub_pool, hub_project, hub_version, hub_versiontitle, hub_cookie, cache_dir):
self.path = abspath(get_absolute_path(game.path))
self.plugin_main = game.plugin_main
self.canvas_main = game.canvas_main
self.flash_main = game.flash_main
self.mapping_table = game.mapping_table
self.files = game.deploy_files.items
self.engine_version = game.engine_version
self.is_multiplayer = game.is_multiplayer
self.aspect_ratio = game.aspect_ratio
self.cache_dir = cache_dir
self.game_cache_dir = join(abspath(cache_dir), game.slug)
self.stopped = False
self.hub_project = hub_project
self.hub_version = hub_version
self.hub_versiontitle = hub_versiontitle
self.hub_session = None
self.hub_pool = hub_pool
self.hub_cookie = hub_cookie
self.hub_timeout = 200
self.total_files = 0
self.num_files = 0
self.num_bytes = 0
self.uploaded_files = 0
self.uploaded_bytes = 0
self.done = False
self.error = None
try:
makedirs(self.get_gzip_dir())
except OSError as e:
if e.errno != EEXIST:
LOG.error(str(e))
示例3: is_correct
def is_correct(self):
try:
abs_path = get_absolute_path(self.__str__())
return access(abs_path, W_OK)
except (AttributeError, TypeError):
# TODO: These are thrown by get_absolute_path when called on None and probably shouldn't be needed
return False
示例4: get_versions
def get_versions(self):
# if the game path is defined, find play-html files.
versions = [ ]
if self.path.is_correct():
abs_path = get_absolute_path(self.path)
slug = self.slug + '/'
executable_extensions = self._executable_extensions
flash_dict = None
for file_name in listdir(abs_path):
if file_name.endswith(executable_extensions):
version = { 'title': os.path.basename(file_name),
'url': slug + file_name }
if file_name.endswith('.swf'):
if flash_dict is None:
flash_dict = {}
flash_config_path = join_path(abs_path, 'flash.yaml')
if access(flash_config_path, R_OK):
f = open(unicode(flash_config_path), 'r')
try:
flash_dict = yaml.load(f)
finally:
f.close()
version['flash'] = flash_dict
versions.append(version)
return versions
示例5: __init__
def __init__(self):
self.lock = Lock()
self.lock.acquire()
self._sessions = {}
path = config.get('gamesessions.yaml', 'gamesessions.yaml')
self.path = get_absolute_path(path)
self.load_sessions()
self.lock.release()
示例6: __call__
def __call__(self, environ, start_response):
request_path = environ.get('PATH_INFO', '')
# check if the request is for static files at all
path_parts = request_path.strip('/').split('/', 2)
if len(path_parts) == 3 and path_parts[0] in ['play', 'game-meta']:
slug = path_parts[1]
game = self.game_list.get_by_slug(slug)
if game and game.path.is_set():
asset_path = path_parts[2]
file_asset_path = normpath(join(get_absolute_path(game.path), asset_path))
def build_file_iter(f, block_size):
return StaticFileIter(file_asset_path, normpath(join(slug, asset_path)), f, block_size)
def remove_ranges_start_response(status, headers, exc_info=None):
if status == '200 OK':
headers = [t for t in headers if t[0] != 'Accept-Ranges' and t[0] != 'Content-Range']
return start_response(status, headers, exc_info)
# check if the request is already cached
app = self.cached_apps.get(request_path)
if app:
environ['wsgi.file_wrapper'] = build_file_iter
try:
return app(environ, remove_ranges_start_response)
except OSError as e:
LOG.error(e)
elif access(file_asset_path, R_OK):
content_type, _ = guess_type(file_asset_path)
if content_type in self.utf8_mimetypes:
content_type += '; charset=utf-8'
app = FileApp(file_asset_path, content_type=content_type)
if asset_path.startswith('staticmax'):
app.cache_control(max_age=self.staticmax_max_age)
else:
app.cache_control(max_age=0)
self.cached_apps[request_path] = app
environ['wsgi.file_wrapper'] = build_file_iter
return app(environ, remove_ranges_start_response)
start_response(
'404 Not Found',
[('Content-Type', 'text/html; charset=UTF-8'),
('Content-Length', '0')]
)
return ['']
return self.app(environ, start_response)
示例7: post
def post(self, slug, filename):
"""
Saves given contents to file to game folder.
"""
game = get_game_by_slug(slug)
if not game:
self.set_status(404)
return self.finish({'ok': False, 'msg': 'Game does not exist: %s' % slug})
if not filename:
self.set_status(400)
return self.finish({'ok': False, 'msg': 'Missing filename'})
if '..' in filename:
self.set_status(403)
return self.finish({'ok': False, 'msg': 'Cannot write outside game folder'})
content = self.get_argument('content')
self.request.body = None
self.request.arguments = None
file_path = path_join(get_absolute_path(game.get_path()), normpath(filename))
file_dir = dirname(file_path)
if not create_dir(file_dir):
LOG.error('Failed to create directory at "%s"', file_dir)
self.set_status(500)
return self.finish({'ok': False, 'msg': 'Failed to create directory'})
if content:
try:
content = content.encode('utf-8')
except UnicodeEncodeError as e:
LOG.error('Failed to encode file contents: %s', str(e))
self.set_status(500)
return self.finish({'ok': False, 'msg': 'Failed to encode file contents'})
LOG.info('Writing file at "%s" (%d bytes)', file_path, len(content))
else:
LOG.info('Writing empty file at "%s"', file_path)
try:
file_obj = open(file_path, 'wb')
try:
file_obj.write(content)
finally:
file_obj.close()
except IOError as e:
LOG.error('Failed to write file at "%s": %s', file_path, str(e))
self.set_status(500)
return self.finish({'ok': False, 'msg': 'Failed to write file'})
return self.finish({'ok': True})
示例8: _set_userbadges_path
def _set_userbadges_path(self):
if not self.userbadges_path:
try:
path = config['userbadges_db']
except KeyError:
LOG.error('badges_db path config variable not set')
return
if not create_dir(path):
LOG.error('Game badges path \"%s\" could not be created.', path)
self.userbadges_path = norm_path(join_path(get_absolute_path(path), self.game.slug) + '.yaml')
示例9: path_in_use
def path_in_use(self, query_path):
"""
Return True if the given path is already being used in the GameList.
Otherwise False.
"""
# turn path absolute
query_path = get_absolute_path(query_path)
# check all games...
for game in self._slugs.itervalues():
# ... that have a path ...
test_path = game.path
if test_path is not None:
# .. if they are using the given path
test_path = get_absolute_path(test_path)
if query_path == test_path:
return True
return False
示例10: _read_users
def _read_users(self):
do_save = False
try:
path = config['user.yaml']
except KeyError:
LOG.error('Config variable not set for path to "user.yaml"')
if exists(get_absolute_path(path)):
try:
f = open(path, 'rt')
try:
user_info = yaml.load(f)
if 'users' in user_info:
self.active = user_info.get('active', None)
for u in user_info['users']:
user = self._add_user(u)
if self.active is None:
self.active = user.username
else:
user = self._add_user(user_info)
self.active = user.username
do_save = True
finally:
f.close()
except IOError as e:
LOG.error('Failed loading users: %s' % str(e))
else:
self._add_user(User.default_username)
self.active = User.default_username
do_save = True
try:
path = path_join(CONFIG_PATH, 'defaultusers.yaml')
f = open(path, 'rt')
try:
user_info = yaml.load(f)
for u in user_info['users']:
# dont overwrite changed user settings
if u['username'].lower() not in self.users:
user = User(u, default=True)
username = user.username.lower()
self.users[username] = user
do_save = True
finally:
f.close()
except IOError as e:
LOG.error('Failed loading default users: %s' % str(e))
except KeyError:
LOG.error('Username missing for default user "defaultusers.yaml"')
except ValueError:
LOG.error('Username invalid for default user "defaultusers.yaml"')
if do_save:
self._write_users()
示例11: __init__
def __init__(self, game):
self.game = game
self.abs_game_path = get_absolute_path(game.path)
try:
yaml_path = norm_path(get_absolute_path(join_path(game.path, 'gamenotifications.yaml')))
if not access(yaml_path, R_OK):
raise GameNotificationsUnsupportedException()
with open(unicode(yaml_path), 'r') as f:
notifications = {}
for n_key in yaml.load(f):
notifications[n_key['key']] = n_key
self._notifications = notifications
except (IOError, KeyError) as e:
LOG.error('Failed loading gamenotifications: %s', str(e))
raise ApiException('Failed loading gamenotifications.yaml file %s' % str(e))
示例12: create_path
def create_path(self):
try:
path = config['datashare_db']
except KeyError:
LOG.error('datashare_db path config variable not set')
raise
# Create datashare folder
path = join_path(path, self.game.slug)
if not create_dir(path):
LOG.error('DataShare path \"%s\" could not be created.' % path)
raise IOError('DataShare path \"%s\" could not be created.' % path)
return get_absolute_path(path)
示例13: get_path
def get_path(self):
if self.path is not None:
return self.path
try:
path = config['datashare_db']
except KeyError:
LOG.error('datashare_db path config variable not set')
raise
path = get_absolute_path(join_path(path, self.game.slug, self.datashare_id + '.yaml'))
self.path = path
return path
示例14: __init__
def __init__(self, game):
self.lock = Lock()
self.game = game
self.userbadges_path = None
self.abs_game_path = get_absolute_path(game.path)
try:
self.lock.acquire()
yaml_path = norm_path(get_absolute_path(join_path(game.path, 'badges.yaml')))
if not access(yaml_path, R_OK):
raise BadgesUnsupportedException()
f = open(unicode(yaml_path), 'r')
try:
self.badges = yaml.load(f)
finally:
f.close()
except IOError as e:
LOG.error('Failed loading badges: %s', str(e))
raise ApiException('Failed loading badges.yaml file %s' % str(e))
finally:
self.lock.release()
示例15: get_asset
def get_asset(asset, slug, userdata=None):
game = get_game_by_slug(slug)
if userdata:
# asset = user / key
(username, key) = asset.split('/', 1)
user = get_user(username)
userdata = UserData(user=user, game=game)
json_asset = json.loads(userdata.get(key))
filename = key + '.txt'
else:
filename = get_absolute_path(os.path.join(game.path, asset))
with open(filename, 'r') as handle:
json_asset = json.load(handle)
return (json_asset, filename)