Exemplo n.º 1
0
    def test_transition_mod_sync_cow_full(self):
        scratch = "{}/scratch".format(self.mount)
        falloc = 50

        self.assertEqual(
            dattobd.setup(self.minor,
                          self.device,
                          self.cow_full_path,
                          fallocated_space=falloc), 0)
        self.addCleanup(dattobd.destroy, self.minor)

        util.dd("/dev/zero", scratch, falloc + 10, bs="1M")
        self.addCleanup(os.remove, scratch)

        # Possible errors doing this:
        # * EINVAL: The file system already performed the sync
        # * EFBIG: The module performed the sync
        # We want the later to happen, so try to transition without calling sync.

        err = dattobd.transition_to_incremental(self.minor)
        if (err != errno.EFBIG):
            self.skipTest("Kernel flushed before module")

        snapdev = dattobd.info(self.minor)
        self.assertIsNotNone(snapdev)

        self.assertEqual(snapdev["error"], -errno.EFBIG)
        self.assertEqual(snapdev["state"], 2)
Exemplo n.º 2
0
    def test_transition_fs_sync_cow_full(self):
        scratch = "{}/scratch".format(self.mount)
        falloc = 50

        self.assertEqual(
            dattobd.setup(self.minor,
                          self.device,
                          self.cow_full_path,
                          fallocated_space=falloc), 0)
        self.addCleanup(dattobd.destroy, self.minor)

        util.dd("/dev/zero", scratch, falloc + 10, bs="1M")
        self.addCleanup(os.remove, scratch)

        # Possible errors doing this:
        # * EINVAL: The file system already performed the sync
        # * EFBIG: The module performed the sync
        # We want the former to happen, so make the OS sync everything.

        os.sync()
        self.assertEqual(dattobd.transition_to_incremental(self.minor),
                         errno.EINVAL)

        snapdev = dattobd.info(self.minor)
        self.assertIsNotNone(snapdev)

        self.assertEqual(snapdev["error"], -errno.EFBIG)
        self.assertEqual(snapdev["state"], 3)
Exemplo n.º 3
0
    def setUpClass(cls):
        cls.backing_store = "/tmp/disk.img"
        cls.device = "/dev/loop0"
        cls.mount = "/tmp/dattobd"

        cls.kmod = kmod.Module("../src/dattobd.ko")
        cls.kmod.load(debug=1)

        util.dd("/dev/zero", cls.backing_store, 256, bs="1M")
        util.loop_create(cls.device, cls.backing_store)
        util.mkfs(cls.device)
        os.makedirs(cls.mount, exist_ok=True)
        util.mount(cls.device, cls.mount)
Exemplo n.º 4
0
    def setUpClass(cls):
        cls.minor = randint(0, 23)
        r = randint(0, 999)
        cls.mount = "/tmp/elastio-snap_{0:03d}".format(r)

        cls.kmod = kmod.Module("../src/elastio-snap.ko")
        cls.kmod.load(debug=1)
        if os.getenv('TEST_DEVICE'):
            cls.device = os.getenv('TEST_DEVICE')
            dev_size = int(
                subprocess.check_output("blockdev --getsize64 %s" % cls.device,
                                        shell=True,
                                        text=True)) // 1024**2
            util.dd("/dev/zero", cls.device, dev_size, bs="1M")
        else:
            cls.backing_store = "/tmp/disk_{0:03d}.img".format(r)
            util.dd("/dev/zero", cls.backing_store, 256, bs="1M")
            cls.device = util.loop_create(cls.backing_store)

        util.mkfs(cls.device)
        os.makedirs(cls.mount, exist_ok=True)
        util.mount(cls.device, cls.mount)
Exemplo n.º 5
0
#       if(/^(\d+)\s+\S/) {
#         print;
#         $tags{$1} = gettags($_);  # hash mapping task num to tags string
#       } else { print; }
#     }
#     close(F);
#   } else {
#     print "ERROR: Can't read task file ($tskf)\n";
#     $eflag++;
#   }
#   print "\n";
# }

#s, m, h, d, *rest = time.localtime(t)
y, m, d, h, m, s, *rest = time.localtime(t)
s = util.dd(s)
m = util.dd(m)
h = util.dd(h)
d = util.dd(d)

print("It's tag time!  What are you doing RIGHT NOW ({}:{}:{})?".format(h, m, s))

# Get what the user was last doing. In the case this fails, set eflag and
# print the reason why.

try:
    last_doing = get_last_doing()
except Exception as e:
    last_doing = ''
    eflag += 1
    print('ERROR:', e, file=sys.stderr)
Exemplo n.º 6
0
Arquivo: conf.py Projeto: ikn/wvoas
def translate_dd (d):
    if isinstance(d, defaultdict):
        return defaultdict(d.default_factory, d)
    else:
        # should be (default, dict)
        return dd(*d)
