Replace getcwd with get_main_dir

Signed-off-by: Frinzell, Aaron <aaron.frinzell@intel.com>
This commit is contained in:
Frinzell, Aaron
2024-06-04 09:42:06 -05:00
committed by Aaron Frinzell
parent b330a73630
commit 7c802e494e
2 changed files with 19 additions and 16 deletions
+9 -7
View File
@@ -26,8 +26,10 @@ Library to build module URLs
import os
import json
import re
from chipsec.library.file import get_main_dir
class url:
class url:
def __init__(self):
self.url_info = self.get_url_info()
self.base_url = self.get_base_url()
@@ -36,15 +38,15 @@ class url:
self.ends_with = self.url_info.get('ends_with', '')
def get_url_info(self):
with open(os.path.join(os.getcwd(), 'chipsec', 'library', 'url_format.json'), 'r') as url_file:
return json.loads(url_file.read())
with open(os.path.join(get_main_dir(), 'chipsec', 'library', 'url_format.json'), 'r') as url_file:
return json.loads(url_file.read())
def get_base_url(self):
if 'base_url' not in self.url_info:
raise Exception("Missing Base URL in url file")
raise Exception('Missing Base URL in url file')
return self.url_info['base_url']
def get_module_url(self, module_name: str) -> str:
module_name = re.sub(self.replace_find, self.replace_with , module_name)
module_name = re.sub(self.replace_find, self.replace_with, module_name)
module_url = f'{self.base_url}{module_name}{self.ends_with}'
return module_url
return module_url
+10 -9
View File
@@ -24,6 +24,7 @@ import os
import traceback
import json
import chipsec.library.logger
from chipsec.library.file import get_main_dir
from chipsec.library.url import url
from chipsec.library.returncode import ModuleResult, generate_hash_id
@@ -33,7 +34,7 @@ try:
except ImportError:
_importlib = False
MODPATH_RE = re.compile(r"^\w+(\.\w+)*$")
MODPATH_RE = re.compile(r'^\w+(\.\w+)*$')
class Module:
@@ -77,25 +78,25 @@ class Module:
self.logger.log_bad(traceback.format_exc())
raise msg
return loaded
def get_module_ids_dictionary(self):
with open(os.path.join(os.getcwd(), 'chipsec', 'library', 'module_ids.json'), 'r') as module_ids_file:
with open(os.path.join(get_main_dir(), 'chipsec', 'library', 'module_ids.json'), 'r') as module_ids_file:
module_ids = json.loads(module_ids_file.read())
return module_ids
def update_module_ids_file(self):
with open(os.path.join(os.getcwd(), 'chipsec', 'library', 'module_ids.json'), 'w') as module_ids_file:
with open(os.path.join(get_main_dir(), 'chipsec', 'library', 'module_ids.json'), 'w') as module_ids_file:
module_ids_file.write(json.dumps(self.module_ids))
def get_module_id(self, module_name):
def get_module_id(self, module_name):
if module_name in self.module_ids:
module_id = self.module_ids[module_name]
else:
module_id = generate_hash_id(module_name)
self.module_ids[module_name] = module_id
self.update_module_ids_file()
self.update_module_ids_file()
return module_id
def run(self, module_argv):
self.get_module_object()
@@ -141,7 +142,7 @@ class Module:
myfile = ''
try:
if _importlib:
myfile = getattr(self.module, "__file__")
myfile = getattr(self.module, '__file__')
except:
pass
return myfile