Mercurial > farol > farolluz
comparison farolluz/common.py @ 26:809db989cac5
Reorganize the code in smaller mpodules
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Fri, 24 Oct 2014 17:01:26 +0200 |
parents | farolluz/cvrf.py@4004b67216a9 |
children |
comparison
equal
deleted
inserted
replaced
25:3cab052872f4 | 26:809db989cac5 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 # | |
3 # Authors: | |
4 # BenoƮt Allard <benoit.allard@greenbone.net> | |
5 # | |
6 # Copyright: | |
7 # Copyright (C) 2014 Greenbone Networks GmbH | |
8 # | |
9 # This program is free software; you can redistribute it and/or | |
10 # modify it under the terms of the GNU General Public License | |
11 # as published by the Free Software Foundation; either version 2 | |
12 # of the License, or (at your option) any later version. | |
13 # | |
14 # This program is distributed in the hope that it will be useful, | |
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 # GNU General Public License for more details. | |
18 # | |
19 # You should have received a copy of the GNU General Public License | |
20 # along with this program; if not, write to the Free Software | |
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
22 | |
23 """\ | |
24 Common Objects related to CVRF Documents | |
25 """ | |
26 | |
27 class ValidationError(Exception): pass | |
28 | |
29 | |
30 class CVRFNote(object): | |
31 TYPES = ('General', 'Details', 'Description', 'Summary', 'FAQ', | |
32 'Legal Disclaimer', 'Other') | |
33 def __init__(self, _type, ordinal, note, title=None, audience=None): | |
34 self._type = _type | |
35 self._ordinal = ordinal | |
36 self._note = note | |
37 self._title = title | |
38 self._audience = audience | |
39 | |
40 def getTitle(self): | |
41 """ returns something that can be used as a title """ | |
42 if self._title is None: | |
43 return "%s (#%d)" % (self._type, self._ordinal) | |
44 return "%s (%s)" % (self._title, self._type) | |
45 | |
46 def validate(self): | |
47 if not self._type: | |
48 raise ValidationError('A Note needs to have a Type set') | |
49 if self._type not in self.TYPES: | |
50 raise ValidationError('A Note Type needs to be one of %s' % ', '.join(self.TYPES)) | |
51 if self._ordinal < 0: | |
52 raise ValidationError('A Note ordinal must be a positive integer') | |
53 if not self._note: | |
54 raise ValidationError('A Note must contain some text') | |
55 | |
56 | |
57 def __str__(self): | |
58 return self._note | |
59 | |
60 | |
61 class CVRFReference(object): | |
62 TYPES = ('Self', 'External') | |
63 def __init__(self, url, description, _type=None): | |
64 self._url = url | |
65 self._description = description | |
66 self._type = _type | |
67 | |
68 def validate(self): | |
69 if (self._type is not None) and (self._type not in self.TYPES): | |
70 raise ValidationError('If a Reference type is set, it mist be one of %s' % ', '.join(self.TYPES)) | |
71 if not self._url: | |
72 raise ValidationError('A Reference must contain an URL') | |
73 if not self._description: | |
74 raise ValidationError('A Reference must contain a description') | |
75 | |
76 | |
77 class CVRFAcknowledgment(object): | |
78 def __init__(self, names=[], organizations=[], description=None, | |
79 url=None): | |
80 self._names = names | |
81 self._organizations = organizations | |
82 self._description = description | |
83 self._url = url | |
84 | |
85 def getTitle(self): | |
86 return "%s - %s" % (', '.join(self._names), | |
87 ', '.join(self._organizations)) | |
88 | |
89 def validate(self): | |
90 if (not self._names) and (not self._organizations) and (not self._description): | |
91 raise ValidationError('An Acknowledgment must have at least a Name, an Organization or a Description') | |
92 | |
93 |