Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2bca2122
Kaydet (Commit)
2bca2122
authored
May 10, 2008
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#1858: add distutils.config module
üst
fe598518
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
0 deletions
+124
-0
config.py
Lib/distutils/config.py
+124
-0
No files found.
Lib/distutils/config.py
0 → 100644
Dosyayı görüntüle @
2bca2122
"""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