~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
14612.2.7 by William Grant
scripts
13
3258.8.2 by Andrew Bennetts
Script to generate MD5 sums for existing librarian content.
14
SQL = "UPDATE LibraryFileContent SET md5 = '%s' WHERE id = %d;"
15
16
17
def main(path, minimumID=0):
18
    if not path.endswith('/'):
19
        path += '/'
20
21
    for dirpath, dirname, filenames in os.walk(path):
22
        dirname.sort()
23
        databaseID = dirpath[len(path):]
24
        if not len(databaseID) == 8: # "xx/xx/xx"
25
            continue
26
        for filename in filenames:
27
            databaseID = int(databaseID.replace('/', '') + filename, 16)
28
            if databaseID < minimumID:
29
                continue
30
            filename = os.path.join(dirpath, filename)
31
            md5sum = commands.getoutput('md5sum ' + filename).split(' ', 1)[0]
32
            yield databaseID, md5sum
33
34
if __name__ == '__main__':
35
    if len(sys.argv) > 2:
36
        minimumID = int(sys.argv[2])
37
    else:
38
        minimumID = 0
39
    for databaseID, md5sum in main(sys.argv[1], minimumID):
40
        print SQL % (md5sum, databaseID)