summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/crumbs/builder.py
diff options
context:
space:
mode:
authorShane Wang <shane.wang@intel.com>2012-05-22 19:33:23 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-22 14:56:15 +0100
commite069e53536e4894507a72da79e7e8af55a0d31b1 (patch)
tree5180cb5e2a1443b52cced8ac42dfd6d17c2c0a8f /bitbake/lib/bb/ui/crumbs/builder.py
parent33c4bf2096effc850720009564e3d1adbda24452 (diff)
downloadpoky-e069e53536e4894507a72da79e7e8af55a0d31b1.tar.gz
Hob: reimplement the proxy page
This patch is to reimplement the proxy page in the "Advanced Settings" dialog per the new design in https://bugzilla.yoctoproject.org/attachment.cgi?id=442 and https://bugzilla.yoctoproject.org/attachment.cgi?id=443. [Yocto #2247] (Bitbake rev: 911a60c09c1539a3f10c2bcdb26d40e458c31303) Signed-off-by: Shane Wang <shane.wang@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/builder.py')
-rwxr-xr-xbitbake/lib/bb/ui/crumbs/builder.py143
1 files changed, 106 insertions, 37 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/builder.py b/bitbake/lib/bb/ui/crumbs/builder.py
index 42d0f2ca0e..3282fdf52c 100755
--- a/bitbake/lib/bb/ui/crumbs/builder.py
+++ b/bitbake/lib/bb/ui/crumbs/builder.py
@@ -26,6 +26,7 @@ import copy
26import os 26import os
27import subprocess 27import subprocess
28import shlex 28import shlex
29import re
29from bb.ui.crumbs.template import TemplateMgr 30from bb.ui.crumbs.template import TemplateMgr
30from bb.ui.crumbs.imageconfigurationpage import ImageConfigurationPage 31from bb.ui.crumbs.imageconfigurationpage import ImageConfigurationPage
31from bb.ui.crumbs.recipeselectionpage import RecipeSelectionPage 32from bb.ui.crumbs.recipeselectionpage import RecipeSelectionPage
@@ -42,6 +43,44 @@ import bb.ui.crumbs.utils
42class Configuration: 43class Configuration:
43 '''Represents the data structure of configuration.''' 44 '''Represents the data structure of configuration.'''
44 45
46 @classmethod
47 def parse_proxy_string(cls, proxy):
48 pattern = "^\s*((http|https|ftp|git|cvs)://)?((\S+):(\S+)@)?(\S+):(\d+)/?"
49 match = re.search(pattern, proxy)
50 if match:
51 return match.group(2), match.group(4), match.group(5), match.group(6), match.group(7)
52 else:
53 return None, None, None, "", ""
54
55 @classmethod
56 def make_host_string(cls, prot, user, passwd, host, default_prot=""):
57 if host == None or host == "":
58 return ""
59
60 passwd = passwd or ""
61
62 if user != None and user != "":
63 if prot == None or prot == "":
64 prot = default_prot
65 return prot + "://" + user + ":" + passwd + "@" + host
66 else:
67 if prot == None or prot == "":
68 return host
69 else:
70 return prot + "://" + host
71
72 @classmethod
73 def make_port_string(cls, port):
74 port = port or ""
75 return port
76
77 @classmethod
78 def make_proxy_string(cls, prot, user, passwd, host, port, default_prot=""):
79 if host == None or host == "" or port == None or port == "":
80 return ""
81
82 return Configuration.make_host_string(prot, user, passwd, host, default_prot) + ":" + Configuration.make_port_string(port)
83
45 def __init__(self): 84 def __init__(self):
46 self.curr_mach = "" 85 self.curr_mach = ""
47 # settings 86 # settings
@@ -67,15 +106,43 @@ class Configuration:
67 self.default_task = "build" 106 self.default_task = "build"
68 107
69 # proxy settings 108 # proxy settings
70 self.all_proxy = self.http_proxy = self.ftp_proxy = self.https_proxy = "" 109 self.enable_proxy = None
71 self.git_proxy_host = self.git_proxy_port = "" 110 self.same_proxy = False
72 self.cvs_proxy_host = self.cvs_proxy_port = "" 111 self.proxies = {
112 "http" : [None, None, None, "", ""], # protocol : [prot, user, passwd, host, port]
113 "https" : [None, None, None, "", ""],
114 "ftp" : [None, None, None, "", ""],
115 "git" : [None, None, None, "", ""],
116 "cvs" : [None, None, None, "", ""],
117 }
73 118
74 def clear_selection(self): 119 def clear_selection(self):
75 self.selected_image = None 120 self.selected_image = None
76 self.selected_recipes = [] 121 self.selected_recipes = []
77 self.selected_packages = [] 122 self.selected_packages = []
78 123
124 def split_proxy(self, protocol, proxy):
125 entry = []
126 prot, user, passwd, host, port = Configuration.parse_proxy_string(proxy)
127 entry.append(prot)
128 entry.append(user)
129 entry.append(passwd)
130 entry.append(host)
131 entry.append(port)
132 self.proxies[protocol] = entry
133
134 def combine_proxy(self, protocol):
135 entry = self.proxies[protocol]
136 return Configuration.make_proxy_string(entry[0], entry[1], entry[2], entry[3], entry[4], protocol)
137
138 def combine_host_only(self, protocol):
139 entry = self.proxies[protocol]
140 return Configuration.make_host_string(entry[0], entry[1], entry[2], entry[3], protocol)
141
142 def combine_port_only(self, protocol):
143 entry = self.proxies[protocol]
144 return Configuration.make_port_string(entry[4])
145
79 def update(self, params): 146 def update(self, params):
80 # settings 147 # settings
81 self.curr_distro = params["distro"] 148 self.curr_distro = params["distro"]
@@ -99,14 +166,14 @@ class Configuration:
99 self.default_task = params["default_task"] 166 self.default_task = params["default_task"]
100 167
101 # proxy settings 168 # proxy settings
102 self.all_proxy = params["all_proxy"] 169 self.enable_proxy = params["http_proxy"] != "" or params["https_proxy"] != "" or params["ftp_proxy"] != "" \
103 self.http_proxy = params["http_proxy"] 170 or params["git_proxy_host"] != "" or params["git_proxy_port"] != "" \
104 self.ftp_proxy = params["ftp_proxy"] 171 or params["cvs_proxy_host"] != "" or params["cvs_proxy_port"] != ""
105 self.https_proxy = params["https_proxy"] 172 self.split_proxy("http", params["http_proxy"])
106 self.git_proxy_host = params["git_proxy_host"] 173 self.split_proxy("https", params["https_proxy"])
107 self.git_proxy_port = params["git_proxy_port"] 174 self.split_proxy("ftp", params["ftp_proxy"])
108 self.cvs_proxy_host = params["cvs_proxy_host"] 175 self.split_proxy("git", params["git_proxy_host"] + ":" + params["git_proxy_port"])
109 self.cvs_proxy_port = params["cvs_proxy_port"] 176 self.split_proxy("cvs", params["cvs_proxy_host"] + ":" + params["cvs_proxy_port"])
110 177
111 def load(self, template): 178 def load(self, template):
112 self.curr_mach = template.getVar("MACHINE") 179 self.curr_mach = template.getVar("MACHINE")
@@ -146,14 +213,13 @@ class Configuration:
146 self.selected_recipes = template.getVar("DEPENDS").split() 213 self.selected_recipes = template.getVar("DEPENDS").split()
147 self.selected_packages = template.getVar("IMAGE_INSTALL").split() 214 self.selected_packages = template.getVar("IMAGE_INSTALL").split()
148 # proxy 215 # proxy
149 self.all_proxy = template.getVar("all_proxy") 216 self.enable_proxy = eval(template.getVar("enable_proxy"))
150 self.http_proxy = template.getVar("http_proxy") 217 self.same_proxy = eval(template.getVar("use_same_proxy"))
151 self.ftp_proxy = template.getVar("ftp_proxy") 218 self.split_proxy("http", template.getVar("http_proxy"))
152 self.https_proxy = template.getVar("https_proxy") 219 self.split_proxy("https", template.getVar("https_proxy"))
153 self.git_proxy_host = template.getVar("GIT_PROXY_HOST") 220 self.split_proxy("ftp", template.getVar("ftp_proxy"))
154 self.git_proxy_port = template.getVar("GIT_PROXY_PORT") 221 self.split_proxy("git", template.getVar("GIT_PROXY_HOST") + ":" + template.getVar("GIT_PROXY_PORT"))
155 self.cvs_proxy_host = template.getVar("CVS_PROXY_HOST") 222 self.split_proxy("cvs", template.getVar("CVS_PROXY_HOST") + ":" + template.getVar("CVS_PROXY_PORT"))
156 self.cvs_proxy_port = template.getVar("CVS_PROXY_PORT")
157 223
158 def save(self, template, defaults=False): 224 def save(self, template, defaults=False):
159 # bblayers.conf 225 # bblayers.conf
@@ -183,14 +249,15 @@ class Configuration:
183 template.setVar("DEPENDS", self.selected_recipes) 249 template.setVar("DEPENDS", self.selected_recipes)
184 template.setVar("IMAGE_INSTALL", self.user_selected_packages) 250 template.setVar("IMAGE_INSTALL", self.user_selected_packages)
185 # proxy 251 # proxy
186 template.setVar("all_proxy", self.all_proxy) 252 template.setVar("enable_proxy", self.enable_proxy)
187 template.setVar("http_proxy", self.http_proxy) 253 template.setVar("use_same_proxy", self.same_proxy)
188 template.setVar("ftp_proxy", self.ftp_proxy) 254 template.setVar("http_proxy", self.combine_proxy("http"))
189 template.setVar("https_proxy", self.https_proxy) 255 template.setVar("https_proxy", self.combine_proxy("https"))
190 template.setVar("GIT_PROXY_HOST", self.git_proxy_host) 256 template.setVar("ftp_proxy", self.combine_proxy("ftp"))
191 template.setVar("GIT_PROXY_PORT", self.git_proxy_port) 257 template.setVar("GIT_PROXY_HOST", self.combine_host_only("git"))
192 template.setVar("CVS_PROXY_HOST", self.cvs_proxy_host) 258 template.setVar("GIT_PROXY_PORT", self.combine_port_only("git"))
193 template.setVar("CVS_PROXY_PORT", self.cvs_proxy_port) 259 template.setVar("CVS_PROXY_HOST", self.combine_host_only("cvs"))
260 template.setVar("CVS_PROXY_PORT", self.combine_port_only("cvs"))
194 261
195class Parameters: 262class Parameters:
196 '''Represents other variables like available machines, etc.''' 263 '''Represents other variables like available machines, etc.'''
@@ -212,7 +279,6 @@ class Parameters:
212 self.all_sdk_machines = [] 279 self.all_sdk_machines = []
213 self.all_layers = [] 280 self.all_layers = []
214 self.image_names = [] 281 self.image_names = []
215 self.enable_proxy = False
216 282
217 # for build log to show 283 # for build log to show
218 self.bb_version = "" 284 self.bb_version = ""
@@ -578,13 +644,18 @@ class Builder(gtk.Window):
578 self.handler.set_extra_inherit("packageinfo") 644 self.handler.set_extra_inherit("packageinfo")
579 self.handler.set_extra_inherit("image_types") 645 self.handler.set_extra_inherit("image_types")
580 # set proxies 646 # set proxies
581 if self.parameters.enable_proxy: 647 if self.configuration.enable_proxy == True:
582 self.handler.set_http_proxy(self.configuration.http_proxy) 648 self.handler.set_http_proxy(self.configuration.combine_proxy("http"))
583 self.handler.set_https_proxy(self.configuration.https_proxy) 649 self.handler.set_https_proxy(self.configuration.combine_proxy("https"))
584 self.handler.set_ftp_proxy(self.configuration.ftp_proxy) 650 self.handler.set_ftp_proxy(self.configuration.combine_proxy("ftp"))
585 self.handler.set_all_proxy(self.configuration.all_proxy) 651 self.handler.set_git_proxy(self.configuration.combine_host_only("git"), self.configuration.combine_port_only("git"))
586 self.handler.set_git_proxy(self.configuration.git_proxy_host, self.configuration.git_proxy_port) 652 self.handler.set_cvs_proxy(self.configuration.combine_host_only("cvs"), self.configuration.combine_port_only("cvs"))
587 self.handler.set_cvs_proxy(self.configuration.cvs_proxy_host, self.configuration.cvs_proxy_port) 653 elif self.configuration.enable_proxy == False:
654 self.handler.set_http_proxy("")
655 self.handler.set_https_proxy("")
656 self.handler.set_ftp_proxy("")
657 self.handler.set_git_proxy("", "")
658 self.handler.set_cvs_proxy("", "")
588 659
589 def update_recipe_model(self, selected_image, selected_recipes): 660 def update_recipe_model(self, selected_image, selected_recipes):
590 self.recipe_model.set_selected_image(selected_image) 661 self.recipe_model.set_selected_image(selected_image)
@@ -996,7 +1067,6 @@ class Builder(gtk.Window):
996 all_distros = self.parameters.all_distros, 1067 all_distros = self.parameters.all_distros,
997 all_sdk_machines = self.parameters.all_sdk_machines, 1068 all_sdk_machines = self.parameters.all_sdk_machines,
998 max_threads = self.parameters.max_threads, 1069 max_threads = self.parameters.max_threads,
999 enable_proxy = self.parameters.enable_proxy,
1000 parent = self, 1070 parent = self,
1001 flags = gtk.DIALOG_MODAL 1071 flags = gtk.DIALOG_MODAL
1002 | gtk.DIALOG_DESTROY_WITH_PARENT 1072 | gtk.DIALOG_DESTROY_WITH_PARENT
@@ -1008,7 +1078,6 @@ class Builder(gtk.Window):
1008 response = dialog.run() 1078 response = dialog.run()
1009 settings_changed = False 1079 settings_changed = False
1010 if response == gtk.RESPONSE_YES: 1080 if response == gtk.RESPONSE_YES:
1011 self.parameters.enable_proxy = dialog.enable_proxy
1012 self.configuration = dialog.configuration 1081 self.configuration = dialog.configuration
1013 self.save_defaults() # remember settings 1082 self.save_defaults() # remember settings
1014 settings_changed = dialog.settings_changed 1083 settings_changed = dialog.settings_changed