mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +02:00
jw.pkg.App: Add lru_cache where possible
ResultCache is a home-grown result cache. The @lru_cache decorator, now available in Python 3, accomplishes the same thing, so try to ditch ResultCache for it. Sadly, this doesn't entirely work as of now, because it uses hash() to hash the arguments, which won't work for the two list-type arguments to add_modules_from_project_txt() (buf and visited). Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
a377745e5e
commit
5cdc32abd7
1 changed files with 6 additions and 3 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import os, sys, argparse, pwd, re
|
import os, sys, argparse, pwd, re
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
from .lib.App import App as Base
|
from .lib.App import App as Base
|
||||||
from .lib.log import *
|
from .lib.log import *
|
||||||
|
|
@ -139,7 +140,7 @@ class App(Base):
|
||||||
self.__pretty_topdir = self.__format_topdir(self.__topdir, args.topdir_format)
|
self.__pretty_topdir = self.__format_topdir(self.__topdir, args.topdir_format)
|
||||||
self.__topdir_fmt = args.topdir_format
|
self.__topdir_fmt = args.topdir_format
|
||||||
if self.__topdir is not None:
|
if self.__topdir is not None:
|
||||||
self.__top_name = self.__res_cache.run(self.read_value, [self.__topdir + '/make/project.conf', 'build', 'name'])
|
self.__top_name = self.read_value(self.__topdir + '/make/project.conf', 'build', 'name')
|
||||||
if not self.__top_name:
|
if not self.__top_name:
|
||||||
self.__top_name = re.sub('-[0-9.-]*$', '', os.path.basename(os.path.realpath(self.__topdir)))
|
self.__top_name = re.sub('-[0-9.-]*$', '', os.path.basename(os.path.realpath(self.__topdir)))
|
||||||
|
|
||||||
|
|
@ -167,6 +168,7 @@ class App(Base):
|
||||||
seen_add = seen.add
|
seen_add = seen.add
|
||||||
return [x for x in seq if not (x in seen or seen_add(x))]
|
return [x for x in seq if not (x in seen or seen_add(x))]
|
||||||
|
|
||||||
|
@lru_cache(maxsize=None)
|
||||||
def get_os(self, args = ""):
|
def get_os(self, args = ""):
|
||||||
import subprocess
|
import subprocess
|
||||||
for d in [ self.__projs_root + '/jw-pkg/scripts', '/opt/jw-pkg/bin' ]:
|
for d in [ self.__projs_root + '/jw-pkg/scripts', '/opt/jw-pkg/bin' ]:
|
||||||
|
|
@ -198,7 +200,7 @@ class App(Base):
|
||||||
if self.__os_cascade is not None:
|
if self.__os_cascade is not None:
|
||||||
return self.__os_cascade.copy()
|
return self.__os_cascade.copy()
|
||||||
r = [ 'os', platform.system().lower() ]
|
r = [ 'os', platform.system().lower() ]
|
||||||
os = self.__opt_os if self.__opt_os is not None else self.__res_cache.run(self.get_os, [])
|
os = self.__opt_os if self.__opt_os is not None else self.get_os()
|
||||||
name = re.sub('-.*', '', os)
|
name = re.sub('-.*', '', os)
|
||||||
series = os
|
series = os
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -235,6 +237,7 @@ class App(Base):
|
||||||
file.close()
|
file.close()
|
||||||
return r.rstrip()
|
return r.rstrip()
|
||||||
|
|
||||||
|
@lru_cache(maxsize=None)
|
||||||
def read_value(self, path, section, key):
|
def read_value(self, path, section, key):
|
||||||
|
|
||||||
def scan_section(f, key):
|
def scan_section(f, key):
|
||||||
|
|
@ -311,7 +314,7 @@ class App(Base):
|
||||||
|
|
||||||
path = proj_root + '/make/project.conf'
|
path = proj_root + '/make/project.conf'
|
||||||
#print('path = ', path, 'self.__top_name = ', self.__top_name, 'name = ', name)
|
#print('path = ', path, 'self.__top_name = ', self.__top_name, 'name = ', name)
|
||||||
return self.__res_cache.run(self.read_value, [path, section, key])
|
return self.read_value(path, section, key)
|
||||||
|
|
||||||
def collect_values(self, names, section, key):
|
def collect_values(self, names, section, key):
|
||||||
r = ""
|
r = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue