Example #1
0
 def render_DELETE(self, request):
     request.setHeader('Content-type', 'application/json')
     content = request.content.read()
     if content:
         del_uuids = json.loads(content)
         self.inst.jobs.jobs = filter(lambda j: j.uuid not in del_uuids, self.inst.jobs.jobs)
         self.inst.jobs.cancel_job(del_uuids)
     return json.dumps(map(lambda j: j.uuid, self.inst.jobs.jobs))
Example #2
0
 def render_DELETE(self, request):
     request.setHeader('Content-type', 'application/json')
     content = request.content.read()
     if content:
         del_uuids = json.loads(content)
         assert isinstance(del_uuids, (list, tuple))
         self.inst.jobs.jobs = filter(lambda x: x['uuid'] not in del_uuids, self.inst.jobs.jobs)
         self.inst.jobs.cancel(del_uuids)
     return json.dumps(self.inst.jobs.jobs)
Example #3
0
 def render_PUT(self, request):
     request.setHeader('Content-type', 'application/json')
     content = request.content.read()
     if content:
         obj = json.loads(content)
         uids = self.add_jobs(obj)
         return json.dumps(uids)
     else:
         return None
Example #4
0
 def writesjson(filename,content):
     if not isinstance(filename,str):
         return
     if isinstance(content,OrderedDict):
         content = sjson.dumps(content)
     else:
         content = ""
     with open(filename, 'w') as f:
         s = '{\n' + content + '}'
         
         #indentation styling
         p = ''
         S = ''
         for c in s:
             if c in ("{","[") and p in ("{","["):
                 S+="\n"
             if c in ("}","]") and p in ("}","]"):
                 S+="\n"
             S += c
             if p in ("{","[") and c not in ("{","[","\n"):
                 S=S[:-1]+"\n"+S[-1]
             if c in ("}","]") and p not in ("}","]","\n"):
                 S=S[:-1]+"\n"+S[-1]
             p = c
         s = S
         s = s.replace(", ","\n")
         l = s.split('\n')
         i = 0
         L = []
         for S in l:
             for c in S:
                 if c in ("}","]"):
                     i=i-1
             L.append("  "*i+S)
             for c in S:
                 if c in ("{","["):
                     i=i+1
         s = '\n'.join(L)
         
         f.write(s)
Example #5
0
def patch_profile_sjsons() -> None:
    if config.custom_resolution:
        profile_sjsons = helpers.try_get_profile_sjson_files()
        if not profile_sjsons:
            msg = """Cannot patch custom resolution to 'ProfileX.sjson'.
This is a non-blocking issue but might prevent you from running Hades at the resolution of your choice."""
            LOGGER.warning(msg)
            return
        edited_list = []
        for file in profile_sjsons:
            LOGGER.debug(f"Analyzing '{file}'")
            data = sjson.loads(file.read_text())
            for key in ['X', 'WindowWidth']:
                data[key] = config.resolution.width
            for key in ['Y', 'WindowHeight']:
                data[key] = config.resolution.height
            # we manually set WindowX/Y in ProfileX.sjson configuration files as a
            # safeguard against WindowX/Y values overflowing when switching to
            # windowed mode while using a custom resolution larger than officially
            # supported by the main monitor, ensuring Hades will not be drawn
            # offscreen and can then be repositioned by the user
            for key in ['WindowX', 'WindowY']:
                if not key in data:
                    data[key] = WINDOW_XY_DEFAULT_OFFSET
                    LOGGER.debug(
                        f"'{key}' not found in '{file.name}', inserted '{key} = {WINDOW_XY_DEFAULT_OFFSET}'"
                    )
                elif data[key] >= WINDOW_XY_OVERFLOW_THRESHOLD:
                    data[key] = WINDOW_XY_DEFAULT_OFFSET
                    LOGGER.debug(
                        f"'{key}' found in '{file.name}' but with overflowed value, reset to '{key} = {WINDOW_XY_DEFAULT_OFFSET}'"
                    )
            file.write_text(sjson.dumps(data))
            edited_list.append(file)
        if edited_list:
            edited_list = '\n'.join(f"  - {file}" for file in edited_list)
            msg = f"""Applied custom resolution to:
{edited_list}"""
            LOGGER.info(msg)
Example #6
0
 def render_GET(self, request):
     request.setHeader('Content-type', 'application/json')
     return json.dumps(self.value)
Example #7
0
 def render_GET(self, request):
     request.setHeader('Content-type', 'application/json')
     rv = map(lambda j: j.__dict__, self.inst.jobs.jobs)
     keys = ['name', 'start_time', 'after', 'actions']
     rv = map(lambda j: {k: j[k] for k in keys}, rv)
     return json.dumps(rv)
Example #8
0
 def render_GET(self, request):
     request.setHeader('Content-type', 'application/json')
     return json.dumps(self.value)
Example #9
0
def __patch_sjson_file(source_sjson: SJSON, file: Path,
                       patches: SJSONPatch) -> None:
    patched_sjson = __patch_sjson_data(source_sjson, patches)
    file.write_text(sjson.dumps(patched_sjson))
    LOGGER.info(f"Patched '{file}'")