Merged '0install' command branch
[zeroinstall/zeroinstall-afb.git] / zeroinstall / injector / requirements.py
blobc1a0bd7d212e5fff9bf3b195d05f87acdeab008a
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 from zeroinstall import _
10 class Requirements(object):
11 """
12 Holds information about what the user asked for (which program, version constraints, etc).
13 """
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 get_as_options(self):
51 gui_args = []
52 if self.not_before:
53 gui_args.insert(0, self.not_before)
54 gui_args.insert(0, '--not-before')
55 if self.before:
56 gui_args.insert(0, self.before)
57 gui_args.insert(0, '--before')
58 if self.source:
59 gui_args.insert(0, '--source')
60 if self.message:
61 gui_args.insert(0, self.message)
62 gui_args.insert(0, '--message')
63 if self.cpu:
64 gui_args.insert(0, self.cpu)
65 gui_args.insert(0, '--cpu')
66 if self.os:
67 gui_args.insert(0, self.os)
68 gui_args.insert(0, '--os')
69 gui_args.append('--command')
70 gui_args.append(self.command or '')
72 return gui_args