~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/env python
8687.15.22 by Karl Fogel
Add the copyright header block to the remaining .py files.
2
# Copyright 2009 Canonical Ltd.  This software is licensed under the
3
# GNU Affero General Public License version 3 (see the file LICENSE).
3258.8.2 by Andrew Bennetts
Script to generate MD5 sums for existing librarian content.
4
5
"""Script to generate SQL to add MD5 sums for existing librarian files."""
6
7
__metaclass__ = type
8
9
import commands
8847.1.1 by Celso Providelo
Integrating the tree script checker into the test suite.
10
import os
11
import sys
3258.8.2 by Andrew Bennetts
Script to generate MD5 sums for existing librarian content.
12
13
SQL = "UPDATE LibraryFileContent SET md5 = '%s' WHERE id = %d;"
14
15
16
def main(path, minimumID=0):
17
    if not path.endswith('/'):
18
        path += '/'
19
20
    for dirpath, dirname, filenames in os.walk(path):
21
        dirname.sort()
22
        databaseID = dirpath[len(path):]
23
        if not len(databaseID) == 8: # "xx/xx/xx"
24
            continue
25
        for filename in filenames:
26
            databaseID = int(databaseID.replace('/', '') + filename, 16)
27
            if databaseID < minimumID:
28
                continue
29
            filename = os.path.join(dirpath, filename)
30
            md5sum = commands.getoutput('md5sum ' + filename).split(' ', 1)[0]
31
            yield databaseID, md5sum
32
33
if __name__ == '__main__':
34
    if len(sys.argv) > 2:
35
        minimumID = int(sys.argv[2])
36
    else:
37
        minimumID = 0
38
    for databaseID, md5sum in main(sys.argv[1], minimumID):
39
        print SQL % (md5sum, databaseID)