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
31413a7b
Kaydet (Commit)
31413a7b
authored
Haz 04, 2000
tarafından
Greg Ward
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
and added 'ensure_dirname()'.
üst
4227dc1b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
1 deletion
+72
-1
cmd.py
Lib/distutils/cmd.py
+72
-1
No files found.
Lib/distutils/cmd.py
Dosyayı görüntüle @
31413a7b
...
...
@@ -9,7 +9,7 @@ in the distutils.command package.
__revision__
=
"$Id$"
import
sys
,
os
,
string
import
sys
,
os
,
string
,
re
from
types
import
*
from
distutils.errors
import
*
from
distutils
import
util
...
...
@@ -173,6 +173,77 @@ class Command:
print
msg
# -- Option validation methods -------------------------------------
# (these are very handy in writing the 'finalize_options()' method)
#
# NB. the general philosophy here is to ensure that a particular option
# value meets certain type and value constraints. If not, we try to
# force it into conformance (eg. if we expect a list but have a string,
# split the string on comma and/or whitespace). If we can't force the
# option into conformance, raise DistutilsOptionError. Thus, command
# classes need do nothing more than (eg.)
# self.ensure_string_list('foo')
# and they can be guaranteed that thereafter, self.foo will be
# a list of strings.
def
_ensure_stringlike
(
self
,
option
,
what
,
default
=
None
):
val
=
getattr
(
self
,
option
)
if
val
is
None
:
setattr
(
self
,
option
,
default
)
return
default
elif
type
(
val
)
is
not
StringType
:
raise
DistutilsOptionError
,
\
"'
%
s' must be a
%
s (got `
%
s`)"
%
(
option
,
what
,
val
)
return
val
def
ensure_string
(
self
,
option
,
default
=
None
):
"""Ensure that 'option' is a string; if not defined, set it to
'default'.
"""
self
.
_ensure_stringlike
(
option
,
"string"
,
default
)
def
ensure_string_list
(
self
,
option
):
"""Ensure that 'option' is a list of strings. If 'option' is
currently a string, we split it either on /,
\
s*/ or /
\
s+/, so
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
["foo", "bar", "baz"].
"""
val
=
getattr
(
self
,
option
)
if
val
is
None
:
return
elif
type
(
val
)
is
StringType
:
setattr
(
self
,
option
,
re
.
split
(
r',\s*|\s+'
,
val
))
else
:
if
type
(
val
)
is
ListType
:
types
=
map
(
type
,
val
)
ok
=
(
types
==
[
StringType
]
*
len
(
val
))
else
:
ok
=
0
if
not
ok
:
raise
DistutilsOptionError
,
\
"'
%
s' must be a list of strings (got
%
s)"
%
\
(
option
,
`val`
)
def
_ensure_tested_string
(
self
,
option
,
tester
,
what
,
error_fmt
,
default
=
None
):
val
=
self
.
_ensure_stringlike
(
option
,
what
,
default
)
if
val
is
not
None
and
not
tester
(
val
):
raise
DistutilsOptionError
,
\
(
"error in '
%
s' option: "
+
error_fmt
)
%
(
option
,
val
)
def
ensure_filename
(
self
,
option
):
"""Ensure that 'option' is the name of an existing file."""
self
.
_ensure_tested_string
(
option
,
os
.
path
.
isfile
,
"filename"
,
"'
%
s' does not exist or is not a file"
)
def
ensure_dirname
(
self
,
option
):
self
.
_ensure_tested_string
(
option
,
os
.
path
.
isdir
,
"directory name"
,
"'
%
s' does not exist or is not a directory"
)
# -- Convenience methods for commands ------------------------------
def
get_command_name
(
self
):
...
...
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