Exemplo n.º 7
0
Arquivo: level.py Projeto: ikn/latof
                overlay.draw(screen)
            rtn = rects
        self._changed = set()
        self._changed_rects = []
        return rtn


class Level1(Level):
    def __init__(self, game, event_handler, ident=0):
        self.tls = []
        Level.__init__(self, game, event_handler, ident)
        self.circuit = circuit.CircuitPuzzle(self, conf.CIRCUIT)
        self._finished = False
        self._step()
        game.scheduler.add_timeout(self._step, seconds=conf.CIRCUIT_MOVE_TIME)

    def _cleanup(self):
        self._finished = True

    def _step(self):
        if self._finished:
            return False
        state = self.circuit.step()
        if state is not None:
            for tl in self.tls:
                tl.set_state(state)
        return True


level_backends = dd(Level, {1: Level1})
Exemplo n.º 8
0
Arquivo: conf.py Projeto: ikn/latof
def translate_dd (d):
    if isinstance(d, defaultdict):
        return defaultdict(d.default_factory, d)
    else:
        # should be (default, dict)
        return dd(*d)
Exemplo n.º 9
0
Arquivo: conf.py Projeto: ikn/latof
class Conf (object):

    IDENT = 'latof'
    USE_SAVEDATA = False
    USE_FONTS = True

    # save data
    SAVE = ()
    # need to take care to get unicode path
    if system() == 'Windows':
        try:
            import ctypes
            n = ctypes.windll.kernel32.GetEnvironmentVariableW(u'APPDATA', None, 0)
            if n == 0:
                raise ValueError()
        except Exception:
            # fallback (doesn't get unicode string)
            CONF_DIR = os.environ[u'APPDATA']
        else:
            buf = ctypes.create_unicode_buffer(u'\0' * n)
            ctypes.windll.kernel32.GetEnvironmentVariableW(u'APPDATA', buf, n)
            CONF_DIR = buf.value
        CONF_DIR = join_path(CONF_DIR, IDENT)
    else:
        CONF_DIR = join_path(os.path.expanduser(u'~'), '.config', IDENT)
    CONF = join_path(CONF_DIR, 'conf')

    # data paths
    DATA_DIR = u''
    IMG_DIR = DATA_DIR + 'img' + sep
    SOUND_DIR = DATA_DIR + 'sound' + sep
    MUSIC_DIR = DATA_DIR + 'music' + sep
    FONT_DIR = DATA_DIR + 'font' + sep

    # display
    WINDOW_ICON = IMG_DIR + 'icon.png'
    WINDOW_TITLE = 'Life and Times of Frog?'
    MOUSE_VISIBLE = dd(True) # per-backend
    FLAGS = 0
    FULLSCREEN = False
    RESIZABLE = False # also determines whether fullscreen togglable
    RES_W = (600, 600)
    RES_F = pg.display.list_modes()[0]
    RES = RES_W
    MIN_RES_W = (320, 180)
    ASPECT_RATIO = None

    # timing
    FPS = dd(60) # per-backend

    # debug
    PROFILE_STATS_FILE = '.profile_stats'
    DEFAULT_PROFILE_TIME = 5

    # input
    KEYS_NEXT = (pg.K_RETURN, pg.K_SPACE, pg.K_KP_ENTER)
    KEYS_BACK = (pg.K_ESCAPE, pg.K_BACKSPACE)
    KEYS_MINIMISE = (pg.K_F10,)
    KEYS_FULLSCREEN = (pg.K_F11, (pg.K_RETURN, pg.KMOD_ALT, True),
                    (pg.K_KP_ENTER, pg.KMOD_ALT, True))
    KEYS_LEFT = (pg.K_LEFT, pg.K_a, pg.K_q)
    KEYS_RIGHT = (pg.K_RIGHT, pg.K_d, pg.K_e)
    KEYS_UP = (pg.K_UP, pg.K_w, pg.K_z, pg.K_COMMA)
    KEYS_DOWN = (pg.K_DOWN, pg.K_s, pg.K_o)
    KEYS_DIRN = (KEYS_LEFT, KEYS_UP, KEYS_RIGHT, KEYS_DOWN)

    ACTION_SETS = {1: ('inspect', 'move'), 2: ('drop', 'move'),
                   3: ('grab', 'use', 'drop')}

    # audio
    MUSIC_AUTOPLAY = True # just pauses music
    MUSIC_VOLUME = dd(.2) # per-backend
    SOUND_VOLUME = .5
    EVENT_ENDMUSIC = pg.USEREVENT
    SOUND_VOLUMES = dd(1, crash = 1.5)
    # generate SOUNDS = {ID: num_sounds}
    SOUNDS = {}
    ss = glob(join_path(SOUND_DIR, '*.ogg'))
    base = len(join_path(SOUND_DIR, ''))
    for fn in ss:
        fn = fn[base:-4]
        for i in xrange(len(fn)):
            if fn[i:].isdigit():
                # found a valid file
                ident = fn[:i]
                if ident:
                    n = SOUNDS.get(ident, 0)
                    SOUNDS[ident] = n + 1

    # gameplay
    TILE_SIZE = (40, 40)
    LEVEL_SIZE = (RES[0] / TILE_SIZE[0], RES[1] / TILE_SIZE[1])
    FROG_MOVE_TIME = .1
    # road
    ROAD_POS = (0, 200)
    ROAD_SIZE = (600, 200)
    TILE_ROAD_POS = (0, 5)
    TILE_ROAD_SIZE = (15, 5)
    ROAD_LANES = (231, 275, 327, 375)
    ROAD_LANE_WIDTH = 40
    ROAD_DIRN = 1 # 1 for left, -1 for right
    CAR_SPEED = 600 # pixels per second
    CAR_SPEED_JITTER = 20 # mean variation of car speed (pixels per second)
    CAR_GAP = {'moving': 50, 'stopped': 5, 'crashed': 0}
    CAR_WEIGHTINGS = {
        'car0': (1, {
            'red': 1,
            'blue': 1,
            'yellow': .3
        }), 'van0': (.3, {
            'white': 1
        }), 'lorry0': (.2, {
            'blue': 1,
            'orange': .5
        })
    }
    CRASH_POS_JITTER = 50 # mean pixels displaced
    CRASH_FOLLOWTHROUGH = 30 # pixels moved past crash point
    # cutscenes
    b = (0, 0, 0)
    INIT_FADE = [b, (False, 1)]
    # each is (event_time, fade[, restore_control_time = event_time)
    RESTART = (1.25, [False, (b, 1), (b, 1.5), (False, 2.5)])
    PROGRESS = (1.25, [False, (b, 1), (b, 1.5), (False, 2.5)])
    END = (1, [False, (b, 1)])
    CRASH = (6, [False, (b, 1), (b, 11), (False, 12)], 3)
    CRASH_STOP_TRAFFIC_SND_TIME = 1

    # UI
    # per-backend, each a {key: value} dict to update fonthandler.Fonts with
    FONT = 'JacquesFrancois.ttf'
    MSG_FONT_SIZE = 17
    LABEL_FONT_SIZE = 13
    REQUIRED_FONTS = dd({
        'msg': (FONT, MSG_FONT_SIZE),
        'label': (FONT, LABEL_FONT_SIZE),
    })
    FONT_COLOUR = (255, 230, 200)
    UI_BG = (30, 20, 0, 150)
    UI_POS = {'msg': (0, 0), 'held': (RES[0] - TILE_SIZE[0], 0)}
    MSG_WIDTH = RES[0] - TILE_SIZE[0] - 5
    MSG_PADDING = (10, 3, 10, 5)
    LABEL_PADDING = (5, 1)
    LABEL_OFFSET = (10, -5)

    # levels
    LEVELS = [{
        'frog pos': (7, 12),
        'objs': {
            (3, 13): ('PuddleOfOil', 'Basket'),
            (2, 13): 'PicnicBlanket'
        }
    }, {
        'frog pos': (7, 12),
        'objs': {
            (5, 13): 'Toolbox',
            (8, 10): 'TrafficLightRight',
            (6, 4): 'TrafficLightLeft'
        }
    }]
    # level 1
    CIRCUIT = {
        'rect': (0, 400, 600, 200),
        'size': (15, 5),
        'states': [(6, 4), (2, 2), (6, 2), (12, 3)],
        'initial dirn': 0,
        'pts': [(7, 4), (2, 4), (2, 2), (12, 2), (12, 4), (7, 4)]
    }
    CIRCUIT_STATE_COLOURS = [(0, 255, 0), (255, 100, 0), (255, 0, 0),
                             (255, 150, 0)]
    CIRCUIT_MOVE_TIME = .05
    CIRCUIT_INITIAL_STATE = 0
    TRAFFIC_LIGHT_STOP_STATES = (2,)
Exemplo n.º 10
0
Arquivo: level.py Projeto: ikn/latof
        self._changed_rects = []
        return rtn


class Level1 (Level):
    def __init__ (self, game, event_handler, ident = 0):
        self.tls = []
        Level.__init__(self, game, event_handler, ident)
        self.circuit = circuit.CircuitPuzzle(self, conf.CIRCUIT)
        self._finished = False
        self._step()
        game.scheduler.add_timeout(self._step,
                                   seconds = conf.CIRCUIT_MOVE_TIME)

    def _cleanup (self):
        self._finished = True

    def _step (self):
        if self._finished:
            return False
        state = self.circuit.step()
        if state is not None:
            for tl in self.tls:
                tl.set_state(state)
        return True


level_backends = dd(Level, {
    1: Level1
})