forked from flux-framework/flux-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request flux-framework#3162 from grondo/python-split-job-m…
…odule python: split flux.job module into multiple files
- Loading branch information
Showing
13 changed files
with
731 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
############################################################### | ||
# Copyright 2020 Lawrence Livermore National Security, LLC | ||
# (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
# | ||
# This file is part of the Flux resource manager framework. | ||
# For details, see https://github.com/flux-framework. | ||
# | ||
# SPDX-License-Identifier: LGPL-3.0 | ||
############################################################### | ||
|
||
from flux.job._wrapper import _RAW as RAW | ||
from _flux._core import ffi | ||
|
||
|
||
def id_parse(jobid_str): | ||
""" | ||
returns: An integer jobid | ||
:rtype int | ||
""" | ||
jobid = ffi.new("flux_jobid_t[1]") | ||
RAW.id_parse(jobid_str, jobid) | ||
return int(jobid[0]) | ||
|
||
|
||
def id_encode(jobid, encoding="f58"): | ||
""" | ||
returns: Jobid encoded in encoding | ||
:rtype str | ||
""" | ||
buflen = 128 | ||
buf = ffi.new("char[]", buflen) | ||
RAW.id_encode(int(jobid), encoding, buf, buflen) | ||
return ffi.string(buf, buflen).decode("utf-8") | ||
|
||
|
||
class JobID(int): | ||
"""Class used to represent a Flux JOBID | ||
JobID is a subclass of `int`, so may be used in place of integer. | ||
However, a JobID may be created from any valid RFC 19 FLUID | ||
encoding, including: | ||
- decimal integer (no prefix) | ||
- hexidecimal integer (prefix 0x) | ||
- dotted hex (dothex) (xxxx.xxxx.xxxx.xxxx) | ||
- kvs dir (dotted hex with `job.` prefix) | ||
- RFC19 F58: (Base58 encoding with prefix `ƒ` or `f`) | ||
A JobID object also has properties for encoding a JOBID into each | ||
of the above representations, e.g. jobid.f85, jobid.words, jobid.dothex... | ||
""" | ||
|
||
def __new__(cls, value): | ||
if isinstance(value, int): | ||
jobid = value | ||
else: | ||
jobid = id_parse(value) | ||
return super(cls, cls).__new__(cls, jobid) | ||
|
||
def encode(self, encoding="dec"): | ||
"""Encode a JobID to alternate supported format""" | ||
return id_encode(self, encoding) | ||
|
||
@property | ||
def dec(self): | ||
"""Return decimal integer representation of a JobID""" | ||
return self.encode() | ||
|
||
@property | ||
def f58(self): | ||
"""Return RFC19 F58 representation of a JobID""" | ||
return self.encode("f58") | ||
|
||
@property | ||
def hex(self): | ||
"""Return 0x-prefixed hexidecimal representation of a JobID""" | ||
return self.encode("hex") | ||
|
||
@property | ||
def dothex(self): | ||
"""Return dotted hexidecimal representation of a JobID""" | ||
return self.encode("dothex") | ||
|
||
@property | ||
def words(self): | ||
"""Return words (mnemonic) representation of a JobID""" | ||
return self.encode("words") | ||
|
||
@property | ||
def kvs(self): | ||
"""Return KVS directory path of a JobID""" | ||
return self.encode("kvs") | ||
|
||
def __str__(self): | ||
return self.encode("f58") | ||
|
||
def __repr__(self): | ||
return f"JobID({self.dec})" |
Oops, something went wrong.