Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fc02aef0
Commit
fc02aef0
authored
May 15, 2008
by
Alexandre Vassalotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed configparser import in distutils.config.
parent
1d1eaa45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
0 deletions
+124
-0
Lib/distutils/config.py
Lib/distutils/config.py
+124
-0
No files found.
Lib/distutils/config.py
0 → 100644
View file @
fc02aef0
"""distutils.pypirc
Provides the PyPIRCCommand class, the base class for the command classes
that uses .pypirc in the distutils.command package.
"""
import
os
import
sys
from
configparser
import
ConfigParser
from
distutils.core
import
Command
DEFAULT_PYPIRC
=
"""
\
[pypirc]
servers =
pypi
[pypi]
username:%s
password:%s
"""
class
PyPIRCCommand
(
Command
):
"""Base command that knows how to handle the .pypirc file
"""
DEFAULT_REPOSITORY
=
'http://pypi.python.org/pypi'
DEFAULT_REALM
=
'pypi'
repository
=
None
realm
=
None
user_options
=
[
(
'repository='
,
'r'
,
"url of repository [default: %s]"
%
\
DEFAULT_REPOSITORY
),
(
'show-response'
,
None
,
'display full response text from server'
)]
boolean_options
=
[
'show-response'
]
def
_get_rc_file
(
self
):
"""Returns rc file path."""
return
os
.
path
.
join
(
os
.
path
.
expanduser
(
'~'
),
'.pypirc'
)
def
_store_pypirc
(
self
,
username
,
password
):
"""Creates a default .pypirc file."""
rc
=
self
.
_get_rc_file
()
f
=
open
(
rc
,
'w'
)
try
:
f
.
write
(
DEFAULT_PYPIRC
%
(
username
,
password
))
finally
:
f
.
close
()
try
:
os
.
chmod
(
rc
,
0600
)
except
OSError
:
# should do something better here
pass
def
_read_pypirc
(
self
):
"""Reads the .pypirc file."""
rc
=
self
.
_get_rc_file
()
if
os
.
path
.
exists
(
rc
):
print
'Using PyPI login from %s'
%
rc
repository
=
self
.
repository
or
self
.
DEFAULT_REPOSITORY
realm
=
self
.
realm
or
self
.
DEFAULT_REALM
config
=
ConfigParser
()
config
.
read
(
rc
)
sections
=
config
.
sections
()
if
'distutils'
in
sections
:
# let's get the list of servers
index_servers
=
config
.
get
(
'distutils'
,
'index-servers'
)
_servers
=
[
server
.
strip
()
for
server
in
index_servers
.
split
(
'
\
n
'
)
if
server
.
strip
()
!=
''
]
if
_servers
==
[]:
# nothing set, let's try to get the default pypi
if
'pypi'
in
sections
:
_servers
=
[
'pypi'
]
else
:
# the file is not properly defined, returning
# an empty dict
return
{}
for
server
in
_servers
:
current
=
{
'server'
:
server
}
current
[
'username'
]
=
config
.
get
(
server
,
'username'
)
current
[
'password'
]
=
config
.
get
(
server
,
'password'
)
# optional params
for
key
,
default
in
((
'repository'
,
self
.
DEFAULT_REPOSITORY
),
(
'realm'
,
self
.
DEFAULT_REALM
)):
if
config
.
has_option
(
server
,
key
):
current
[
key
]
=
config
.
get
(
server
,
key
)
else
:
current
[
key
]
=
default
if
(
current
[
'server'
]
==
repository
or
current
[
'repository'
]
==
repository
):
return
current
elif
'server-login'
in
sections
:
# old format
server
=
'server-login'
if
config
.
has_option
(
server
,
'repository'
):
repository
=
config
.
get
(
server
,
'repository'
)
else
:
repository
=
self
.
DEFAULT_REPOSITORY
return
{
'username'
:
config
.
get
(
server
,
'username'
),
'password'
:
config
.
get
(
server
,
'password'
),
'repository'
:
repository
,
'server'
:
server
,
'realm'
:
self
.
DEFAULT_REALM
}
return
{}
def
initialize_options
(
self
):
"""Initialize options."""
self
.
repository
=
None
self
.
realm
=
None
self
.
show_response
=
0
def
finalize_options
(
self
):
"""Finalizes options."""
if
self
.
repository
is
None
:
self
.
repository
=
self
.
DEFAULT_REPOSITORY
if
self
.
realm
is
None
:
self
.
realm
=
self
.
DEFAULT_REALM
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