Skip to content

Commit b0f6e74

Browse files
Rework config_directory
1 parent 218735d commit b0f6e74

6 files changed

Lines changed: 42 additions & 79 deletions

File tree

docs/web/products.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ database arguments:
158158
is the server which will make the database connection.
159159
160160
--sqlite SQLITE_FILE Path of the SQLite database file to use. All paths will
161-
be relative to the server's <CONFIG_DIRECTORY>. If an
161+
be relative to the server's <WORKSPACE_DIRECTORY>. If an
162162
SQLite server needs to have a different directory, use
163163
symlinks inside the config directory.
164164
(default: <ENDOPINT>.sqlite)

docs/web/user_guide.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ optional arguments:
164164
-h, --help show this help message and exit
165165
-w WORKSPACE, --workspace WORKSPACE
166166
Directory where CodeChecker can store analysis result
167-
related data, such as the database. (Cannot be
168-
specified at the same time with '--sqlite' or
169-
'--config-directory'.) (default:
167+
related data, such as the database. (default:
170168
/home/<username>/.codechecker)
171169
-f CONFIG_DIRECTORY, --config-directory CONFIG_DIRECTORY
172170
Directory where CodeChecker server should read server-
@@ -215,7 +213,7 @@ optional arguments:
215213
216214
configuration database arguments:
217215
--sqlite SQLITE_FILE Path of the SQLite database file to use. (default:
218-
<CONFIG_DIRECTORY>/config.sqlite)
216+
<WORKSPACE_DIRECTORY>/config.sqlite)
219217
--postgresql Specifies that a PostgreSQL database is to be used
220218
instead of SQLite. See the "PostgreSQL arguments"
221219
section on how to configure the database connection.

web/client/codechecker_client/cli/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def __register_add(parser):
779779
required=False,
780780
help="Path of the SQLite database file to use. "
781781
"All paths will be relative to the server's "
782-
"<CONFIG_DIRECTORY>. If an SQLite server "
782+
"<WORKSPACE_DIRECTORY>. If an SQLite server "
783783
"needs to have a different directory, use "
784784
"symlinks inside the config directory.")
785785

web/server/codechecker_server/api/product_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def getProductConfiguration(self, product_id):
294294
# Strip the config directory from the path, to allow for
295295
# easier editing
296296
config_dir = \
297-
os.path.normpath(self.__server.config_directory) + "/"
297+
os.path.normpath(self.__server.workspace_directory) + "/"
298298
if args['sqlite'].startswith(config_dir):
299299
db_name = args['sqlite'][len(config_dir):]
300300
else:
@@ -428,8 +428,8 @@ def addProduct(self, product):
428428
codechecker_api_shared.ttypes.ErrorCode.DATABASE,
429429
"SQLite database must be given by relative path!")
430430

431-
dbc.database = path_for_fake_root(os.path.join("/", dbc.database),
432-
self.__server.config_directory)
431+
dbc.database = path_for_fake_root(os.path.join(
432+
"/", dbc.database), self.__server.workspace_directory)
433433

434434
# Check if the database is already in use by another product.
435435
db_in_use = self.__server.is_database_used(product)
@@ -610,7 +610,7 @@ def editProduct(self, product_id, new_config):
610610
"SQLite database must be given by relative path!")
611611
dbc.database = path_for_fake_root(
612612
os.path.join("/", dbc.database),
613-
self.__server.config_directory)
613+
self.__server.workspace_directory)
614614

615615
# Some values come encoded as Base64, decode these.
616616
displayed_name = convert.from_b64(new_config.displayedName_b64) \

web/server/codechecker_server/cli/server.py

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ def add_arguments_to_parser(parser):
8585
default=default_workspace,
8686
required=False,
8787
help="Directory where CodeChecker can store analysis "
88-
"result related data, such as the database. "
89-
"(Cannot be specified at the same time with "
90-
"'--sqlite' or '--config-directory'.)")
88+
"result related data, such as the database.")
9189

9290
parser.add_argument('-f', '--config-directory',
9391
type=str,
9492
dest="config_directory",
95-
default=default_workspace,
9693
required=False,
9794
help="Directory where CodeChecker server should read "
9895
"server-specific configuration (such as "
@@ -169,9 +166,6 @@ def add_arguments_to_parser(parser):
169166
type=str,
170167
dest="sqlite",
171168
metavar='SQLITE_FILE',
172-
default=os.path.join(
173-
'<CONFIG_DIRECTORY>',
174-
"config.sqlite"),
175169
required=False,
176170
help="Path of the SQLite database file to use.")
177171

