develop
Самоукин Алексей 14 years ago
parent 154dcdf079
commit 392441d3a2

@ -25,6 +25,13 @@ from shutil import copytree, rmtree
import ctypes import ctypes
import cl_overriding import cl_overriding
import re import re
import sys
import getpass
import cl_lang
tr = cl_lang.lang()
tr.setLocalDomain('cl_lib')
tr.setLanguage(sys.modules[__name__])
class _error: class _error:
# Здесь ошибки, если они есть # Здесь ошибки, если они есть
@ -413,3 +420,30 @@ def pathJoin(*paths):
map(lambda x: x.startswith("/") and x[1:] or x, map(lambda x: x.startswith("/") and x[1:] or x,
paths[1:]),'')) paths[1:]),''))
def getUserPassword(flag="dialog", pwDialog=False):
"""Получить пароль у пользователя
flag - опция "dalog" или "stdin" - откуда получаем пароль
pwDialog - структура для вывода приглашения в режиме диалога
"""
userPwd = ""
if flag == "dialog":
if not pwDialog:
pwDialog = [_("New password"),
_("Retype new password")]
pwdA = getpass.getpass(pwDialog[0]+":")
pwdB = getpass.getpass(pwDialog[1]+":")
elif flag == "stdin":
pwdA = sys.stdin.readline().rstrip()
pwdB = sys.stdin.readline().rstrip()
else:
cl_overriding.printERROR(_("ERROR in function getUserPassword, \
incorrect option 'flag=%s'")%flag)
return False
if not pwdA or not (pwdA == pwdB):
cl_overriding.printERROR(_("ERROR") + ": " +\
_("password incorrect")+ ": " + _("try again"))
return False
userPwd = pwdA
return userPwd

@ -14,7 +14,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from cl_data import DataVars import sys
from cl_datavars import DataVars
from cl_print import color_print from cl_print import color_print
# Перевод модуля # Перевод модуля
import cl_lang import cl_lang

@ -328,32 +328,3 @@ in a sambaDomainName',
if you want to continue to run the program again")) if you want to continue to run the program again"))
return False return False
return isCorrectStringNet(strNet) return isCorrectStringNet(strNet)
def getUserPassword(self, options, optDialog, optStdIn, pwDialog=False):
"""Получить пароль у пользователя
options - полученные опции командной строки
optDialog - опция командной строки для вывода диалога для получения
пароля
optStdIn - опция командной строки для получения пароля из
стандартного ввода (stdin)
pwDialog - структура для вывода приглашения в режиме диалога
"""
userPwd = ""
if optStdIn and options.has_key(optStdIn):
pwdA = sys.stdin.readline().rstrip()
pwdB = sys.stdin.readline().rstrip()
elif optDialog and options.has_key(optDialog):
if not pwDialog:
pwDialog = [_("New password"),
_("Retype new password")]
pwdA = getpass.getpass(pwDialog[0]+":")
pwdB = getpass.getpass(pwDialog[1]+":")
if (optStdIn and options.has_key(optStdIn)) or\
(optDialog and options.has_key(optDialog)):
if not pwdA or not (pwdA == pwdB):
self.printERROR (_("ERROR") + ": " +\
_("password incorrect")+ ": " + _("try again"))
return False
userPwd = pwdA
return userPwd
Loading…
Cancel
Save