]> git.decadent.org.uk Git - dak.git/blob - dak/import_new_files.py
67fdf33d961a9cebc092b700ea8469549361de07
[dak.git] / dak / import_new_files.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Import known_changes files
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009  Mike O'Connor <stew@debian.org>
9 @license: GNU General Public License version 2 or later
10 """
11
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 ################################################################################
27
28
29 ################################################################################
30
31 import sys
32 import os
33 import logging
34 import threading
35 import glob
36 from daklib.dbconn import DBConn, get_dbchange
37 from daklib.config import Config
38
39 # where in dak.conf all of our configuration will be stowed
40 options_prefix = "NewFiles"
41 options_prefix = "%s::Options" % options_prefix
42
43 log = logging.getLogger()
44
45 ################################################################################
46
47
48 def usage (exit_code=0):
49     print """Usage: dak import-new-files [options]
50
51 OPTIONS
52      -v, --verbose
53         show verbose information messages
54
55      -q, --quiet
56         supress all output but errors
57
58 """
59     sys.exit(exit_code)
60
61 class ImportKnownChanges(object):
62     @session_wrapper
63     def __init__(self, session=None):
64         try:
65             newq = get_policy_queue('new', session)
66             for changes_fn in glob.glob(newq.path + "/*.changes"):
67                 changes_bn = os.path.basename(fn)
68                 chg = session.query(DBChange).filter_by(changesname=changes_bn).one()
69
70                 u = Upload()
71                 u.changes_file = changes_fn
72                 u.load_changes(changes_fn)
73
74                 for chg_fn in u.pkg.files.keys():
75                     cpf = ChangePendingFile()
76                     cpf.filename = chg_fn
77                     cpf.size = self.files[chg_fn]['size']
78                     cpf.md5sum = self.files[chg_fn]['md5sum']
79
80                     session.add(cpf)
81                     chg.files.append(cpf)
82
83
84             session.commit()
85             
86         except KeyboardInterrupt:
87             print("Caught C-c; terminating.")
88             utils.warn("Caught C-c; terminating.")
89             self.plsDie()
90
91
92 def main():
93     cnf = Config()
94
95     arguments = [('h',"help", "%s::%s" % (options_prefix,"Help")),
96                  ('q',"quiet", "%s::%s" % (options_prefix,"Quiet")),
97                  ('v',"verbose", "%s::%s" % (options_prefix,"Verbose")),
98                 ]
99
100     args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments,sys.argv)
101
102     num_threads = 1
103
104     if len(args) > 0:
105         usage(1)
106
107     if cnf.has_key("%s::%s" % (options_prefix,"Help")):
108         usage(0)
109
110     level=logging.INFO
111     if cnf.has_key("%s::%s" % (options_prefix,"Quiet")):
112         level=logging.ERROR
113
114     elif cnf.has_key("%s::%s" % (options_prefix,"Verbose")):
115         level=logging.DEBUG
116
117
118     logging.basicConfig( level=level,
119                          format='%(asctime)s %(levelname)s %(message)s',
120                          stream = sys.stderr )
121
122     ImportNewFiles()
123
124
125 if __name__ == '__main__':
126     main()