@@ -373,54 +367,22 @@ def arg_match(options):
373367
# is intended later on.
374368
delattr(args, 'not_host_only')
375369

376-
# --workspace and --sqlite cannot be specified either, as
377-
# both point to a database location.
378-
options = ['--sqlite', '--workspace']
379-
options_short = ['--sqlite', '-w']
380-
if set(arg_match(options)) == set(options) or \
381-
set(arg_match(options_short)) == set(options_short):
382-
parser.error("argument --sqlite: not allowed with "
383-
"argument --workspace")
384-
385-
# --workspace and --config-directory also aren't allowed together now,
386-
# the latter one is expected to replace the earlier.
387-
options = ['--config-directory', '--workspace']
388-
options_short = ['--config-directory', '-w']
389-
if set(arg_match(options)) == set(options) or \
390-
set(arg_match(options_short)) == set(options_short):
391-
parser.error("argument --config-directory: not allowed with "
392-
"argument --workspace")
393-
394370
# If workspace is specified, sqlite is workspace/config.sqlite
395371
# and config_directory is the workspace directory.
396-
if arg_match(['--workspace', '-w']):
372+
if not args.config_directory:
397373
args.config_directory = args.workspace
374+
375+
if not args.sqlite:
398376
args.sqlite = os.path.join(args.workspace,
399377
'config.sqlite')
400-
setattr(args, 'dbdatadir', os.path.join(args.workspace,
401-
'pgsql_data'))
402-
403-
# Workspace should not exist as a Namespace key.
404-
delattr(args, 'workspace')
405-
406-
if '<CONFIG_DIRECTORY>' in args.sqlite:
407-
# Replace the placeholder variable with the actual value.
408-
args.sqlite = args.sqlite.replace('<CONFIG_DIRECTORY>',
409-
args.config_directory)
410378

411379
# Convert relative sqlite file path to absolute.
412-
if 'sqlite' in args:
413-
args.sqlite = os.path.abspath(args.sqlite)
380+
args.sqlite = os.path.abspath(args.sqlite)
414381

415382
if 'postgresql' not in args:
416383
# Later called database modules need the argument to be actually
417384
# present, even though the default is suppressed in the optstring.
418385
setattr(args, 'postgresql', False)
419-
420-
# This is not needed by the database starter as we are
421-
# running SQLite.
422-
if 'dbdatadir' in args:
423-
delattr(args, 'dbdatadir')
424386
else:
425387
# If --postgresql is given, --sqlite is useless.
426388
delattr(args, 'sqlite')
@@ -429,6 +391,10 @@ def arg_match(options):
429391
if "list" in args or "stop" in args or "stop_all" in args:
430392
setattr(args, "instance_manager", True)
431393

394+
# Log directories
395+
LOG.info(f"Workspace directory: {args.workspace}")
396+
LOG.info(f"Config directory: {args.config_directory}")
397+
432398
# If everything is fine, do call the handler for the subcommand.
433399
return main(args)
434400

@@ -808,7 +774,7 @@ def __instance_management(args):
808774
if 'stop' in args and \
809775
not (i['port'] == args.view_port and
810776
os.path.abspath(i['workspace']) ==
811-
os.path.abspath(args.config_directory)):
777+
os.path.abspath(args.workspace)):
812778
continue
813779

814780
try:
@@ -836,7 +802,7 @@ def __reload_config(args):
836802
if 'reload' in args and \
837803
not (i['port'] == args.view_port and
838804
os.path.abspath(i['workspace']) ==
839-
os.path.abspath(args.config_directory)):
805+
os.path.abspath(args.workspace)):
840806
continue
841807

842808
try:
@@ -890,13 +856,6 @@ def server_init_start(args):
890856
if not host_check.check_zlib():
891857
raise ModuleNotFoundError("zlib is not available on the system!")
892858

893-
# WARNING
894-
# In case of SQLite args.dbaddress default value is used
895-
# for which the is_localhost should return true.
896-
if is_localhost(args.dbaddress) and \
897-
not os.path.exists(args.config_directory):
898-
os.makedirs(args.config_directory)
899-
900859
# Make sure the SQLite file can be created if it not exists.
901860
if 'sqlite' in args and \
902861
not os.path.isdir(os.path.dirname(args.sqlite)):
@@ -907,7 +866,7 @@ def server_init_start(args):
907866
"option. The server will ask for users to authenticate!")
908867

