当前位置: 首页>>代码示例>>Python>>正文


Python typing.Text方法代码示例

本文整理汇总了Python中typing.Text方法的典型用法代码示例。如果您正苦于以下问题:Python typing.Text方法的具体用法?Python typing.Text怎么用?Python typing.Text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在typing的用法示例。


在下文中一共展示了typing.Text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_username

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def set_username(username: Optional[Text] = None,
                 prompt: Optional[Text] = None) -> Text:
  """Sets the username in the registry.

  Optionally prompts if there is no username supplied as a parameter.

  Args:
    username: Value to set as the username in registry.
    prompt: Custom string to append to username prompt.

  Returns:
    username: The determined username.

  Raises:
    Error: Failed to set username in registry.
  """
  if not username:
    username = interact.GetUsername(prompt)
  try:
    registry.set_value('Username', username)
  except registry.Error as e:
    raise Error(str(e))

  return username 
开发者ID:google,项目名称:glazier,代码行数:26,代码来源:identity.py

示例2: set_hostname

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def set_hostname(hostname: Optional[Text] = None) -> Text:
  """Sets the hostname in the registry.

   Gets hostname from socket.hostname if no hostname is passed.

  Args:
    hostname: Value to set as the hostname in registry.

  Returns:
    hostname: The determined hostname.

  Raise:
    Error: Failed to set hostname in registry.
  """
  if not hostname:
    hostname = socket.gethostname()

  hostname = hostname.strip()

  try:
    registry.set_value('Name', hostname)
  except registry.Error as e:
    raise Error(str(e))

  return hostname 
开发者ID:google,项目名称:glazier,代码行数:27,代码来源:identity.py

示例3: _GetHash

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def _GetHash(self, file_path: Text) -> bytes:
    """Calculates the hash of the boot wim.

    Args:
      file_path: path to the file to be hashed

    Returns:
      hash of boot wim in hex
    """
    block_size = 33554432  # define bytes to read at a time when hashing (32mb)
    hasher = hashlib.sha256()

    with open(file_path, 'rb') as f:
      fb = f.read(block_size)
      while fb:
        hasher.update(fb)
        fb = f.read(block_size)
    return base64.b64encode(hasher.digest()) 
开发者ID:google,项目名称:glazier,代码行数:20,代码来源:beyondcorp.py

示例4: _EventLogUpload

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def _EventLogUpload(self, source_log: Text):
    """Upload the log file contents to the local EventLog."""
    event_handler = logging.handlers.NTEventLogHandler('GlazierBuildLog')
    logger = logging.Logger('eventlogger')
    logger.addHandler(event_handler)
    logger.setLevel(logging.DEBUG)

    try:
      with open(source_log, 'r') as f:
        content = f.readlines()
        for line in content:
          logger.info(line)
    except IOError:
      raise LogCopyError(
          'Unable to open log file. It will not be imported into '
          'the Windows Event Log.') 
开发者ID:google,项目名称:glazier,代码行数:18,代码来源:log_copy.py

示例5: _ShareUpload

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def _ShareUpload(self, source_log: Text, share: Text):
    """Copy the log file to a network file share.

    Args:
      source_log: Path to the source log file to be copied.
      share: The destination share to copy the file to.

    Raises:
      LogCopyError: Failure to mount share and copy log.
    """
    creds = LogCopyCredentials()
    username = creds.GetUsername()
    password = creds.GetPassword()

    mapper = drive_map.DriveMap()
    result = mapper.MapDrive('l:', share, username, password)
    if result:
      destination = self._GetLogFileName()
      try:
        shutil.copy(source_log, destination)
      except shutil.Error:
        raise LogCopyError('Log copy failed.')
      mapper.UnmapDrive('l:')
    else:
      raise LogCopyError('Drive mapping failed.') 
开发者ID:google,项目名称:glazier,代码行数:27,代码来源:log_copy.py

示例6: Transform

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def Transform(string: Text, build_info) -> Text:
  r"""Transforms abbreviated file names to absolute file paths.

  Short name support:
    #: A reference to the active release branch location.
    @: A reference to the binary storage root.
    \#: Escaped # character - replaced by # in string
    \@: Escaped @ character - replaced by @ in string

  Args:
    string: The configuration string to be transformed.
    build_info: the current build information

  Returns:
    The adjusted file name string to be used in the manifest.
  """
  string = re.sub(r'(?<!\\)#', PathCompile(build_info) + '/', string)
  string = re.sub(r'\\#', '#', string)
  string = re.sub(r'(?<!\\)@', str(build_info.BinaryPath()), string)
  string = re.sub(r'\\@', '@', string)
  return string 
开发者ID:google,项目名称:glazier,代码行数:23,代码来源:download.py

示例7: _ConvertBytes

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def _ConvertBytes(self, num_bytes: int) -> Text:
    """Converts number of bytes to a human readable format.

    Args:
      num_bytes: The number to convert to a more human readable format (int).

    Returns:
      size: The number of bytes in human readable format (string).
    """
    num_bytes = float(num_bytes)
    if num_bytes >= 1099511627776:
      terabytes = num_bytes / 1099511627776
      size = '%.2fTB' % terabytes
    elif num_bytes >= 1073741824:
      gigabytes = num_bytes / 1073741824
      size = '%.2fGB' % gigabytes
    elif num_bytes >= 1048576:
      megabytes = num_bytes / 1048576
      size = '%.2fMB' % megabytes
    elif num_bytes >= 1024:
      kilobytes = num_bytes / 1024
      size = '%.2fKB' % kilobytes
    else:
      size = '%.2fB' % num_bytes
    return size 
