Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
02abac66
Commit
02abac66
authored
May 17, 2014
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use context managers to reliably close files
parent
95ca7733
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
22 deletions
+10
-22
ez_setup.py
ez_setup.py
+10
-22
No files found.
ez_setup.py
View file @
02abac66
...
@@ -183,14 +183,11 @@ def has_powershell():
...
@@ -183,14 +183,11 @@ def has_powershell():
if
platform
.
system
()
!=
'Windows'
:
if
platform
.
system
()
!=
'Windows'
:
return
False
return
False
cmd
=
[
'powershell'
,
'-Command'
,
'echo test'
]
cmd
=
[
'powershell'
,
'-Command'
,
'echo test'
]
devnull
=
open
(
os
.
path
.
devnull
,
'wb'
)
with
open
(
os
.
path
.
devnull
,
'wb'
)
as
devnull
:
try
:
try
:
try
:
subprocess
.
check_call
(
cmd
,
stdout
=
devnull
,
stderr
=
devnull
)
subprocess
.
check_call
(
cmd
,
stdout
=
devnull
,
stderr
=
devnull
)
except
Exception
:
except
Exception
:
return
False
return
False
finally
:
devnull
.
close
()
return
True
return
True
download_file_powershell
.
viable
=
has_powershell
download_file_powershell
.
viable
=
has_powershell
...
@@ -201,14 +198,11 @@ def download_file_curl(url, target):
...
@@ -201,14 +198,11 @@ def download_file_curl(url, target):
def
has_curl
():
def
has_curl
():
cmd
=
[
'curl'
,
'--version'
]
cmd
=
[
'curl'
,
'--version'
]
devnull
=
open
(
os
.
path
.
devnull
,
'wb'
)
with
open
(
os
.
path
.
devnull
,
'wb'
)
as
devnull
:
try
:
try
:
try
:
subprocess
.
check_call
(
cmd
,
stdout
=
devnull
,
stderr
=
devnull
)
subprocess
.
check_call
(
cmd
,
stdout
=
devnull
,
stderr
=
devnull
)
except
Exception
:
except
Exception
:
return
False
return
False
finally
:
devnull
.
close
()
return
True
return
True
download_file_curl
.
viable
=
has_curl
download_file_curl
.
viable
=
has_curl
...
@@ -219,14 +213,11 @@ def download_file_wget(url, target):
...
@@ -219,14 +213,11 @@ def download_file_wget(url, target):
def
has_wget
():
def
has_wget
():
cmd
=
[
'wget'
,
'--version'
]
cmd
=
[
'wget'
,
'--version'
]
devnull
=
open
(
os
.
path
.
devnull
,
'wb'
)
with
open
(
os
.
path
.
devnull
,
'wb'
)
as
devnull
:
try
:
try
:
try
:
subprocess
.
check_call
(
cmd
,
stdout
=
devnull
,
stderr
=
devnull
)
subprocess
.
check_call
(
cmd
,
stdout
=
devnull
,
stderr
=
devnull
)
except
Exception
:
except
Exception
:
return
False
return
False
finally
:
devnull
.
close
()
return
True
return
True
download_file_wget
.
viable
=
has_wget
download_file_wget
.
viable
=
has_wget
...
@@ -240,19 +231,16 @@ def download_file_insecure(url, target):
...
@@ -240,19 +231,16 @@ def download_file_insecure(url, target):
from
urllib.request
import
urlopen
from
urllib.request
import
urlopen
except
ImportError
:
except
ImportError
:
from
urllib2
import
urlopen
from
urllib2
import
urlopen
src
=
dst
=
None
src
=
urlopen
(
url
)
try
:
try
:
src
=
urlopen
(
url
)
# Read all the data in one block.
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data
=
src
.
read
()
data
=
src
.
read
()
dst
=
open
(
target
,
"wb"
)
dst
.
write
(
data
)
finally
:
finally
:
if
src
:
src
.
close
()
src
.
close
()
if
dst
:
# Write all the data in one block to avoid creating a partial file.
dst
.
close
()
with
open
(
target
,
"wb"
)
as
dst
:
dst
.
write
(
data
)
download_file_insecure
.
viable
=
lambda
:
True
download_file_insecure
.
viable
=
lambda
:
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment