mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-29 13:04:27 +01:00
getvar works again
This commit is contained in:
15
common.py
15
common.py
@@ -100,8 +100,9 @@ class LkmcCliFunction(cli_function.CliFunction):
|
|||||||
* command timing
|
* command timing
|
||||||
* some common flags, e.g.: --arch, --dry-run, --verbose
|
* some common flags, e.g.: --arch, --dry-run, --verbose
|
||||||
'''
|
'''
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, do_print_time=True, **kwargs):
|
||||||
kwargs['config_file'] = consts['config_file']
|
kwargs['config_file'] = consts['config_file']
|
||||||
|
self._do_print_time = do_print_time
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Args for all scripts.
|
# Args for all scripts.
|
||||||
@@ -659,7 +660,7 @@ to allow overriding configs from the CLI.
|
|||||||
ret = self.timed_main()
|
ret = self.timed_main()
|
||||||
if not kwargs['dry_run']:
|
if not kwargs['dry_run']:
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
self.print_time(end_time - start_time)
|
self._print_time(end_time - start_time)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def make_build_dirs(self):
|
def make_build_dirs(self):
|
||||||
@@ -685,11 +686,11 @@ to allow overriding configs from the CLI.
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
def _print_time(self, ellapsed_seconds):
|
||||||
def print_time(ellapsed_seconds):
|
if self._do_print_time:
|
||||||
hours, rem = divmod(ellapsed_seconds, 3600)
|
hours, rem = divmod(ellapsed_seconds, 3600)
|
||||||
minutes, seconds = divmod(rem, 60)
|
minutes, seconds = divmod(rem, 60)
|
||||||
print("time {:02}:{:02}:{:02}".format(int(hours), int(minutes), int(seconds)))
|
print("time {:02}:{:02}:{:02}".format(int(hours), int(minutes), int(seconds)))
|
||||||
|
|
||||||
def raw_to_qcow2(self, prebuilt=False, reverse=False):
|
def raw_to_qcow2(self, prebuilt=False, reverse=False):
|
||||||
if prebuilt or not os.path.exists(self.env['qemu_img_executable']):
|
if prebuilt or not os.path.exists(self.env['qemu_img_executable']):
|
||||||
|
|||||||
37
getvar
37
getvar
@@ -5,13 +5,16 @@ import types
|
|||||||
import common
|
import common
|
||||||
from shell_helpers import LF
|
from shell_helpers import LF
|
||||||
|
|
||||||
parser = self.get_argparse(argparse_args={
|
class Main(common.LkmcCliFunction):
|
||||||
'description': '''Print the value of a kwargs['py'] variable.
|
def __init__(self):
|
||||||
|
super().__init__(
|
||||||
|
description='''\
|
||||||
|
Print the value of a self.env['py'] variable.
|
||||||
|
|
||||||
This is useful to:
|
This is useful to:
|
||||||
|
|
||||||
* give dry commands on the README that don't change when we refactor directory structure
|
* give dry commands on the README that don't change when we refactor directory structure
|
||||||
* create simple bash scripts that call use kwargs['py'] variables
|
* create simple bash scripts that call use self.env['py'] variables
|
||||||
|
|
||||||
For example, to get the Buildroot output directory for an ARM build, use:
|
For example, to get the Buildroot output directory for an ARM build, use:
|
||||||
|
|
||||||
@@ -24,16 +27,18 @@ List all available variables:
|
|||||||
....
|
....
|
||||||
./%(prog)s
|
./%(prog)s
|
||||||
....
|
....
|
||||||
....
|
''',
|
||||||
'''
|
do_print_time=False,
|
||||||
})
|
)
|
||||||
parser.add_argument('variable', nargs='?')
|
self.add_argument('variable', nargs='?')
|
||||||
args = self.setup(parser)
|
|
||||||
if kwargs['variable']:
|
def timed_main(self):
|
||||||
print(getattr(common, kwargs['variable']))
|
variable = self.env['variable']
|
||||||
else:
|
if variable:
|
||||||
for attr in dir(common):
|
print(self.env[variable])
|
||||||
if not attr.startswith('__'):
|
else:
|
||||||
val = getattr(common, attr)
|
for key in self.env:
|
||||||
if not callable(val) and not type(val) is types.ModuleType:
|
print('{}={}'.format(key, self.env[key]))
|
||||||
print('{} {}'.format(attr, val))
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
Main().cli()
|
||||||
|
|||||||
Reference in New Issue
Block a user