#
# Copyright (c) 2008 rPath, Inc.
#

import os

from rmakeplugin import rMakePlugin

class rMakeProxy(rMakePlugin):
    name = 'rmakeproxy'

    def pluginMethod(self):

        self._setupProxy()
        self._seutprBuilder()

    def _setupProxy(self):
        proxycfg = '/etc/rmake/server.d/proxy'

        if 'conaryproxy' in self.rmakecfg:
            proxy = self.rmakecfg['conaryproxy']
        else:
            host = self.id.getLocalHostname()

        fh = open(proxycfg, 'w')
        fh.write('proxy http://%s:7778/' % host)

    def _setuprBuilder(self):
        rbuildercfg = '/etc/rmake/server.d/rbuilder'

        if 'rbuilderurl' in self.rmakecfg:
            fh = open(rbuildercfg, 'w')
            fh.write('rbuilderUrl %s\n' % self.rmakecfg['rbuilderurl'])

@@ -90,21 +90,22 @@
 ss rMake
-Proxy
+Server
 (rMakePl
@@ -128,21 +128,22 @@
 = 'rmake
-proxy
+server
 '%0A%0A    d
@@ -165,17 +165,16 @@
 (self):%0A
-%0A
         
@@ -212,10 +212,10 @@
 ._se
-u
 t
+u
 prBu
@@ -221,16 +221,45 @@
 uilder()
+%0A        self._setupRepoUrl()
 %0A%0A    de
@@ -552,16 +552,18 @@
 %25s:7778/
+%5Cn
 ' %25 host
@@ -724,32 +724,32 @@
 uildercfg, 'w')%0A
-
             fh.w
@@ -804,8 +804,336 @@
 rurl'%5D)%0A
+%0A    def _setupRepoUrl(self):%0A        repourlcfg = '/etc/rmake/server.d/serverurl'%0A%0A        if 'serverurl' in self.rmakecfg:%0A            url = self.rmakecfg%5B'serverurl'%5D%0A        else:%0A            url = 'http://%25s/conary/' %25 self.id.getLocalHostname()%0A%0A        fh = open(repourlcfg, 'w')%0A        fh.write('serverUrl %25s%5Cn' %25 url)%0A

add repo url config