# Path: redsolutioncms/models.py
# class ProcessTask(models.Model):
#     task = models.CharField(verbose_name=_('task'), max_length=255)
#     pid = models.IntegerField(verbose_name=_('process pid'), blank=True, null=True)
#     lock = models.BooleanField(verbose_name=_('task inactive'), default=False)
#     executed = models.BooleanField(verbose_name=_('task executed'), default=False)
#     process_finished = models.BooleanField(verbose_name=_('process finished'), default=False)
#     wait = models.BooleanField(verbose_name=_('wait finish'), default=False)
# 
#     def __unicode__(self):
#         return self.task
# 
# Path: redsolutioncms/loader.py
# def install_in_home():
# def run_cmd(cmd, cmd_dict=None):
# def process_cmd_string(cmd, cmd_dict=None):
# def run_in_home(cmd):
# def main():


from django.core.management.base import BaseCommand, CommandError
from redsolutioncms.models import ProcessTask
from redsolutioncms.loader import home_dir, process_cmd_string
import subprocess
import time
import os, signal
                        import ctypes
                        pass
                    else:
                        try:
                            os.kill(task.pid, signal.SIG_DFL)
                        except OSError:
                            task.process_finished = True
                            task.save()
                tasks = ProcessTask.objects.filter(executed=False)
                time.sleep(1)
                lock_tasks = tasks.filter(lock=True)
                if lock_tasks:
                    first_lock_task = lock_tasks[0]
                    tasks = tasks.filter(id__lt=first_lock_task.id)
                if tasks:
                    task = tasks[0]
                    print task.task, 'executing...'
                    if os.sys.platform == 'win32':
                        CREATE_NEW_PROCESS_GROUP = 512
                        p = subprocess.Popen(task.task,
                            creationflags=CREATE_NEW_PROCESS_GROUP)
                    else:
                        p = subprocess.Popen(task.task, close_fds=True,
                            shell=True, preexec_fn=os.setsid,)
                    task.pid = p.pid
                    if task.wait:
                        p.wait()
                        task.process_finished = True
                    task.executed = True
                    task.save()
        except KeyboardInterrupt:

# Path: redsolutioncms/models.py
# class ProcessTask(models.Model):
#     task = models.CharField(verbose_name=_('task'), max_length=255)
#     pid = models.IntegerField(verbose_name=_('process pid'), blank=True, null=True)
#     lock = models.BooleanField(verbose_name=_('task inactive'), default=False)
#     executed = models.BooleanField(verbose_name=_('task executed'), default=False)
#     process_finished = models.BooleanField(verbose_name=_('process finished'), default=False)
#     wait = models.BooleanField(verbose_name=_('wait finish'), default=False)
# 
#     def __unicode__(self):
#         return self.task
# 
# Path: redsolutioncms/loader.py
# def install_in_home():
# def run_cmd(cmd, cmd_dict=None):
# def process_cmd_string(cmd, cmd_dict=None):
# def run_in_home(cmd):
# def main():


# Path: redsolutioncms/management/commands/wrap_runserver.py
from django.core.management.base import BaseCommand, CommandError
from redsolutioncms.models import ProcessTask
from redsolutioncms.loader import home_dir, process_cmd_string
import subprocess
import time
import os, signal
                        import ctypes

                        pass
                    else:
                        try:
                            os.kill(task.pid, signal.SIG_DFL)
                        except OSError:
                            task.process_finished = True
                            task.save()
                tasks = ProcessTask.objects.filter(executed=False)
                time.sleep(1)
                lock_tasks = tasks.filter(lock=True)
                if lock_tasks:
                    first_lock_task = lock_tasks[0]
                    tasks = tasks.filter(id__lt=first_lock_task.id)
                if tasks:
                    task = tasks[0]
                    print task.task, 'executing...'
                    if os.sys.platform == 'win32':
                        CREATE_NEW_PROCESS_GROUP = 512
                        p = subprocess.Popen(task.task,
                            creationflags=CREATE_NEW_PROCESS_GROUP)
                    else:
                        p = subprocess.Popen(task.task, close_fds=True,
                            shell=True, preexec_fn=os.setsid,)
                    task.pid = p.pid
                    if task.wait:
                        p.wait()
                        task.process_finished = True
                    task.executed = True
                    task.save()
        except KeyboardInterrupt:

            executing_tasks = ProcessTask.objects.filter(process_finished=False)