Exemple #1
0
    def handle(self, *args, **options):

        #if len(args) < 4: raise CommandError('usage: <repo name> <branch> <file> <run_status>')

        br = Branch.objects.get(repo__name__exact=options['repo'], name__exact=options['branch'])
        if not br: raise CommandError("invalid repo/branch")
        if options['logtype'] == 'code':
            br.code_run_status = options['runstatus']
        else:
            br.run_status = options['runstatus']
        br.save()
        
        brlog = BranchLog()
        
        try:
            brlog = BranchLog.objects.get(branch=br, logtype=options['logtype'])
        except ObjectDoesNotExist:
            brlog.branch = br
            brlog.logtype = options['logtype']

        lastlog = 'From ' + options['file'] + '<br/>'
        
        for line in fileinput.input(options['file']):
            lastlog += line + '<br/>'
            
        if len(lastlog) > 20000:
            lastlog = lastlog[len(lastlog) - 20000:]
        brlog.lastlog = lastlog
        brlog.save()
Exemple #2
0
def adminMenu(request):
    if request.method == u'GET' and request.GET.__contains__('reset') and request.GET['reset'] == 'true':
        snaptype = request.GET['type']
        branch_id = request.GET['branch_id']
        branch = Branch.objects.get(id=branch_id)
        if snaptype == 'config':
            branch.run_status = 'd'
        else:
            branch.code_run_status = 'd'
        branch.save()
        return redirect("/admin/?success=true")

    if request.method == u'GET' and request.GET.__contains__('snapshot') and request.GET['snapshot'] == 'true':
        branch_id = request.GET['branch_id']
        snaptype = request.GET['type']
        branch = Branch.objects.get(id=branch_id)
        if snaptype == 'config' and branch.run_status != 'r':
            repo_name = branch.repo.name
            branch_name = branch.name
            pr = subprocess.Popen(os.path.join(settings.BASE_DIR,
                                  'config_cronjob.sh') + ' ' + repo_name + ' ' + branch_name + ' >/var/sftmp/ssRun.out 2>&1 &',
                                  shell=True)
            logger.debug('Started With pid ' + str(pr.pid))
            pr.wait()
            if pr.returncode == 0:
                brlog = BranchLog()
                try:
                    brlog = BranchLog.objects.get(branch=branch, logtype=snaptype)
                except ObjectDoesNotExist:
                    brlog.branch = branch
                    brlog.logtype = snaptype
                brlog.last_log = 'Started'
                brlog.save()
                branch.run_status = 'r'
                branch.save()
                return redirect("/admin/?success=true")
            return redirect("/admin/?failed=true")
        if snaptype == 'code' and branch.code_run_status != 'r':
            repo_name = branch.repo.name
            branch_name = branch.name
            pr = subprocess.Popen(os.path.join(settings.BASE_DIR,
                                    'code_cronjob.sh') + ' ' + repo_name + ' ' + branch_name + ' >/var/sftmp/ssRun.out 2>&1 &',
                                    shell=True)
            logger.debug('Started With pid ' + str(pr.pid))
            pr.wait()
            if pr.returncode == 0:
                brlog = BranchLog()
                try:
                    brlog = BranchLog.objects.get(branch=branch, logtype=snaptype)
                except ObjectDoesNotExist:
                    brlog.branch = branch
                    brlog.logtype = snaptype
                brlog.last_log = 'Started'
                brlog.save()
                branch.code_run_status = 'r'
                branch.save()
                return redirect("/admin/?success=true")
            return redirect("/admin/?failed=true")

    repos = Repo.objects.all()
    branches = Branch.objects.all()
    ctab = CronTab()
    cronlist = []
    for item in [entry.render() for entry in ctab]:
        if item.find(CRON_COMMENT) != -1:
            cronlist.append(item)

    return render(request, 'admin_menu.html', {'repos': repos, 'branches': branches, 'crontab': cronlist})