[Piuparts-devel] Chroot.create_apt_conf

Herbert Fortes terberh at gmail.com
Sat Feb 23 17:53:50 GMT 2019


On 2/23/19 9:35 AM, Herbert Fortes wrote:
> On 2/21/19 1:17 PM, Herbert Fortes wrote:
>> On 2/21/19 11:37 AM, Andreas Beckmann wrote:
>>> Did someone consider using
>>>
>>> apt-config dump Acquire::http::Proxy
>>>
>>
>> What I should did at first.
> 
> 
> Patch with Andreas tips:
> 
> https://github.com/hpfn-d/piuparts_3/pull/23/commits/d1ec2798d4a170efaab739fe7988de5e8e056d8b

Heads up! 'acquire_string' for settings.proxy and os.environ.

acquire_string = 'Acquire::http::Proxy "%s";\n'
if settings.proxy:
    proxy = acquire_string % settings.proxy
elif "http_proxy" in os.environ:
    proxy = acquire_string % os.environ["http_proxy"]
else:
    subprocess stuff

https://github.com/hpfn-d/piuparts_3/pull/23/commits/0515ca5375bf682b1a1178368f064b7be4ce559e




> 
> proxy will be '' or the entire text (PY2 and Py3).
> 
>>>> import subprocess
>>>> p = subprocess.Popen(['apt-config', 'dump', 'Acquire::http::Proxy'], stdout=subprocess.PIPE, encoding='utf-8')
>>>> s, _ = p.communicate()
>>>> if s: print(s)
> ... 
> Acquire::http::Proxy "http://www.proxy.com:89/";
> 
>>>>
> 
> In version 3.3 timeout was added to p.communicate()
> https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
> 
> 
> 
> Regards,
> Herbert
> 
> obs: lines does not need to be a list(). Or at least 
>      the first 4 lines.append() are not necessary.
> 
>      The way it was written looks like a string '+='.  Using
>      a string concat, the "''.join()" is not needed when 
>      'create_file()'.
>      
>      IMO string concat is better than a list() in this case.
> 




More information about the Piuparts-devel mailing list