1 """
2 Holds information about what the user asked for (which program, version constraints, etc).
3 """
4
5
6
7
8 from zeroinstall import SafeException
9
11 """
12 Holds information about what the user asked for (which program, version constraints, etc).
13 """
14
15
16 __slots__ = [
17 'interface_uri',
18 'command',
19 'source',
20 'extra_restrictions',
21 'os', 'cpu',
22 'message',
23 ]
24
26 """@type interface_uri: str"""
27 self.interface_uri = interface_uri
28 self.command = 'run'
29 self.source = False
30 self.os = self.cpu = None
31 self.message = None
32 self.extra_restrictions = {}
33
35 self.extra_restrictions = self._handle_restrictions(options)
36
37 for uri, expr in self.extra_restrictions.items():
38 if not expr:
39 raise SafeException("Missing version expression for {uri}".format(uri = uri))
40
41 self.source = bool(options.source)
42 self.message = options.message
43
44 self.cpu = options.cpu
45 self.os = options.os
46
47
48 if options.command is None:
49 if self.source:
50 self.command = 'compile'
51 else:
52 self.command = 'run'
53 else:
54 self.command = options.command or None
55
57 """Update the settings based on the options (used for "0install update APP").
58 @return: whether any settings were changed
59 @rtype: bool
60 @since: 1.9"""
61 restriction_updates = self._handle_restrictions(options)
62
63 changed = False
64 for key in ['message', 'cpu', 'os', 'command']:
65 value = getattr(options, key)
66 if value is not None:
67 changed = changed or value != getattr(self, key)
68 setattr(self, key, value)
69
70 for uri, expr in restriction_updates.items():
71 old = self.extra_restrictions.get(uri, None)
72 changed = expr != old
73 if expr:
74 self.extra_restrictions[uri] = expr
75 elif uri in self.extra_restrictions:
76 del self.extra_restrictions[uri]
77
78 if options.source and not self.source:
79
80
81 raise SafeException("Can't update from binary to source type!")
82 return changed
83
85 """@rtype: [str]"""
86 gui_args = []
87 if self.extra_restrictions:
88
89 for uri, r in self.extra_restrictions.items():
90 gui_args.insert(0, r)
91 gui_args.insert(0, uri)
92 gui_args.insert(0, '--version-for')
93 if self.source:
94 gui_args.insert(0, '--source')
95 if self.message:
96 gui_args.insert(0, self.message)
97 gui_args.insert(0, '--message')
98 if self.cpu:
99 gui_args.insert(0, self.cpu)
100 gui_args.insert(0, '--cpu')
101 if self.os:
102 gui_args.insert(0, self.os)
103 gui_args.insert(0, '--os')
104 gui_args.append('--command')
105 gui_args.append(self.command or '')
106
107 return gui_args
108
117
119 """Gets the list of restrictions specified by the user.
120 Handles --before, --not-before, --version and --version-for options.
121 If a mapping isn't present, then the user didn't specify a restriction.
122 If an entry maps to None, the user wishes to remove the restriction."""
123 version = options.version
124
125 interface_uri = self.interface_uri
126
127
128 if options.before is not None or options.not_before is not None:
129 if version is not None:
130 raise SafeException("Can't use --before or --not-before with --version")
131 if options.before or options.not_before:
132 version = (options.not_before or '') + '..'
133 if options.before:
134 version += '!' + options.before
135 else:
136 version = ''
137
138 restrictions = dict((uri, (expr or None)) for (uri, expr) in (options.version_for or []))
139
140
141 if version is not None:
142 if interface_uri in restrictions:
143 raise SafeException("Can't use --version and --version-for to set {uri}".format(uri = interface_uri))
144 restrictions[interface_uri] = version or None
145
146 return restrictions
147