Ejemplo n.º 1
0
 def write_after_flock(self, pid_file):
     inst = ApplicationInstance(os.path.abspath(pid_file),
                                autoExit=False,
                                flock=True)
     with open(self.temp_file, 'wt') as f:
         f.write('foo')
     inst.flockUnlock()
Ejemplo n.º 2
0
    def test_autoExit_unique_process(self):
        self.inst = ApplicationInstance(os.path.abspath(self.file_name),
                                        autoExit = True)

        self.assertExists(self.file_name)
        this_pid = os.getpid()
        this_procname = tools.processName(this_pid)
        with open(self.file_name, 'rt') as file_with_pid:
            self.assertEqual(file_with_pid.read(), '{}\n{}'.format(this_pid, this_procname))
Ejemplo n.º 3
0
 def write_after_flock(
     self,
     pid_file,
 ):
     inst = ApplicationInstance(os.path.abspath(pid_file), False)
     inst.flockExclusiv()
     with open(self.temp_file, 'wt') as f:
         f.write('foo')
     inst.flockUnlock()
Ejemplo n.º 4
0
    def test_autoExit_other_running_process(self):
        pid = self.createProcess()
        procname = tools.processName(pid)

        # create file with pid and process name
        with open(self.file_name, "wt") as file_with_pid:
            file_with_pid.write(str(pid) + "\n")
            file_with_pid.write(procname)

        with self.assertRaises(SystemExit):
            self.inst = ApplicationInstance(os.path.abspath(self.file_name),
                                            autoExit=True)
Ejemplo n.º 5
0
 def test_auto_flock(self):
     self.inst = ApplicationInstance(os.path.abspath(self.file_name),
                                     autoExit=False,
                                     flock=True)
     thread = Thread(target=self.write_after_flock, args=(self.file_name, ))
     thread.start()
     #give the thread some time
     thread.join(0.01)
     self.assertFalse(os.path.exists(self.temp_file))
     self.inst.startApplication()
     #wait for the thread to finish
     thread.join()
     self.assertTrue(os.path.exists(self.temp_file))
     with open(self.temp_file, 'rt') as f:
         self.assertEqual(f.read(), 'foo')
Ejemplo n.º 6
0
def shutdown(args):
    """
    Command for shutting down the computer after the current snapshot has
    finished.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments

    Raises:
        SystemExit:     0 if successful; 1 if it failed either because there is
                        no active snapshot for this profile or shutdown is not
                        supported.
    """
    setQuiet(args)
    printHeader()
    cfg = getConfig(args)

    sd = tools.ShutDown()
    if not sd.canShutdown():
        logger.warning('Shutdown is not supported.')
        sys.exit(RETURN_ERR)

    instance = ApplicationInstance(cfg.takeSnapshotInstanceFile(), False)
    profile = '='.join((cfg.currentProfile(), cfg.profileName()))
    if not instance.busy():
        logger.info(
            'There is no active snapshot for profile %s. Skip shutdown.' %
            profile)
        sys.exit(RETURN_ERR)

    print(
        'Shutdown is waiting for the snapshot in profile %s to end.\nPress CTRL+C to interrupt shutdown.\n'
        % profile)
    sd.activate_shutdown = True
    try:
        while instance.busy():
            logger.debug('Snapshot is still active. Wait for shutdown.')
            sleep(5)
    except KeyboardInterrupt:
        print('Shutdown interrupted.')
    else:
        logger.info('Shutdown now.')
        sd.shutdown()
    sys.exit(RETURN_OK)
Ejemplo n.º 7
0
 def setUp(self):
     super(TestApplicationInstance, self).setUp()
     self.temp_file = '/tmp/temp.txt'
     self.file_name = "/tmp/file_with_pid"
     self.inst = ApplicationInstance(os.path.abspath(self.file_name), False)
     self.subproc = None
Ejemplo n.º 8
0

#    def update_place_status(self, p):
#        translated_langs = p.get_translation_list(reset=True)
#        if translated_langs: #TODO: en az bir dil oldugu icin bu herzaman True oluyor.
#            status = p.translation_status
#            p.translation_status = 20
#            if all([ l in translated_langs for l in self.auto_langs ] ):
#                p.translation_status = 30
#            if status != p.translation_status :
#                p.save()

if __name__ == '__main__':
    o = None
    inst = None
    try:
        inst = ApplicationInstance('/tmp/gtranslate.pid')

        o = TranslationMachine()
        o.run()
        if inst:
            inst.exitApplication()
    except SystemExit:
        if inst:
            inst.exitApplication()
        pass
    except:
        if inst:
            inst.exitApplication()
        log.exception('beklenmeyen hata')
Ejemplo n.º 9
0
import os, sys
pathname = os.path.dirname(sys.argv[0])
sys.path.append(os.path.abspath(pathname))
sys.path.append(
    os.path.normpath(os.path.join(os.path.abspath(pathname), '../')))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from applicationinstance import ApplicationInstance

from places.models import Currency

import logging
log = logging.getLogger('genel')

if __name__ == '__main__':
    o = None
    inst = None
    try:
        inst = ApplicationInstance('/tmp/update_currency.pid')

        Currency.updateRates()
        if inst:
            inst.exitApplication()
    except SystemExit:
        if inst:
            inst.exitApplication()
        pass
    except:
        if inst:
            inst.exitApplication()
        log.exception('beklenmeyen hata')
Ejemplo n.º 10
0
 def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/stdout', stderr='/dev/null'):
     self.stdin = stdin
     self.stdout = stdout
     self.stderr = stderr
     self.pidfile = pidfile
     self.appInstance = ApplicationInstance(pidfile, auto_exit = False, flock = False)
Ejemplo n.º 11
0
 def setUp(self):
     logger.DEBUG = '-v' in sys.argv
     self.temp_file = '/tmp/temp.txt'
     self.file_name = "/tmp/file_with_pid"
     self.inst = ApplicationInstance(os.path.abspath(self.file_name), False)
     self.subproc = None