當前位置: 首頁>>代碼示例>>Python>>正文


Python os.html方法代碼示例

本文整理匯總了Python中os.html方法的典型用法代碼示例。如果您正苦於以下問題:Python os.html方法的具體用法?Python os.html怎麽用?Python os.html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.html方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: send_sigint

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def send_sigint(self):
        # `signal.CTRL_C_EVENT` is also sent to the test process itself.
        # See https://docs.python.org/3.6/library/os.html#os.kill
        # So we need to wait the signal and ignore it.
        # We can NOT ignore the signal by modifying the signal handler here.
        # If we temporary ignores the signal, the signal will sent again
        # when the signal handler is restored.
        # If we ignore the signal permanently, we couldn't interrupt the test.
        if os.name == 'nt':
            try:
                os.kill(self.p.pid, signal.CTRL_C_EVENT)
                while True:
                    pass
            except KeyboardInterrupt:
                pass
        else:
            os.kill(self.p.pid, signal.SIGINT) 
開發者ID:chainer,項目名稱:chainer,代碼行數:19,代碼來源:test_multiprocess_iterator.py

示例2: run

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def run(command):
    # TODO: replace this with fork()
    #       (https://docs.python.org/2/library/os.html#os.fork)
    pid = 0
    if pid == 0:
        # This is the child, we'll try to do some containment here
        try:
            contain(command)
        except Exception:
            traceback.print_exc()
            os._exit(1)  # something went wrong in contain()

    # This is the parent, pid contains the PID of the forked process
    # wait for the forked child and fetch the exit status
    _, status = os.waitpid(pid, 0)
    print('{} exited with status {}'.format(pid, status)) 
開發者ID:Fewbytes,項目名稱:rubber-docker,代碼行數:18,代碼來源:rd.py

示例3: rename

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def rename(src, dst):
  """os.rename(src, dst) wrapper with support for long paths on Windows.

  Availability: Unix, Windows."""
  if isWindows():
    # On Windows, rename fails if destination exists, see
    # https://docs.python.org/2/library/os.html#os.rename
    try:
      os.rename(_makelongpath(src), _makelongpath(dst))
    except OSError as e:
      if e.errno == errno.EEXIST:
        os.remove(_makelongpath(dst))
        os.rename(_makelongpath(src), _makelongpath(dst))
      else:
        raise
  else:
    os.rename(src, dst) 
開發者ID:GerritCodeReview,項目名稱:git-repo,代碼行數:19,代碼來源:platform_utils.py

示例4: system

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def system():
    import platform
    # On some Windows installation (Python 2.4) platform.system() is
    # broken and incorrectly returns 'Microsoft' instead of 'Windows'.
    # http://mail.python.org/pipermail/patches/2007-June/022947.html
    syst = platform.system()
    if syst == 'Microsoft':
        return 'Windows'
    return syst


# Set and get environment variables does not handle unicode strings correctly
# on Windows.

# Acting on os.environ instead of using getenv()/setenv()/unsetenv(),
# as suggested in <http://docs.python.org/library/os.html#os.environ>:
# "Calling putenv() directly does not change os.environ, so it's
# better to modify os.environ." (Same for unsetenv.) 
開發者ID:Lithium876,項目名稱:ConTroll_Remote_Access_Trojan,代碼行數:20,代碼來源:compat.py

示例5: test_set_config_value_file_permissions

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def test_set_config_value_file_permissions(self):
        self.cli_config.set_value('test_section', 'test_option', 'a_value')
        file_mode = os.stat(self.cli_config.config_path).st_mode
        self.assertTrue(bool(file_mode & stat.S_IRUSR))
        self.assertTrue(bool(file_mode & stat.S_IWUSR))
        # only S_IRUSR and S_IWUSR are supported on Windows: https://docs.python.org/3.8/library/os.html#os.chmod
        if os.name != 'nt':
            self.assertFalse(bool(file_mode & stat.S_IXUSR))
            self.assertFalse(bool(file_mode & stat.S_IRGRP))
            self.assertFalse(bool(file_mode & stat.S_IWGRP))
            self.assertFalse(bool(file_mode & stat.S_IXGRP))
            self.assertFalse(bool(file_mode & stat.S_IROTH))
            self.assertFalse(bool(file_mode & stat.S_IWOTH))
            self.assertFalse(bool(file_mode & stat.S_IXOTH)) 
