1
2
3 import os
4
5 from os.path import exists, join
6
7 import turbogears as tg
8
9 from eggbasket.util import is_package_dir, is_package_file
10
12 """Validator checking if a package name refers to a valid package directory.
13 """
14
15 messages = {
16 'notFound': u'Package not found: %(package)s'
17 }
18
20 pkg_root = tg.config.get('eggbasket.package_root', os.getcwd())
21 if not is_package_dir(join(pkg_root, value)):
22
23
24 if is_package_dir(join(pkg_root, value.lower())):
25 value = value.lower()
26 else:
27 raise tg.validators.Invalid(
28 self.message('notFound', state, package=value), value, state)
29 return value
30
32 """Validator checking if a file name refers to a valid package file.
33
34 Must be used as a chained validator.
35 """
36
37 messages = {
38 'notFound': u'Package file not found: %(filename)s'
39 }
40
42 filename = value['filename']
43 pkg_root = tg.config.get('eggbasket.package_root', os.getcwd())
44 pkg_dir = join(pkg_root, value['package'])
45 pkg_file = join(pkg_dir, filename)
46 if not exists(pkg_file) or not is_package_file(pkg_file):
47 message = self.message('notFound', state, filename=filename)
48 errors = dict(filename=message)
49 raise tg.validators.Invalid(message, value, state,
50 error_dict=errors)
51
59
60 __all__ = [
61 'PackageFileSchema'
62 'ValidPackage',
63 'ValidPackageFile'
64 ]
65