Fixed bug where PackageKit downloaded the wrong architecture
[zeroinstall/solver.git] / zeroinstall / injector / requirements.py
blob3015a0cf8c926002e9e4968fd6fe1b30fe9f523c
1 """
2 Holds information about what the user asked for (which program, version constraints, etc).
3 """
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 class Requirements(object):
9 """
10 Holds information about what the user asked for (which program, version constraints, etc).
11 """
13 # Note: apps.py serialises our __slots__
14 __slots__ = [
15 'interface_uri',
16 'command',
17 'source',
18 'before', 'not_before',
19 'os', 'cpu',
20 'message',
23 def __init__(self, interface_uri):
24 self.interface_uri = interface_uri
25 self.command = 'run'
26 self.source = False
27 self.before = self.not_before = None
28 self.os = self.cpu = None
29 self.message = None
31 def parse_options(self, options):
32 self.not_before = options.not_before
33 self.before = options.before
35 self.source = bool(options.source)
36 self.message = options.message
38 self.cpu = options.cpu
39 self.os = options.os
41 # (None becomes 'run', while '' becomes None)
42 if options.command is None:
43 if self.source:
44 self.command = 'compile'
45 else:
46 self.command = 'run'
47 else:
48 self.command = options.command or None
50 def parse_update_options(self, options):
51 """Update the settings based on the options (used for "0install update APP").
52 @return: whether any settings were changed
53 @rtype: bool
54 @since: 1.9"""
55 changed = False
56 for key in ['not_before', 'before', 'message', 'cpu', 'os', 'command']:
57 value = getattr(options, key)
58 if value is not None:
59 changed = changed or value != getattr(self, key)
60 setattr(self, key, value)
61 if options.source and not self.source:
62 # (partly because it doesn't make much sense, and partly because you
63 # can't undo it, as there's no --not-source option)
64 from zeroinstall import SafeException
65 raise SafeException("Can't update from binary to source type!")
66 return changed
68 def get_as_options(self):
69 gui_args = []
70 if self.not_before:
71 gui_args.insert(0, self.not_before)
72 gui_args.insert(0, '--not-before')
73 if self.before:
74 gui_args.insert(0, self.before)
75 gui_args.insert(0, '--before')
76 if self.source:
77 gui_args.insert(0, '--source')
78 if self.message:
79 gui_args.insert(0, self.message)
80 gui_args.insert(0, '--message')
81 if self.cpu:
82 gui_args.insert(0, self.cpu)
83 gui_args.insert(0, '--cpu')
84 if self.os:
85 gui_args.insert(0, self.os)
86 gui_args.insert(0, '--os')
87 gui_args.append('--command')
88 gui_args.append(self.command or '')
90 return gui_args