開發者ID:microsoft,項目名稱:knack,代碼行數:16,代碼來源:test_config.py

示例6: fsync

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def fsync(self):
        if self._oplog:
            # https://docs.python.org/2/library/os.html#os.fsync
            self._oplog.flush()
            self._last_flush_time  = time()
            self._writes_unflushed = 0
            return os.fsync(self._oplog.fileno()) 
開發者ID:Percona-Lab,項目名稱:mongodb_consistent_backup,代碼行數:9,代碼來源:Oplog.py

示例7: read

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def read(self, *args, **kwargs):
        _size = None

        try:
            _size = kwargs.get('size', args[0])
        except IndexError:
            pass

        return self.getvalue()[:_size]

    # https://docs.python.org/2/library/stdtypes.html#bltin-file-objects Says file.write(str) 
開發者ID:SafeBreach-Labs,項目名稱:backdoros,代碼行數:13,代碼來源:backdoros.py

示例8: __import__

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def __import__(*args, **kwargs):
    global _is_debug

    if _is_debug:
        print "*** HOOKED *** IMPORT: args = %s, kwargs = %s" % (args, kwargs)

    name = args[0]

    try:
        return _real_import(*args, **kwargs)
    except ImportError:
        # TODO: Add support for more extensions? (e.g. *.pyc)
        if _mem_storage.has_key(args[0] + '.py'):
            name = args[0] + '.py'
        if _mem_storage.has_key(name):
            # It's a Virtual File!
            new_mod = imp.new_module(name)
            exec _mem_storage[name].read() in new_mod.__dict__
            sys.modules[args[0]] = new_mod
            return new_mod
        else:
            # It's a bust!
            raise ImportError('ImportError: No module named %s' % name)


# TODO: Monkey patch https://docs.python.org/2/library/os.html#file-descriptor-operations 
開發者ID:SafeBreach-Labs,項目名稱:backdoros,代碼行數:28,代碼來源:backdoros.py

示例9: safe_sleep

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def safe_sleep(seconds):
  """Ensure that the thread sleeps at a minimum the requested seconds.

  Until Python 3.5, there was no guarantee that time.sleep() would actually sleep the requested
  time. See https://docs.python.org/3/library/time.html#time.sleep."""
  if sys.version_info[0:2] >= (3, 5):
    time.sleep(seconds)
  else:
    start_time = current_time = time.time()
    while current_time - start_time < seconds:
      remaining_time = seconds - (current_time - start_time)
      time.sleep(remaining_time)
      current_time = time.time() 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:15,代碼來源:common.py

示例10: finalize

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def finalize(self, source=None):
    """Rename `work_dir` to `target_dir` using `os.rename()`.

    :param str source: An optional source offset into the `work_dir`` to use for the atomic
                       update of `target_dir`. By default the whole `work_dir` is used.

    If a race is lost and `target_dir` already exists, the `target_dir` dir is left unchanged and
    the `work_dir` directory will simply be removed.
    """
    if self.is_finalized:
      return

    source = os.path.join(self._work_dir, source) if source else self._work_dir
    try:
      # Perform an atomic rename.
      #
      # Per the docs: https://docs.python.org/2.7/library/os.html#os.rename
      #
      #   The operation may fail on some Unix flavors if src and dst are on different filesystems.
      #   If successful, the renaming will be an atomic operation (this is a POSIX requirement).
      #
      # We have satisfied the single filesystem constraint by arranging the `work_dir` to be a
      # sibling of the `target_dir`.
      os.rename(source, self._target_dir)
    except OSError as e:
      if e.errno not in (errno.EEXIST, errno.ENOTEMPTY):
        raise e
    finally:
      self.cleanup() 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:31,代碼來源:common.py

示例11: generate_256bit_key

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def generate_256bit_key():
    """Generate a pseudo-random secure ready-for-crypto-use key.

    Generate it straight using urandom. Proving randomness is impossible, and a good source
    is a hotly debated subject. As always, opinions are welcome but please inform
    yourself first and be prepared to cite a source.

    Further Reading:
    https://docs.python.org/3.5/library/os.html#os.urandom
    https://docs.python.org/2.7/library/os.html#os.urandom
    https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
    http://www.2uo.de/myths-about-urandom/
    https://github.com/dlitz/pycrypto/blob/master/lib/Crypto/Random/__init__.py
    """
    return binascii.hexlify(os.urandom(32)) 
