3 # Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 from daklib.dbconn import *
32 dak import <suite> <component> <files...>
35 -h, --help: show this help message
36 -a, --add-overrides: add missing overrides automatically
37 -c, --changed-by: Changed-By for imported source packages
39 -s, --ignore-signature: ignore signature for imported source packages
41 WARNING: This command does no sanity checks. Only use it on trusted packages.
44 def import_source(transaction, suite, component, directory, filename,
45 changed_by=None, keyrings=None, require_signature=True,
49 session = transaction.session
51 source = daklib.upload.Source.from_file(directory, filename, keyrings, require_signature)
53 if source.valid_signature:
54 fingerprint = session.query(Fingerprint).filter_by(fingerprint=source.primary_fingerprint).one()
55 if changed_by is None:
56 changed_by = source.dsc['Maintainer']
57 db_changed_by = get_or_set_maintainer(changed_by, session)
59 transaction.install_source(directory, source, suite, component, db_changed_by, fingerprint=fingerprint)
61 if add_overrides and not session.query(Override).filter_by(suite=suite.get_overridesuite(), component=component, package=source.dsc['Source']).join(OverrideType).filter(OverrideType.overridetype == 'dsc').first():
62 overridetype = session.query(OverrideType).filter_by(overridetype='dsc').one()
63 overridesuite = suite.get_overridesuite()
65 if component.component_name != 'main':
66 section_name = "{0}/{1}".format(component.component_name, section_name)
67 section = session.query(Section).filter_by(section=section).one()
68 priority = session.query(Priority).filter_by(priority='extra').one()
70 override = Override(package=control.dsc['Source'], suite=overridesuite, component=component,
71 section=section, priority=priority, overridetype=overridetype)
74 def import_binary(transaction, suite, component, directory, filename, add_overrides=False):
75 session = transaction.session
77 binary = daklib.upload.Binary.from_file(directory, filename)
78 transaction.install_binary(directory, binary, suite, component)
80 if add_overrides and not session.query(Override).filter_by(suite=suite.get_overridesuite(), component=component, package=binary.control['Package']).join(OverrideType).filter(OverrideType.overridetype == binary.type).first():
81 overridetype = session.query(OverrideType).filter_by(overridetype=binary.type).one()
82 overridesuite = suite.get_overridesuite()
83 section = session.query(Section).filter_by(section=binary.control['Section']).one()
84 priority = session.query(Priority).filter_by(priority=binary.control['Priority']).one()
86 override = Override(package=binary.control['Package'], suite=overridesuite, component=component,
87 section=section, priority=priority, overridetype=overridetype)
90 def import_file(transaction, suite, component, directory, filename,
91 changed_by=None, keyrings=None, require_signature=False,
92 add_overrides = False):
96 if daklib.regexes.re_file_binary.match(filename):
97 import_binary(transaction, suite, component, directory, filename, add_overrides)
98 elif daklib.regexes.re_file_dsc.match(filename):
99 import_source(transaction, suite, component, directory, filename,
100 changed_by=changed_by, keyrings=keyrings,
101 require_signature=require_signature, add_overrides=add_overrides)
103 raise Exception('File is neither source nor binary package: {0}'.format(filename))
110 ('h', 'help', 'Import::Options::Help'),
111 ('a', 'add-overrides', 'Import::Options::AddOverrides'),
112 ('c', 'changed-by', 'Import::Options::ChangedBy', 'HasArg'),
113 ('s', 'ignore-signature', 'Import::Options::IgnoreSignature'),
116 cnf = daklib.config.Config()
117 cnf['Import::Options::Dummy'] = ''
118 argv = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
119 options = cnf.subtree('Import::Options')
121 if 'Help' in options or len(argv) < 3:
126 component_name = argv[1]
129 add_overrides = options.find_b('AddOverrides')
130 require_signature = not options.find_b('IgnoreSignature')
131 changed_by = options.find('ChangedBy') or None
133 with daklib.archive.ArchiveTransaction() as transaction:
134 session = transaction.session
135 suite = session.query(Suite).filter_by(suite_name=suite_name).one()
136 component = session.query(Component).filter_by(component_name=component_name).one()
137 keyrings = session.query(Keyring).filter_by(active=True).order_by(Keyring.priority)
138 keyring_files = [ k.keyring_name for k in keyrings ]
141 directory, filename = os.path.split(os.path.abspath(f))
142 import_file(transaction, suite, component, directory, filename,
143 changed_by=changed_by,
144 keyrings=keyring_files, require_signature=require_signature,
145 add_overrides=add_overrides)
149 if __name__ == '__main__':