Gentoo Archives: gentoo-commits

From: Magnus Granberg <zorry@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] dev/zorry:master commit in: gobs/bin/
Date: Fri, 27 Apr 2012 20:59:47
Message-Id: 1335560350.327266bf7d8956adb90e073f1d41d6a101545e54.zorry@gentoo
1 commit: 327266bf7d8956adb90e073f1d41d6a101545e54
2 Author: Magnus Granberg <zorry <AT> gentoo <DOT> org>
3 AuthorDate: Fri Apr 27 20:59:10 2012 +0000
4 Commit: Magnus Granberg <zorry <AT> gentoo <DOT> org>
5 CommitDate: Fri Apr 27 20:59:10 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=dev/zorry.git;a=commit;h=327266bf
7
8 Add logging sync.py part2
9
10 ---
11 gobs/bin/gobs_updatedb~ | 128 -----------------------------------------------
12 1 files changed, 0 insertions(+), 128 deletions(-)
13
14 diff --git a/gobs/bin/gobs_updatedb~ b/gobs/bin/gobs_updatedb~
15 deleted file mode 100755
16 index 4dce5ce..0000000
17 --- a/gobs/bin/gobs_updatedb~
18 +++ /dev/null
19 @@ -1,128 +0,0 @@
20 -#!/usr/bin/python
21 -# Copyright 2006-2011 Gentoo Foundation
22 -# Distributed under the terms of the GNU General Public License v2
23 -
24 -""" This code will update the sql backend with needed info for
25 - the Frontend and the Guest deamon. """
26 -
27 -import sys
28 -import os
29 -import multiprocessing
30 -import logging
31 -
32 -# Get the options from the config file set in gobs.readconf
33 -from gobs.readconf import get_conf_settings
34 -reader = get_conf_settings()
35 -gobs_settings_dict=reader.read_gobs_settings_all()
36 -logfile = gobs_settings_dict['gobs_logfile']
37 -
38 -# make a CM
39 -from gobs.ConnectionManager import connectionManager
40 -CM=connectionManager(gobs_settings_dict)
41 -#selectively import the pgsql/mysql querys
42 -if CM.getName()=='pgsql':
43 - from gobs.pgsql import *
44 -
45 -from gobs.check_setup import check_make_conf
46 -from gobs.arch import gobs_arch
47 -from gobs.package import gobs_package
48 -from gobs.categories import gobs_categories
49 -from gobs.old_cpv import gobs_old_cpv
50 -from gobs.categories import gobs_categories
51 -from gobs.sync import git_pull, sync_tree
52 -import portage
53 -
54 -def init_portage_settings():
55 -
56 - """ Get the BASE Setup/Config for portage.settings
57 - @type: module
58 - @module: The SQL Backend
59 - @type: dict
60 - @parms: config options from the config file (host_setup_root)
61 - @rtype: settings
62 - @returns new settings
63 - """
64 - # check config setup
65 - #git stuff
66 - conn=CM.getConnection()
67 - check_make_conf()
68 - logging.info("Check configs done")
69 - # Get default config from the configs table and default_config=1
70 - config_id = get_default_config(conn) # HostConfigDir = table configs id
71 - CM.putConnection(conn);
72 - default_config_root = "/var/lib/gobs/" + gobs_settings_dict['gobs_gitreponame'] + "/" + config_id[0] + "/"
73 - # Set config_root (PORTAGE_CONFIGROOT) to default_config_root
74 - mysettings = portage.config(config_root = default_config_root)
75 - logging.info("Setting default config to:", config_id[0])
76 - return mysettings
77 -
78 -def update_cpv_db_pool(mysettings, package_line):
79 - conn=CM.getConnection()
80 - # Setup portdb, gobs_categories, gobs_old_cpv, package
81 - myportdb = portage.portdbapi(mysettings=mysettings)
82 - init_categories = gobs_categories(mysettings)
83 - init_package = gobs_package(mysettings, myportdb)
84 - # split the cp to categories and package
85 - element = package_line.split('/')
86 - categories = element[0]
87 - package = element[1]
88 - # Check if we don't have the cp in the package table
89 - package_id = have_package_db(conn,categories, package)
90 - if package_id is None:
91 - # Add new package with ebuilds
92 - init_package.add_new_package_db(categories, package)
93 - # Ceck if we have the cp in the package table
94 - elif package_id is not None:
95 - # Update the packages with ebuilds
96 - init_package.update_package_db(categories, package, package_id)
97 - # Update the metadata for categories
98 - init_categories.update_categories_db(categories)
99 - CM.putConnection(conn)
100 -
101 -def update_cpv_db(mysettings):
102 - """Code to update the cpv in the database.
103 - @type:settings
104 - @parms: portage.settings
105 - @type: module
106 - @module: The SQL Backend
107 - @type: dict
108 - @parms: config options from the config file
109 - """
110 - print "Checking categories, package, ebuilds"
111 - # Setup portdb, gobs_categories, gobs_old_cpv, package
112 - myportdb = portage.portdbapi(mysettings=mysettings)
113 - package_id_list_tree = []
114 - # Will run some update checks and update package if needed
115 - # Get categories/package list from portage
116 - package_list_tree = myportdb.cp_all()
117 - # Use all exept 2 cores when multiprocessing
118 - pool_cores= multiprocessing.cpu_count()
119 - if pool_cores > "3":
120 - use_pool_cores = pool_cores - 2
121 - else:
122 - use_pool_cores = 1
123 - pool = multiprocessing.Pool(processes=use_pool_cores)
124 - # Run the update package for all package in the list in
125 - # a multiprocessing pool
126 - for package_line in sorted(package_list_tree):
127 - pool.apply_async(update_cpv_db_pool, (mysettings, package_line,))
128 - pool.close()
129 - pool.join()
130 - print "Checking categories, package and ebuilds done"
131 -
132 -def main():
133 - # Main
134 - # Logging
135 - logging.basicConfig(filename=gobs_settings_dict['gobs_logfile'], level=logging.INFO)
136 - # Init settings for the default config
137 - git_pull
138 - sync_tree()
139 - mysettings = init_portage_settings()
140 - init_arch = gobs_arch()
141 - init_arch.update_arch_db()
142 - # Update the cpv db
143 - update_cpv_db(mysettings)
144 - CM.closeAllConnections()
145 -
146 -if __name__ == "__main__":
147 - main()
148 \ No newline at end of file