Exemple #1
0
    def install_os_deps(self, conn, distro_info):

        distro_name = re.search(r"\nNAME=\"(.*)\"", distro_info, re.M).group(1)

        if "Ubuntu" in distro_name:
            distro_version = re.search(r"\nDISTRIB_RELEASE=(.*)", distro_info,
                                       re.M).group(1)

            conn.sudo("apt-get install python3-pip -y", hide=True)
            transfer = Transfer(conn)
            for file in os.listdir("machine_diagnostics_protocol"):
                if os.path.isdir(f"machine_diagnostics_protocol/{file}"):
                    directoryname = file
                    conn.run(f"mkdir -p {directoryname}")
                    for sub_file in os.listdir(
                            f"machine_diagnostics_protocol/{directoryname}"):
                        transfer.put(
                            f"machine_diagnostics_protocol/{directoryname}/{sub_file}",
                            f"{directoryname}/")
                else:
                    transfer.put(f"machine_diagnostics_protocol/{file}")

            if distro_version == "14.04":
                conn.sudo(f"cp /home/{self.user}/mdp.conf /etc/init",
                          hide=True)
                conn.run(
                    f"pip3 install -r /home/{self.user}/requirements.txt --user",
                    hide=True)
                conn.sudo("initctl reload-configuration", hide=True)
                conn.sudo("service mdp restart", hide=True, pty=False)
            else:
                conn.sudo("")

        else:
            pass
def _gunicorn_service(ctx, con, env, e, app_path, app_name, conf):
    lines = conf.split('\n')
    service = os.getcwd() + '/{}.service'.format(app_name)
    for line in lines:
        with open(service, 'a+') as file:
            file.write(line.strip())
            file.write('\n')
    gunicorn_service = '/etc/systemd/system/'
    transfer = Transfer(con)
    transfer.put(service, remote='/tmp', preserve_mode=True)
    sudorun(ctx, env, 'mv /tmp/' + app_name + '.service ' + gunicorn_service)
    os.remove(service)
Exemple #3
0
def put(local: str, remote: str, preserve_mode: bool = True) -> Result:
    """
    Закачать файл на сервер
    <http://docs.fabfile.org/en/2.5/api/transfer.html#fabric.transfer.Transfer.put>

    :param local: путь до локального файла
    :param remote: путь куда сохранить на сервере
    :param preserve_mode: сохранить права
    """
    t = Transfer(global_context.conn)
    return t.put(local=local, remote=remote, preserve_mode=preserve_mode)
Exemple #4
0
def put_template(template_path: str, remote: str, **context: Any) -> Result:
    """
    Отрендерить файл с помощью jinja-шаблонов и закачать на сервер
    См раздел templates.

    <http://docs.fabfile.org/en/2.5/api/transfer.html#fabric.transfer.Transfer.put>

    :param template_path: путь до локального файла jinja
    :param remote: путь куда сохранить на сервере
    :param context: контекс для рендеринга jinja2
    """
    filestr = render(template_path=template_path, **context)
    t = Transfer(global_context.conn)
    return t.put(local=BytesIO(filestr.encode()),
                 remote=remote,
                 preserve_mode=False)
Exemple #5
0
def put_template(template_path: str, remote: str, **context) -> Result:
    filestr = render(template_path=template_path, **context)
    t = Transfer(global_context.conn)
    return t.put(local=StringIO(filestr), remote=remote, preserve_mode=False)
Exemple #6
0
def put(local: str, remote: str, preserve_mode: bool = True) -> Result:
    # http://docs.fabfile.org/en/2.5/api/transfer.html#fabric.transfer.Transfer.put
    t = Transfer(global_context.conn)
    return t.put(local=local, remote=remote, preserve_mode=preserve_mode)