To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit d1158e8a authored by John Zhang's avatar John Zhang
Browse files

updated python language module

parent 7908a261
...@@ -55,7 +55,7 @@ class Python(Language): ...@@ -55,7 +55,7 @@ class Python(Language):
cmd.append(target) cmd.append(target)
# first & second argument: callback class name and parameter string # first & second argument: callback class name and parameter string
cmd.append(task.callback['name']) cmd.append(task.callback['dylib'])
cmd.append(task.callback['param']) cmd.append(task.callback['param'])
cmd.extend(bmc['args']) cmd.extend(bmc['args'])
......
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class Callback:
"""
Callback root class used by Python
"""
def __init__(self, param_s):
"""
:param param_s: parameter string for initialisation
"""
pass
def begin(self, kwds=None):
"""
Begin measurement.
"""
pass
def end(self, kwds=None):
"""
End measurement.
"""
pass
def report(self):
"""
Report data to file.
"""
pass
def get_callback(cb_name):
"""
Import callback classes from submodule files,
and dynamically select which class to return.
NOTE: new Callback class implementations should be added here
"""
from callback.cb_print import PrintCallback
from callback.cb_time import TimeCallback
from callback.cb_clock import ClockCallback
name_dic = {
'print': PrintCallback,
'time': TimeCallback,
'clock': ClockCallback,
}
cb_cls = name_dic[cb_name]
return cb_cls
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import time
from callback import Callback
DEFAULT_FLOAT_PREC = 6
class ClockCallback(Callback):
def __init__(self, param_s):
self.data = []
self.t0 = None
self.prec = int(param_s) if param_s else DEFAULT_FLOAT_PREC
def begin(self, **kwds):
self.t0 = time.clock()
def end(self, **kwds):
t1 = time.clock()
self.data.append(t1 - self.t0)
def report(self):
for flt in self.data:
print(("%%.%df" % self.prec) % flt)
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
A simple print callback class as an example.
"""
from callback import Callback
import json
class PrintCallback(Callback):
def __init__(self, param_s):
print("initialised PrintCallback with: %s" % param_s)
def begin(self, **kwds):
print("begin measurement")
def end(self, **kwds):
print("end measurement")
def report(self):
json.dump({}, fp)
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import time
from callback import Callback
class TimeCallback(Callback):
def __init__(self, param_s):
print("initialised PrintCallback with: %s" % param_s)
self.data = []
self.time = 0
def begin(self, **kwds):
print("begin measurement")
self.time = time.time()
def end(self, **kwds):
print("end measurement")
self.data.append(time.time() - self.time)
def report(self, file_name):
sys.stdout.writelines("\n".join(map(str, self.data)))
...@@ -21,8 +21,8 @@ def fib(n): ...@@ -21,8 +21,8 @@ def fib(n):
def main(argv): def main(argv):
from callback import get_callback from callback import get_callback
cb_cls_name, cb_param = argv[1:3] libcb_path, cb_param = argv[1:3]
cb = get_callback(cb_cls_name)(cb_param) cb = get_callback(libcb_path)(cb_param)
scale_factor = int(argv[3]) scale_factor = int(argv[3])
n = int(argv[4]) n = int(argv[4])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment