コード例 #1
0
def run(child_name, params=[], base_dir='.', process_protocol=None):
    """
    This is another portable solution to execute a process.
    """
    if bpio.isFrozen() and bpio.Windows():
        progpath = os.path.abspath(os.path.join(base_dir, child_name + '.exe'))
        executable = progpath
        cmdargs = [progpath]
        cmdargs.extend(params)
    else:
        progpath = os.path.abspath(os.path.join(base_dir, child_name + '.py'))
        executable = sys.executable
        cmdargs = [executable, progpath]
        cmdargs.extend(params)
    if not os.path.isfile(executable):
        lg.out(1, 'child_process.run ERROR %s not found' % executable)
        return None
    if not os.path.isfile(progpath):
        lg.out(1, 'child_process.run ERROR %s not found' % progpath)
        return None
    lg.out(6, 'child_process.run: "%s"' % (' '.join(cmdargs)))

    if bpio.Windows():
        from twisted.internet import _dumbwin32proc
        real_CreateProcess = _dumbwin32proc.win32process.CreateProcess

        def fake_createprocess(_appName, _commandLine, _processAttributes,
                               _threadAttributes, _bInheritHandles,
                               creationFlags, _newEnvironment,
                               _currentDirectory, startupinfo):
            import win32con
            flags = win32con.CREATE_NO_WINDOW
            return real_CreateProcess(_appName, _commandLine,
                                      _processAttributes, _threadAttributes,
                                      _bInheritHandles, flags, _newEnvironment,
                                      _currentDirectory, startupinfo)

        setattr(_dumbwin32proc.win32process, 'CreateProcess',
                fake_createprocess)

    if process_protocol is None:
        process_protocol = ChildProcessProtocol(child_name)
    try:
        Process = reactor.spawnProcess(process_protocol,
                                       executable,
                                       cmdargs,
                                       path=base_dir)
    except:
        lg.out(1, 'child_process.run ERROR executing: %s' % str(cmdargs))
        lg.exc()
        return None

    if bpio.Windows():
        setattr(_dumbwin32proc.win32process, 'CreateProcess',
                real_CreateProcess)

    lg.out(6, 'child_process.run [%s] pid=%d' % (child_name, Process.pid))
    return Process
コード例 #2
0
ファイル: child_process.py プロジェクト: hack-bitdust/devel
def detach(cmdargs):
    """
    
    """
    lg.out(2, "child_process.detach %s" % str(cmdargs))
    try:
        if bpio.Windows():
            import win32process
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                # stdin=subprocess.PIPE,
                # stdout=subprocess.PIPE,
                # stderr=subprocess.PIPE,
                universal_newlines=False,
                creationflags=win32process.CREATE_NO_WINDOW | win32process.DETACHED_PROCESS,
                close_fds=True,)
        else:
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
                close_fds=True,
            )
    except:
        lg.out(1, 'child_process.detach ERROR executing: %s' + str(cmdargs))
        lg.exc()
        return None
    return p
コード例 #3
0
ファイル: child_process.py プロジェクト: hack-bitdust/devel
def pipe(cmdargs):
    """
    Execute a process in different way, create a Pipe to do read/write
    operations with child process.

    See ``lib.nonblocking`` module.
    """
    lg.out(6, "child_process.pipe %s" % str(cmdargs))
    try:
        if bpio.Windows():
            import win32process
            p = nonblocking.Popen(
                cmdargs,
                shell=True,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
                creationflags=win32process.CREATE_NO_WINDOW,)
        else:
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,)
    except:
        lg.out(1, 'child_process.pipe ERROR executing: %s' + str(cmdargs))
        lg.exc()
        return None
    return p
コード例 #4
0
ファイル: diskusage.py プロジェクト: hack-bitdust/devel
def GetDriveSpace(path):
    """
    So this a sort of portable way to get the free HDD space in the system.
    """
    if bpio.Windows():
        drive = os.path.abspath(path)[0]
        if os.path.isdir(drive + ':'):
            # the drive the data directory is on, ie C
            return GetWinDriveSpace(drive)
        else:
            return None, None
    else:
        # on linux the mount points can make a directory be off a different disk than root
        return GetLinuxDriveSpace(path)
コード例 #5
0
ファイル: diskusage.py プロジェクト: hack-bitdust/devel
import os
import time
import glob

#------------------------------------------------------------------------------

from lib import diskspace

from main import settings

import bpio

#------------------------------------------------------------------------------

if bpio.Windows():
    import win32api
    import win32file

#------------------------------------------------------------------------------


def GetWinDriveSpace(drive):
    """
    For Windows.

    Return a tuple (<free space in bytes>, <total space in bytes>) or
    (None, None). Call system method ``win32file.GetDiskFreeSpace``.
    """
    try:
        sectorsPerCluster, bytesPerSector, numFreeClusters, totalNumClusters = win32file.GetDiskFreeSpace(