-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate-rpmfind-db
executable file
·93 lines (83 loc) · 3.8 KB
/
populate-rpmfind-db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/var/www/rpm2python/venv/bin/python
""" Utility to update rpmfind database """
###############################################################################
#Programmer: Orcan Ogetbil [email protected] #
#Date: 08/12/2010 #
#Filename: populate-rpmfind-db #
# #
# #
# Copyright 2010 Orcan Ogetbil #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
###############################################################################
import sys
sys.path.append('/var/www/rpm2python/rpm2python')
import _mysql
import _mysql_exceptions
from MySQLdb.constants import FIELD_TYPE
import os
import rcommon
import populatedb
from optparse import OptionParser
import logging
import string
import time
my_config_file='/etc/populate-rpmfind-db.cfg'
""" Utility to update rpmfind database """
os.umask(002)
myapp = rcommon.AppHandler(verifyuser=True,config_file=my_config_file)
parser = OptionParser("usage: %prog [options]")
parser.add_option("-r", "--rebuild",
default=False,
action="store_true",
help="Cleans and rebuilds the whole database.")
parser.add_option("-v",
"--verbose",
default=False,
action="store_true",
help="Verbose output")
parser.add_option("-d", "--distver",
action="store", type="string", dest="distver", default="",
help="Populate only specific distver (give option as number)")
(options, args) = parser.parse_args(sys.argv[1:])
myapp.create_lock()
if options.verbose:
verbosity = logging.DEBUG
else:
verbosity = logging.INFO
myapp.init_logger(verbosity)
if options.rebuild:
my_conv = { FIELD_TYPE.LONG: int }
db_host = myapp.config.get("rpmdb", "host")
db_user = myapp.config.get("rpmdb", "user")
db_pw = myapp.config.get("rpmdb", "password")
db_name = myapp.config.get("rpmdb", "name")
dbase = _mysql.connect(db_host, db_user, db_pw, db_name, conv=my_conv)
populatedb.clean_database(myapp, dbase)
populatedb.create_tables(myapp, dbase)
dbase.close()
distname = myapp.config.get("repositories", "distname_nice")
alldistvers = myapp.config.get("repositories", "alldistvers").split()
if options.distver == "":
for distver in alldistvers:
myapp.distver = distver
myapp.logger.info("Populating rpmfind database for {0} {1}...".format(
distname, distver))
populatedb.update_db(myapp)
else:
myapp.distver = options.distver
myapp.logger.info("Populating rpmfind database for {0} {1}...".format(
distname, options.distver))
populatedb.update_db(myapp)
timerun = myapp.time_run()
myapp.logger.info("\nSuccess! Time run: " + str(timerun) + " s")
myapp.exit()