コード例 #1
0
ファイル: tools.py プロジェクト: ergs/fixie
def register_job_alias(jobid,
                       user,
                       name='',
                       project='',
                       timeout=None,
                       sleepfor=0.1,
                       raise_errors=True):
    """Registers a job id, user, name, and project in the global jobs alias cache.
    Returns whether the registration was successful or not.
    """
    f = ENV['FIXIE_JOB_ALIASES_FILE']
    with flock(f,
               timeout=timeout,
               sleepfor=sleepfor,
               raise_errors=raise_errors) as lockfd:
        if lockfd == 0:
            return False
        # obtain the current contents
        if os.path.isfile(f):
            with open(f) as fh:
                s = fh.read()
            if s.strip():
                cache = json.loads(s)
            else:
                cache = {}
        else:
            cache = {}
        # add the entry as approriate
        if user not in cache:
            cache[user] = {}
        u = cache[user]
        if project not in u:
            u[project] = {}
        p = u[project]
        if name not in p:
            p[name] = set()
        p[name].add(jobid)
        # write the file back out
        with open(f, 'w') as fh:
            json.dump(cache, fh)
    return True
コード例 #2
0
ファイル: test_json.py プロジェクト: yarden-livnat/fixie
def test_set():
    s = {1, 2, 3}
    obs = jsonutils.dumps(s)
    assert '__set__' in obs
    t = jsonutils.loads(obs)
    assert s == t
コード例 #3
0
ファイル: test_json.py プロジェクト: yarden-livnat/fixie
def test_uuid():
    u = uuid.uuid4()
    obs = jsonutils.dumps(u)
    assert '__UUID__' in obs
    v = jsonutils.loads(obs)
    assert u == v
コード例 #4
0
ファイル: test_json.py プロジェクト: yarden-livnat/fixie
def test_bytes():
    s = b"some bytes"
    obs = jsonutils.dumps(s)
    assert '__bytes__' in obs
    t = jsonutils.loads(obs)
    assert s == t