-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
73 lines (59 loc) · 2.4 KB
/
config.py
File metadata and controls
73 lines (59 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
# This file is part of the pymfony package.
#
# (c) Alexandre Quercia <alquerci@email.com>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
from __future__ import absolute_import;
from pymfony.component.system import Object;
from pymfony.component.system.oop import interface;
from pymfony.component.config import FileLocator as BaseFileLocator;
"""
"""
@interface
class FileResourceLocatorInterface(Object):
def locateResource(self, name, directory=None, first=True):
"""Returns the file path for a given resource.
A Resource can be a file or a directory.
The resource name must follow the following pattern:
@BundleName/path/to/a/file.something
where package is the name of the package
and the remaining part is the relative path in the package.
If directory is passed, and the first segment of the path is Resources,
this method will look for a file named:
directory/BundleName/path/without/Resources
@param name: string A resource name to locate
@param path: string A directory where to look for the resource first
@param first: Boolean Whether to return the first path
or paths for all matching bundles
@return: string|array The absolute path of the resource
or an array if $first is false
@raise InvalidArgumentException: if the file cannot be found or
the name is not valid
@raise RuntimeException: if the name contains invalid/unsafe characters
"""
pass;
class FileLocator(BaseFileLocator):
"""FileLocator uses the KernelInterface to locate resources in packages.
"""
def __init__(self, kernel, path=None, paths = None):
"""
"""
if paths is None:
paths = list();
assert isinstance(kernel, FileResourceLocatorInterface);
self.__kernel = kernel;
self.__path = path;
if path:
paths.append(path);
BaseFileLocator.__init__(self, paths=paths);
def locate(self, name, currentPath=None, first=True):
if name.startswith("@"):
return self.__kernel.locateResource(name, self.__path, first);
return BaseFileLocator.locate(
self,
name,
currentPath=currentPath,
first=first
);