Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/creactistore/_templates/lib/olpcfr/semanticxo/_runner.py~
blob: d3a82903c20dd532c2537f36a802060369050511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# python import
import os, shlex, subprocess, tarfile

# server tools import
from server.tools import storage

# server import
from server.flask import logger


class Runner(object):

    class __Singleton:

        def __init__(self):
            self.proc = None

        def run(self):
            # prepare paths
            _store_path = storage.get_path(path='store')
            # change dir for unzipping
            os.chdir(_store_path)
            if os.path.exists('redstore'):
                pass
            else:
                _trip_zip = storage.get_path(path='data/triplestore.tar.bz2')
                # extract files in tmp dir
                _tar = tarfile.open(_trip_zip)
                _tar.extractall()
                _tar.close()
            # get args
            args = shlex.split('sh %s/wrapper.sh' % _store_path)
            self.proc = subprocess.Popen(args)
            # stay in the dir
            os.chdir(storage.BUNDLE)

        def stop(self):
            pass

    # singleton instance
    instance = None

    def __new__(c):
        if Runner.instance is None:
            Runner.instance = Runner.__Singleton()
        else:
            pass
        return Runner.instance