~ubuntu-branches/ubuntu/quantal/ubuntu-system-service/quantal

« back to all changes in this revision

Viewing changes to UbuntuSystemService/backend.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Rodrigo Moya
  • Date: 2012-01-10 09:59:59 UTC
  • Revision ID: package-import@ubuntu.com-20120110095959-bkzo6eymzuj9qjim
Tags: 0.2.2
[ Rodrigo Moya ]
* merged lp:~rodrigo-moya/system-service/fix-877088:
  - only write apt proxy to a single file

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
                         os.listdir(os.path.join(confdir,"apt.conf.d"))]
125
125
        apt_conffiles.insert(0, os.path.join(confdir,"apt.conf"))
126
126
        # then scan them for the content
 
127
        already_saved = False
127
128
        for f in apt_conffiles:
128
129
            new_content = []
129
130
            found = False
130
 
            for line in open(f):
131
 
                # Only replace the Acquire::%s::proxy entry, not other more
132
 
                # complicated forms of the proxy settings
133
 
                if line.lower().startswith("acquire::%s::proxy " % proxy_type):
134
 
                    found = True
135
 
                    line = "Acquire::%s::proxy \"%s\";\n" % (proxy_type, new_proxy)
136
 
                new_content.append(line)
137
 
            # if we found/replaced the proxy, write it out now
138
 
            if not found:
 
131
            try:
 
132
                file = open(f)
 
133
                for line in file:
 
134
                    # Only replace the Acquire::%s::proxy entry, not other more
 
135
                    # complicated forms of the proxy settings
 
136
                    if line.lower().startswith("acquire::%s::proxy " % proxy_type):
 
137
                        if already_saved:
 
138
                            continue
 
139
                        found = True
 
140
                        line = "Acquire::%s::proxy \"%s\";\n" % (proxy_type, new_proxy)
 
141
                        already_saved = True
 
142
                    new_content.append(line)
 
143
            except Exception:
 
144
                pass
 
145
 
 
146
            # if we didn't find the proxy, write it out now
 
147
            if not found and not already_saved:
139
148
                new_content.append("Acquire::%s::proxy \"%s\";\n" % (proxy_type, new_proxy))
 
149
                already_saved = True
140
150
            open(f,"w").write("".join(new_content))
 
151
 
141
152
        return True
142
153
 
143
154
    def _write_etc_environment_proxy(self, proxy_type, new_proxy):