1 |
commit: 7a6764b06e02586172b5bb34c3989d490289ddda |
2 |
Author: Magnus Granberg <zorry <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Apr 28 16:00:52 2012 +0000 |
4 |
Commit: Magnus Granberg <zorry <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Apr 28 16:00:52 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=dev/zorry.git;a=commit;h=7a6764b0 |
7 |
|
8 |
add logging and multiprocessing to gobs_setup_profile |
9 |
|
10 |
--- |
11 |
gobs/bin/gobs_setup_profile | 8 +++ |
12 |
gobs/pym/init_setup_profile.py | 122 +++++++++++++++++++++++---------------- |
13 |
2 files changed, 80 insertions(+), 50 deletions(-) |
14 |
|
15 |
diff --git a/gobs/bin/gobs_setup_profile b/gobs/bin/gobs_setup_profile |
16 |
index 902ffe8..9a1dd04 100755 |
17 |
--- a/gobs/bin/gobs_setup_profile |
18 |
+++ b/gobs/bin/gobs_setup_profile |
19 |
@@ -3,9 +3,17 @@ |
20 |
# Distributed under the terms of the GNU General Public License v2 |
21 |
|
22 |
from gobs.init_setup_profile import setup_profile_main |
23 |
+from gobs.readconf import get_conf_settings |
24 |
+reader = get_conf_settings() |
25 |
+gobs_settings_dict=reader.read_gobs_settings_all() |
26 |
+ |
27 |
+import logging |
28 |
|
29 |
def main(): |
30 |
# Main |
31 |
+ # Logging |
32 |
+ logging.basicConfig(filename=gobs_settings_dict['gobs_logfile'], \ |
33 |
+ format='%(levelname)s: %(asctime)s %(message)s', level=logging.INFO) |
34 |
setup_profile_main(args=None) |
35 |
|
36 |
if __name__ == "__main__": |
37 |
|
38 |
diff --git a/gobs/pym/init_setup_profile.py b/gobs/pym/init_setup_profile.py |
39 |
index e647e1f..a18865e 100644 |
40 |
--- a/gobs/pym/init_setup_profile.py |
41 |
+++ b/gobs/pym/init_setup_profile.py |
42 |
@@ -7,6 +7,7 @@ |
43 |
|
44 |
import sys |
45 |
import os |
46 |
+import logging |
47 |
|
48 |
# Get the options from the config file set in gobs.readconf |
49 |
from gobs.readconf import get_conf_settings |
50 |
@@ -19,9 +20,42 @@ CM=connectionManager(gobs_settings_dict) |
51 |
if CM.getName()=='pgsql': |
52 |
from gobs.pgsql import * |
53 |
|
54 |
-from gobs.check_setup import check_make_conf, git_pull |
55 |
+from gobs.check_setup import check_make_conf |
56 |
+from gobs.sync import git_pull |
57 |
from gobs.package import gobs_package |
58 |
import portage |
59 |
+import multiprocessing |
60 |
+def add_cpv_query_pool(init_package, config_id_list, package_line) |
61 |
+ conn=CM.getConnection() |
62 |
+ # FIXME: remove the check for gobs when in tree |
63 |
+ if package_line != "dev-python/gobs": |
64 |
+ build_dict = {} |
65 |
+ packageDict = {} |
66 |
+ ebuild_id_list = [] |
67 |
+ # split the cp to categories and package |
68 |
+ element = package_line.split('/') |
69 |
+ categories = element[0] |
70 |
+ package = element[1] |
71 |
+ logging.info"C %s/%s", categories, package # C = Checking |
72 |
+ pkgdir = mysettings['PORTDIR'] + "/" + categories + "/" + package |
73 |
+ config_cpv_listDict = init_package.config_match_ebuild(categories, package, config_id_list) |
74 |
+ if config_cpv_listDict != {}: |
75 |
+ cpv = categories + "/" + package + "-" + config_cpv_listDict[config_id]['ebuild_version'] |
76 |
+ attDict = {} |
77 |
+ attDict['categories'] = categories |
78 |
+ attDict['package'] = package |
79 |
+ attDict['ebuild_version_tree'] = config_cpv_listDict[config_id]['ebuild_version'] |
80 |
+ packageDict[cpv] = attDict |
81 |
+ build_dict['checksum'] = portage.checksum.sha256hash(pkgdir + "/" + package + "-" + config_cpv_listDict[config_id]['ebuild_version'] + ".ebuild")[0] |
82 |
+ build_dict['package_id'] = have_package_db(conn, categories, package)[0] |
83 |
+ build_dict['ebuild_version'] = config_cpv_listDict[config_id]['ebuild_version'] |
84 |
+ ebuild_id = get_ebuild_id_db_checksum(conn, build_dict) |
85 |
+ if ebuild_id is not None: |
86 |
+ ebuild_id_list.append(ebuild_id) |
87 |
+ init_package.add_new_ebuild_buildquery_db(ebuild_id_list, packageDict, config_cpv_listDict) |
88 |
+ logging.info"C %s/%s ... Done.", categories, package |
89 |
+ CM.putConnection(conn) |
90 |
+ return |
91 |
|
92 |
def setup_profile_main(args=None): |
93 |
""" |
94 |
@@ -31,56 +65,44 @@ def setup_profile_main(args=None): |
95 |
conn=CM.getConnection() |
96 |
if args is None: |
97 |
args = sys.argv[1:] |
98 |
- if args[0] == "-add": |
99 |
- git_pull() |
100 |
- check_make_conf() |
101 |
- print "Check configs done" |
102 |
- # Get default config from the configs table and default_config=1 |
103 |
- config_id = args[1] |
104 |
- default_config_root = "/var/lib/gobs/" + gobs_settings_dict['gobs_gitreponame'] + "/" + config_id + "/" |
105 |
- # Set config_root (PORTAGE_CONFIGROOT) to default_config_root |
106 |
- mysettings = portage.config(config_root = default_config_root) |
107 |
- myportdb = portage.portdbapi(mysettings=mysettings) |
108 |
- init_package = gobs_package(mysettings, myportdb) |
109 |
- # get the cp list |
110 |
- package_list_tree = package_list_tree = myportdb.cp_all() |
111 |
- print "Setting default config to:", config_id |
112 |
- config_id_list = [] |
113 |
- config_id_list.append(config_id) |
114 |
- for package_line in sorted(package_list_tree): |
115 |
- # FIXME: remove the check for gobs when in tree |
116 |
- if package_line != "dev-python/gobs": |
117 |
- build_dict = {} |
118 |
- packageDict = {} |
119 |
- ebuild_id_list = [] |
120 |
- # split the cp to categories and package |
121 |
- element = package_line.split('/') |
122 |
- categories = element[0] |
123 |
- package = element[1] |
124 |
- print "C", categories + "/" + package # C = Checking |
125 |
- pkgdir = mysettings['PORTDIR'] + "/" + categories + "/" + package |
126 |
- config_cpv_listDict = init_package.config_match_ebuild(categories, package, config_id_list) |
127 |
- if config_cpv_listDict != {}: |
128 |
- cpv = categories + "/" + package + "-" + config_cpv_listDict[config_id]['ebuild_version'] |
129 |
- attDict = {} |
130 |
- attDict['categories'] = categories |
131 |
- attDict['package'] = package |
132 |
- attDict['ebuild_version_tree'] = config_cpv_listDict[config_id]['ebuild_version'] |
133 |
- packageDict[cpv] = attDict |
134 |
- build_dict['checksum'] = portage.checksum.sha256hash(pkgdir + "/" + package + "-" + config_cpv_listDict[config_id]['ebuild_version'] + ".ebuild")[0] |
135 |
- build_dict['package_id'] = have_package_db(conn, categories, package)[0] |
136 |
- build_dict['ebuild_version'] = config_cpv_listDict[config_id]['ebuild_version'] |
137 |
- ebuild_id = get_ebuild_id_db_checksum(conn, build_dict) |
138 |
- if ebuild_id is not None: |
139 |
- ebuild_id_list.append(ebuild_id) |
140 |
- init_package.add_new_ebuild_buildquery_db(ebuild_id_list, packageDict, config_cpv_listDict) |
141 |
+ if args[0] == "-add": |
142 |
+ config_id = args[1] |
143 |
+ logging.info("Adding build querys for %s:", config_id) |
144 |
+ git_pull() |
145 |
+ check_make_conf() |
146 |
+ logging.info("Check configs done") |
147 |
+ # Get default config from the configs table and default_config=1 |
148 |
+ default_config_root = "/var/lib/gobs/" + gobs_settings_dict['gobs_gitreponame'] + "/" + config_id + "/" |
149 |
+ # Set config_root (PORTAGE_CONFIGROOT) to default_config_root |
150 |
+ mysettings = portage.config(config_root = default_config_root) |
151 |
+ myportdb = portage.portdbapi(mysettings=mysettings) |
152 |
+ init_package = gobs_package(mysettings, myportdb) |
153 |
+ # get the cp list |
154 |
+ package_list_tree = package_list_tree = myportdb.cp_all() |
155 |
+ logging.info("Setting default config to:", config_id) |
156 |
+ config_id_list = [] |
157 |
+ config_id_list.append(config_id) |
158 |
+ # Use all exept 2 cores when multiprocessing |
159 |
+ pool_cores= multiprocessing.cpu_count() |
160 |
+ if pool_cores >= 3: |
161 |
+ use_pool_cores = pool_cores - 2 |
162 |
+ else: |
163 |
+ use_pool_cores = 1 |
164 |
+ pool = multiprocessing.Pool(processes=use_pool_cores) |
165 |
+ for package_line in sorted(package_list_tree): |
166 |
+ pool.apply_async(add_cpv_query_pool, (init_package, config_id_list, package_line,)) |
167 |
+ pool.close() |
168 |
+ pool.join() |
169 |
+ logging.info("Adding build querys for: %s ... Done.", config_id) |
170 |
|
171 |
- if args[0] == "-del": |
172 |
- config_id = args[1] |
173 |
- querue_id_list = get_queue_id_list_config(conn, config_id) |
174 |
- if querue_id_list is not None: |
175 |
- for querue_id in querue_id_list: |
176 |
- del_old_queue(conn, querue_id) |
177 |
+ if args[0] == "-del": |
178 |
+ config_id = args[1] |
179 |
+ logging.info("Removeing build querys for %s:", config_id) |
180 |
+ querue_id_list = get_queue_id_list_config(conn, config_id) |
181 |
+ if querue_id_list is not None: |
182 |
+ for querue_id in querue_id_list: |
183 |
+ del_old_queue(conn, querue_id) |
184 |
+ logging.info("Removeing build querys for: %s ... Done.", config_id) |
185 |
CM.putConnection(conn) |
186 |
|
187 |
|
188 |
\ No newline at end of file |