開發者ID:dispel,項目名稱:jak,代碼行數:17,代碼來源:helpers.py

示例12: contain

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def contain(command):
    # TODO: exec command, note the difference between the exec flavours
    #       https://docs.python.org/2/library/os.html#os.execv
    # NOTE: command is an array (the first element is path/file, and the entire
    #       array is exec's args)

    os._exit(0)  # TODO: remove this after adding exec 
開發者ID:Fewbytes,項目名稱:rubber-docker,代碼行數:9,代碼來源:rd.py

示例13: allocate_shm_file

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def allocate_shm_file(filename, nbytes, dbytes, readonly):
  exists = os.path.exists(filename)
  size = 0 if not exists else os.path.getsize(filename)

  if readonly and not exists:
    raise SharedMemoryReadError(filename + " has not been allocated. Requested " + str(nbytes) + " bytes.")
  elif readonly and size != nbytes:
    raise SharedMemoryReadError("{} exists, but the allocation size ({} bytes) does not match the request ({} bytes).".format(
      filename, size, nbytes
    ))

  if exists: 
    if size > nbytes:
      with open(filename, 'wb') as f:
        os.ftruncate(f.fileno(), nbytes)
    elif size < nbytes:
      # too small? just remake it below
      os.unlink(filename) 

  exists = os.path.exists(filename)

  if not exists:
    # Previously we were writing out real files full of zeros, 
    # but a) that takes forever and b) modern OSes support sparse
    # files (i.e. gigabytes of zeros that take up only a few real bytes).
    #
    # The following should take advantage of this functionality and be faster.
    # It should work on Python 2.7 Unix, and Python 3.5+ on Unix and Windows.
    #
    # References:
    #   https://stackoverflow.com/questions/8816059/create-file-of-particular-size-in-python
    #   https://docs.python.org/3/library/os.html#os.ftruncate
    #   https://docs.python.org/2/library/os.html#os.ftruncate
    #
    with open(filename, 'wb') as f:
      os.ftruncate(f.fileno(), nbytes) 
開發者ID:seung-lab,項目名稱:cloud-volume,代碼行數:38,代碼來源:sharedmemory.py

示例14: _exit_processes

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def _exit_processes(exit_code):  # type: (int) -> None
    """Exit main thread and child processes.

    For more information:
        https://docs.python.org/2/library/os.html#process-management
        https://docs.python.org/3/library/os.html#process-management

    Args:
        exit_code (int): exit code
    """
    os._exit(exit_code)  # pylint: disable=protected-access 
開發者ID:aws,項目名稱:sagemaker-containers,代碼行數:13,代碼來源:_trainer.py

示例15: test_create_folder

# 需要導入模塊: import os [as 別名]
# 或者: from os import html [as 別名]
def test_create_folder(self):
        folder_path = 'new_folder'
        shared_utils.create_folder(folder_path)
        self.assertTrue(os.path.isdir(folder_path))

        # change just-created folder to be unaccessible
        os.chmod(folder_path, 0o0)

        # try creating a folder inside the unaccessible one
        # NOTE: apparently there's no way to make a Windows folder
        # read-only programmatically, so first check if the parent
        # folder cannot be accessed. See Windows note in os.chmod()
        # https://docs.python.org/3/library/os.html#os.chmod
        blocked_folder_path = os.path.join(folder_path, 'blocked_folder')
        if not os.access(folder_path, os.W_OK):
            with self.assertRaises(OSError) as cm:
                shared_utils.create_folder(blocked_folder_path)
            self.assertEqual(cm.exception.errno, 13)

        # try creating a folder with the same name as an existing file
        file_path = 'new_file'
        with open(file_path, "w+"):
            with self.assertRaises(OSError) as cm:
                shared_utils.create_folder(file_path)
            self.assertEqual(cm.exception.errno, 17)

        # remove artifacts
        os.chmod(folder_path, 0o755)
        if os.path.exists(folder_path):
            os.rmdir(folder_path)
        if os.path.exists(file_path):
            os.remove(file_path) 
開發者ID:adobe-type-tools,項目名稱:opentype-svg,代碼行數:34,代碼來源:shared_utils_test.py


注:本文中的os.html方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。