Esempio n. 1
0
def clear_work_dir(ename):
    print('Stoping supervisor')
    run_command('sudo service supervisor stop')
    print('Removing work dir')
    env_path = os.path.join(settings.WORK_DIR, ename)
    bashCommand = "sudo rm -r %s" % env_path
    try:
        run_command(bashCommand)
    except:
        pass
    # remove nginx conf
    nginx_path = os.path.join(settings.BASE_DIR, 'env-conf', 'nginx', ename)
    try:
        os.remove(nginx_path)
    except:
        pass

    # remove supervisor conf
    filename = '%s-django.conf' % ename
    supervisor_conf_path = os.path.join(settings.BASE_DIR, 'env-conf',
                                        'supervisor', filename)
    try:
        os.remove(supervisor_conf_path)
    except:
        pass

    filename = '%s-frontend.conf' % ename
    supervisor_conf_path = os.path.join(settings.BASE_DIR, 'env-conf',
                                        'supervisor', filename)
    try:
        os.remove(supervisor_conf_path)
    except:
        pass
    restart()
Esempio n. 2
0
def clone_origin(poj_id):
    from project.models import Project
    prj = Project.objects.get(pk=poj_id)
    print('Cloning origin from %s' % prj.git)
    path = os.path.join(settings.ORIGIN_DIR, prj.name)
    try:
        os.mkdir(path)
    except:
        pass
    os.chdir(path)
    run_command("git clone %s %s" % (prj.git, prj.name))
Esempio n. 3
0
def git_clone(env_id):
    from .models import Environ
    env = Environ.objects.get(pk=env_id)
    prj = env.project
    path_to = os.path.join(settings.WORK_DIR, env.name)
    path_from = os.path.join(settings.ORIGIN_DIR, prj.name)
    bashCommand = "cp -r %s/. %s" % (path_from, path_to)
    print('Pulling origin')
    os.chdir(path_from)
    run_command('git pull origin release')
    # g = git.cmd.Git(path_from)
    # g.pull()
    print('Coping project')
    run_command(bashCommand)
    git_create_branch(env_id)
Esempio n. 4
0
def clone_origin(poj_id):
    import time
    time.sleep(1)
    from project.models import Project
    prj = Project.objects.get(pk=poj_id)
    print('Cloning origin from %s' % prj.git)
    path = os.path.join(settings.ORIGIN_DIR, prj.name)
    os.mkdir(path)
    os.chdir(path)
    command = f'git clone {prj.git} .'
    run_command(command)
    print('Cheking', os.path.join(path, 'install'))
    if os.path.isfile(os.path.join(path, 'install')):
        os.chdir(path)
        run_command('bash install')
Esempio n. 5
0
def git_pull(env_id):
    env = Environ.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, env.name)
    os.chdir(path)
    out = run_command('git pull origin master')
    #out = run_command('git push')
    return out
Esempio n. 6
0
def git_diff(env_id):
    env = Env.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, normalize_email(
        env.email), 'pressa-besa')
    os.chdir(path)
    out = run_command('git diff')
    return out
Esempio n. 7
0
def git_push(env_id):
    env = Environ.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, env.name)
    os.chdir(path)
    bname = 'devel-%s' % env.name
    command = 'git push --set-upstream origin %s' % bname
    # command = 'git push'
    out = run_command(command)
    return out
Esempio n. 8
0
def git_push(env_id):
    env = Env.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, normalize_email(
        env.email), 'pressa-besa')
    os.chdir(path)
    bname = 'devel-%s' % normalize_email(env.email)
    command = 'git push --set-upstream origin %s' % bname
    # command = 'git push'
    out = run_command(command)
    return out
Esempio n. 9
0
def git_commit(env_id):
    env = Environ.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, env.name)
    os.chdir(path)
    run_command('git add .')
    comment = 'commit from %s project %s' % (env.user.username,
                                             env.project.name)
    run_command_arr(['git', 'commit', '-m', '"%s"' % comment])
    d = run_command('git push')
    print(d)
    # repo = Repo(path)
    # t = repo.head.commit.tree
    #if repo.git.diff(t):
    # print('Make commit')
    # repo.git.add(update=True)
    # comment = 'commit from %s project %s' % (env.user.username, env.project.name)
    # r = repo.index.commit(comment)
    env.state = 'edited'
    env.save()
    # save_commit(comment, env)
    # os.chdir(path)
    # out = run_command('git push')
    return {"error": None, "output": f'Данные закомичены. {d["output"]} '}
Esempio n. 10
0
def git_create_branch(env_id):
    from .models import Environ
    env = Environ.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, env.name)
    os.chdir(path)
    bname = 'devel-%s' % env.name
    run_command("git branch %s" % bname)
    run_command("git checkout %s" % bname)
    run_command("git push --set-upstream origin %s" % bname)
Esempio n. 11
0
def merge_release(env_id):
    from .models import Environ
    env = Environ.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, env.name)
    os.chdir(path)
    bname = 'devel-%s' % env.name
    command = 'git push --set-upstream origin %s' % bname
    run_command(command)
    path = os.path.join(settings.ORIGIN_DIR, env.project.name)
    os.chdir(path)
    command = 'git pull'
    run_command(command)
    command = 'git merge origin/devel-%s' % env.name
    run_command(command)
Esempio n. 12
0
def clear_log(request, id):
    env = Environ.objects.get(pk=id)
    lname = f'{env.name}.django.{settings.DOMAIN}'
    logname = f'{env.name}.django.{settings.DOMAIN}-err.log'
    path = os.path.join(settings.BASE_DIR, 'logs', lname)
    logpath = os.path.join(settings.BASE_DIR, 'logs', logname)
    command = "sudo supervisorctl -c /etc/supervisor/supervisord.conf stop %s" % lname
    run_command(command)

    command = "rm -f %s" % logpath
    print(command)
    run_command(command)
    command = "sudo supervisorctl -c /etc/supervisor/supervisord.conf start %s" % lname
    run_command(command)
    rez = {"output": 'Ok'}
    return JsonResponse(rez)
Esempio n. 13
0
def build_front(ep_id):
    from .models import EnvironProcess
    ep = EnvironProcess.objects.get(pk=ep_id)
    path = os.path.join(settings.WORK_DIR, ep.env.name, ep.path)
    os.chdir(path)
    run_command(ep.command)
Esempio n. 14
0
def reread():
    print('Rereading supervisor')
    run_command("sudo service supervisorctl reread")
    print('Restarting nginx')
    run_command("sudo service nginx restart")
Esempio n. 15
0
def clear_origin(poj_id):
    from project.models import Project
    prj = Project.objects.get(pk=poj_id)
    env_path = os.path.join(settings.ORIGIN_DIR, prj.name)
    bashCommand = "sudo rm -r %s" % env_path
    run_command(bashCommand)
Esempio n. 16
0
def git_diff(env_id):
    env = Environ.objects.get(pk=env_id)
    path = os.path.join(settings.WORK_DIR, env.name)
    os.chdir(path)
    out = run_command('git diff')
    return out
Esempio n. 17
0
def restart():
    print('Restarting supervisor')
    run_command("sudo service supervisor restart")
    print('Restarting nginx')
    run_command("sudo service nginx restart")