909868
context = webserver_context.get_context()
910-
context.codechecker_workspace = args.config_directory
869+
context.codechecker_workspace = args.workspace
911870
context.db_username = args.dbusername
912871

913872
environ = env.extend(context.path_env_extra,
@@ -993,8 +952,8 @@ def server_init_start(args):
993952

994953
# Create the main database link from the arguments passed over the
995954
# command line.
996-
cfg_dir = os.path.abspath(args.config_directory)
997-
default_product_path = os.path.join(cfg_dir, 'Default.sqlite')
955+
workspace_dir = os.path.abspath(args.workspace)
956+
default_product_path = os.path.join(workspace_dir, 'Default.sqlite')
998957
create_default_product = 'sqlite' in args and \
999958
not os.path.exists(default_product_path)
1000959

@@ -1073,6 +1032,7 @@ def server_init_start(args):
10731032

10741033
try:
10751034
return server.start_server(args.config_directory,
1035+
args.workspace,
10761036
package_data,
10771037
args.view_port,
10781038
cfg_sql_server,
@@ -1098,20 +1058,21 @@ def main(args):
10981058
Setup a logger server based on the configuration and
10991059
manage the CodeChecker server.
11001060
"""
1101-
workspace = (
1102-
args.config_directory
1103-
if "config_directory" in args and not hasattr(args, "instance_manager")
1104-
else None
1105-
)
11061061

11071062
# Create workspace directory before logging is initialized.
1108-
if workspace and not os.path.exists(args.config_directory):
1109-
LOG.info("Creating non existing config directory: %s",
1110-
args.config_directory)
1111-
os.makedirs(args.config_directory)
1063+
if not hasattr(args, "instance_manager"):
1064+
if not os.path.exists(args.workspace):
1065+
LOG.info("Creating non existing workspace directory: %s",
1066+
args.workspace)
1067+
os.makedirs(args.workspace)
1068+
1069+
if not os.path.exists(args.config_directory):
1070+
LOG.info("Creating non existing config directory: %s",
1071+
args.config_directory)
1072+
os.makedirs(args.config_directory)
11121073

11131074
with logger.LogCfgServer(
1114-
args.verbose if "verbose" in args else None, workspace=workspace
1075+
args.verbose if "verbose" in args else None, workspace=args.workspace
11151076
):
11161077
try:
11171078
cmd_config.check_config_file(args)

web/server/codechecker_server/server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ def __init__(self,
802802
server_address,
803803
RequestHandlerClass,
804804
config_directory,
805+
workspace_directory,
805806
product_db_sql_server,
806807
pckg_data,
807808
context,
@@ -814,6 +815,7 @@ def __init__(self,
814815
LOG.debug("Initializing HTTP server...")
815816

816817
self.config_directory = config_directory
818+
self.workspace_directory = workspace_directory
817819
self.www_root = pckg_data['www_root']
818820
self.doc_root = pckg_data['doc_root']
819821
self.version = pckg_data['version']
@@ -1147,10 +1149,11 @@ def formatted_address(self) -> str:
11471149
return f"[{str(self.address)}]:{self.port}"
11481150

11491151

1150-
def start_server(config_directory: str, package_data, port: int,
1151-
config_sql_server, listen_address: str,
1152-
force_auth: bool, skip_db_cleanup: bool,
1153-
context, check_env, machine_id: str) -> int:
1152+
def start_server(config_directory: str, workspace_directory: str,
1153+
package_data, port: int, config_sql_server,
1154+
listen_address: str, force_auth: bool,
1155+
skip_db_cleanup: bool, context, check_env,
1156+
machine_id: str) -> int:
11541157
"""
11551158
Starts the HTTP server to handle Web client and Thrift requests, execute
11561159
background jobs.
@@ -1260,6 +1263,7 @@ def _cleanup_incomplete_tasks(action: str) -> int:
12601263
http_server = server_clazz((listen_address, port),
12611264
RequestHandler,
12621265
config_directory,
1266+
workspace_directory,
12631267
config_sql_server,
12641268
package_data,
12651269
context,

0 commit comments

Comments
 (0)