Ejemplo n.º 1
0
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
    assert isinstance(commands, list)
    # noinspection PyUnusedLocal
    p = None
    for c in commands:
        try:
            p = subprocess_Popen([c] + args,
                                 cwd=cwd,
                                 stdout=PIPE,
                                 stderr=(PIPE if hide_stderr else None))
            break
        except EnvironmentError:
            e = sys_exc_info()[1]
            if e.errno == ENOENT:
                continue
            if verbose:
                print(('unable to run {}'.format(args[0])))
                print(e)
            return None
    else:
        if verbose:
            print(('unable to find command, tried {}'.format(commands)))
        return None
    stdout = p.communicate()[0].strip()
    if sys_version >= '3':
        stdout = stdout.decode()
    if p.returncode != 0:
        if verbose:
            print(('unable to run {} (error)'.format(args[0])))
        return None
    return stdout
Ejemplo n.º 2
0
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
   assert isinstance(commands, list)
   # noinspection PyUnusedLocal
   p = None
   for c in commands:
      try:
         # remember shell=False, so use git.cmd on windows, not just git
         p = subprocess_Popen([c] + args, cwd=cwd, stdout=subprocess_PIPE, stderr=(subprocess_PIPE if hide_stderr else None))
         break
      except EnvironmentError:
         e = sys_exc_info()[1]
         if e.errno == ERRNO_ENOENT:
            continue
         if verbose:
            print('unable to run {}'.format(args[0]))
            print(e)
         return None
   else:
      if verbose:
         print('unable to find command, tried {}'.format(commands, ))
      return None
   stdout = p.communicate()[0].strip()
   if sys_version >= '3':
      stdout = stdout.decode()
   if p.returncode != 0:
      if verbose:
         print('unable to run {} (error)'.format(args[0]))
      return None
   return stdout
Ejemplo n.º 3
0
    def RunServer(self, server_name, port):
        script_dir = os_path.dirname(os_path.abspath(__file__))
        root_dir = os_path.join(script_dir, '..')
        server_py = os_path.join(root_dir, 'server.py')

        tmpdirname = TemporaryDirectory()
        log('created temporary directory: ' + tmpdirname.name)

        subenv = os_environ.copy()
        subenv['LIMBO_WEB_SERVER'] = server_name
        subenv['LIMBO_LISTEN_HOST'] = LISTEN_HOST
        subenv['LIMBO_LISTEN_PORT'] = str(port)
        subenv['LIMBO_STORAGE_DIRECTORY'] = tmpdirname.name
        # don't waste time for saving files:
        subenv['LIMBO_DISABLE_STORAGE'] = '1'

        pid = subprocess_Popen(['python', server_py], cwd=root_dir, env=subenv)
        return [tmpdirname, pid]
Ejemplo n.º 4
0
def run_child_server(server_name, host, port):
    script_dir = os_path.dirname(os_path.abspath(__file__))
    root_dir = os_path.join(script_dir, '..')
    server_py = os_path.join(root_dir, 'server.py')

    tmpdir = TemporaryDirectory()
    log('created temporary directory: ' + tmpdir.name)

    subenv = os_environ.copy()
    subenv['LIMBO_WEB_SERVER'] = server_name
    subenv['LIMBO_LISTEN_HOST'] = host
    subenv['LIMBO_LISTEN_PORT'] = str(port)
    subenv['LIMBO_STORAGE_DIRECTORY'] = tmpdir.name

    pid = subprocess_Popen(['python', server_py], cwd=root_dir, env=subenv)
    try:
        wait_net_service(host, port, 10)
    except Exception:
        pid.terminate()
        tmpdir.cleanup()
        raise
    return [tmpdir, pid]
def os_system(command):
    """Execute a command"""
    proc = subprocess_Popen(command, shell=True,stdout=subprocess.PIPE,)
    stdout_value = proc.communicate()[0]
Ejemplo n.º 6
0
ERR_TRACERT_ERROR = 1
ERR_NODE_NAME_ERROR = 2
ERR_TRANSITION_ERROR = 3
ERR_INTERNET_CONNECTION_ERROR = 4

argParser = ArgumentParser(
    description="Трассировка автономных систем. Пользователь вводит доменное "
    "имя или IP адрес. Осуществляется трассировка до указанного узла. На "
    "выходе таблица со столбцами: номер узла, IP, ASN, страна и провайдер")
argParser.add_argument('internet_address',
                       type=str,
                       help='IP или доменное имя')
args = argParser.parse_args()

tracert = subprocess_Popen(['tracert', args.internet_address],
                           stdout=PROCESS_PIPE,
                           stderr=PROCESS_PIPE)

start_time = time()
tracert_out = ""
while True:
    try:
        tracert_stdout, tracert_stderr = tracert.communicate(timeout=10)
        break
    except TimeoutExpiredError:
        print("tracert in progress " + str(int(time() - start_time)) +
              " seconds...")

tracert_out = StringIO(tracert_stdout.decode('cp866'))
tracert_err = tracert_stderr.decode('cp866')
Ejemplo n.º 7
0
config = ConfigParser.ConfigParser()
with open('buildout.cfg') as conf:
    config.readfp(conf)
    bind_ip = config.get('mongodb','bind_ip')
    port = config.get('mongodb','port')
    mongodb_data_path = config.get('mongodb','dbpath')
    mongodb_log_path = config.get('mongodb','logpath')

path_cwd = os_getcwd()

# need to fix : all options from rod.recipe.mongodb are not handle
mongod_proc = subprocess_Popen([
    os_path_join(path_cwd, 'bin/mongod'),
    '--dbpath', os_path_join(path_cwd,mongodb_data_path.split('/',1)[1]),
    '--bind_ip', bind_ip,
    '--master',
    '--port', port,
    '--logpath', os_path_join(path_cwd,mongodb_log_path.split('/',1)[1]),
    '--directoryperdb',
])

time_sleep(3)
sys_stdout.write('Process ID of MongoD %s' % (mongod_proc.pid))

mongo_running = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = mongo_running.connect_ex((bind_ip, int(port)))

if result == 0:
    client = pymongo_MongoClient(bind_ip, int(port))
    db = client.wekan.add_user(
        'wekan',