开发者ID:google,项目名称:glazier,代码行数:27,代码来源:download.py

示例8: _SetUrl

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def _SetUrl(self, url: Text):
    """Simple helper function to determine signed URL.

    Args:
      url: the url we want to download from.

    Returns:
      A string with the applicable URLs

    Raises:
      DownloadError: Failed to obtain SignedURL.
    """
    if not FLAGS.use_signed_url:
      return url
    config_server = '%s%s' % (FLAGS.config_server, '/')
    try:
      return self._beyondcorp.GetSignedUrl(
          url[url.startswith(config_server) and len(config_server):])
    except beyondcorp.BCError as e:
      raise DownloadError(e) 
开发者ID:google,项目名称:glazier,代码行数:22,代码来源:download.py

示例9: ActiveConfigPath

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def ActiveConfigPath(self,
                       append: Optional[Text] = None,
                       pop: bool = False,
                       set_to: Optional[List[Text]] = None) -> List[Text]:
    """Tracks the active configuration path beneath the config root.

    Use append/pop for directory traversal.

    Args:
      append: Append a string to the active config path.
      pop: Pop the rightmost string from the active config path.
      set_to: Set the config path to an entirely new path.

    Returns:
      The active config path after any modifications.
    """
    if append:
      self._active_conf_path.append(append)
    elif set_to:
      self._active_conf_path = set_to
    elif pop and self._active_conf_path:
      self._active_conf_path.pop()
    return self._active_conf_path 
开发者ID:google,项目名称:glazier,代码行数:25,代码来源:buildinfo.py

示例10: EncryptionLevel

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def EncryptionLevel(self) -> Text:
    """Determines what encryption level is required for this machine.

    Returns:
      The required encryption type as a string (none, tpm)
    """
    if self.IsVirtual():
      logging.info(
          'Virtual machine type %s does not require full disk '
          'encryption.', self.ComputerModel())
      return 'none'

    logging.info('Machine %s requires full disk encryption.',
                 self.ComputerModel())

    if self.TpmPresent():
      logging.info('TPM detected - using TPM encryption.')
      return 'tpm'

    logging.info('No TPM was detected in this machine.')
    return 'tpm' 
开发者ID:google,项目名称:glazier,代码行数:23,代码来源:buildinfo.py

示例11: OsCode

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def OsCode(self) -> Text:
    """Return the OS code associated with this build.

    Returns:
      the os code as a string

    Raises:
      Error: Reference to an unknown operating system.
    """
    os = self.ComputerOs()
    release_info = self._ReleaseInfo()
    if 'os_codes' in release_info:
      os_codes = release_info['os_codes']
      if os in os_codes:
        return os_codes[os]['code']
    raise Error('Unknown OS [%s]' % os) 
开发者ID:google,项目名称:glazier,代码行数:18,代码来源:buildinfo.py

示例12: Branch

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def Branch(self) -> Text:
    """Determine the current build branch.

    Returns:
      The build branch as a string.

    Raises:
      Error: Reference to an unknown operating system.
    """
    versions = self.KnownBranches()
    comp_os = self.ComputerOs()
    if not comp_os:
      raise Error('Unable to determine host OS.')
    if comp_os in versions:
      return versions[comp_os]
    raise Error('Unable to find a release that supports %s.' % comp_os) 
开发者ID:google,项目名称:glazier,代码行数:18,代码来源:buildinfo.py

示例13: check_id

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def check_id() -> Text:
  """Call set_id if image identifier is not set and in WinPE.

  Check build_info (dumped via buildinfodump) in host if image_id does
  not exist.

  Returns:
    Image identifier as a string if already set.
  """
  image_id = None
  try:
    image_id = registry.get_value('image_id')
  except registry.Error as e:
    logging.error(str(e))

  if image_id:
    return image_id
  if winpe.check_winpe():
    return _set_id()

  return _check_file() 
开发者ID:google,项目名称:glazier,代码行数:23,代码来源:identifier.py

示例14: _LaunchPs

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def _LaunchPs(self, op: Text,
                args: List[Text],
                ok_result: Optional[List[int]] = None) -> int:
    """Launch the powershell executable to run a script.

    Args:
      op: -Command or -File
      args: any additional commandline args as a list
      ok_result: a list of acceptable exit codes; default is 0

    Returns:
      Process returncode if successfully exited.

    Raises:
      PowerShellError: failure to execute powershell command cleanly
    """
    if op not in ['-Command', '-File']:
      raise PowerShellError('Unsupported PowerShell parameter: %s' % op)

    try:
      return execute.execute_binary(_Powershell(),
                                    ['-NoProfile', '-NoLogo', op] + args,
                                    ok_result, self.shell, self.log)
    except execute.Error as e:
      raise PowerShellError(str(e)) 
开发者ID:google,项目名称:glazier,代码行数:27,代码来源:powershell.py

示例15: RunCommand

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Text [as 别名]
def RunCommand(self,
                 command: List[Text],
                 ok_result: Optional[List[int]] = None) -> int:
    """Run a powershell script on the local filesystem.

    Args:
      command: a list containing the command and all accompanying arguments
      ok_result: a list of acceptable exit codes; default is 0

    Returns:
      Process returncode if successfully exited.
    """
    assert isinstance(command, list), 'command must be passed as a list'
    if ok_result:
      assert isinstance(ok_result,
                        list), 'result codes must be passed as a list'
    return self._LaunchPs('-Command', command, ok_result) 
开发者ID:google,项目名称:glazier,代码行数:19,代码来源:powershell.py


注:本文中的typing.Text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。