Skip to content

Commit 89a72aa

Browse files
Rework config_directory
1 parent 6c7fcb0 commit 89a72aa

6 files changed

Lines changed: 40 additions & 78 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
@@ -163,9 +163,7 @@ optional arguments:
163163
-h, --help show this help message and exit
164164
-w WORKSPACE, --workspace WORKSPACE
165165
Directory where CodeChecker can store analysis result
166-
related data, such as the database. (Cannot be
167-
specified at the same time with '--sqlite' or
168-
'--config-directory'.) (default:
166+
related data, such as the database. (default:
169167
/home/<username>/.codechecker)
170168
-f CONFIG_DIRECTORY, --config-directory CONFIG_DIRECTORY
171169
Directory where CodeChecker server should read server-
@@ -200,7 +198,7 @@ optional arguments:
200198
201199
configuration database arguments:
202200
--sqlite SQLITE_FILE Path of the SQLite database file to use. (default:
203-
<CONFIG_DIRECTORY>/config.sqlite)
201+
<WORKSPACE_DIRECTORY>/config.sqlite)
204202
--postgresql Specifies that a PostgreSQL database is to be used
205203
instead of SQLite. See the "PostgreSQL arguments"
206204
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
@@ -87,14 +87,11 @@ def add_arguments_to_parser(parser):
8787
default=default_workspace,
8888
required=False,
8989
help="Directory where CodeChecker can store analysis "
90-
"result related data, such as the database. "
91-
"(Cannot be specified at the same time with "
92-
"'--sqlite' or '--config-directory'.)")
90+
"result related data, such as the database.")
9391

9492
parser.add_argument('-f', '--config-directory',
9593
type=str,
9694
dest="config_directory",
97-
default=default_workspace,
9895
required=False,
9996
help="Directory where CodeChecker server should read "
10097
"server-specific configuration (such as "
@@ -152,9 +149,6 @@ def add_arguments_to_parser(parser):
152149
type=str,
153150
dest="sqlite",
154151
metavar='SQLITE_FILE',
155-
default=os.path.join(
156-
'<CONFIG_DIRECTORY>',
157-
"config.sqlite"),
158152
required=False,
159153
help="Path of the SQLite database file to use.")
160154

@@ -356,54 +350,22 @@ def arg_match(options):
356350
# is intended later on.
357351
delattr(args, 'not_host_only')
358352

359-
# --workspace and --sqlite cannot be specified either, as
360-
# both point to a database location.
361-
options = ['--sqlite', '--workspace']
362-
options_short = ['--sqlite', '-w']
363-
if set(arg_match(options)) == set(options) or \
364-
set(arg_match(options_short)) == set(options_short):
365-
parser.error("argument --sqlite: not allowed with "
366-
"argument --workspace")
367-
368-
# --workspace and --config-directory also aren't allowed together now,
369-
# the latter one is expected to replace the earlier.
370-
options = ['--config-directory', '--workspace']
371-
options_short = ['--config-directory', '-w']
372-
if set(arg_match(options)) == set(options) or \
373-
set(arg_match(options_short)) == set(options_short):
374-
parser.error("argument --config-directory: not allowed with "
375-
"argument --workspace")
376-
377353
# If workspace is specified, sqlite is workspace/config.sqlite
378354
# and config_directory is the workspace directory.
379-
if arg_match(['--workspace', '-w']):
355+
if not args.config_directory:
380356
args.config_directory = args.workspace
357+
358+
if not args.sqlite:
381359
args.sqlite = os.path.join(args.workspace,
382360
'config.sqlite')
383-
setattr(args, 'dbdatadir', os.path.join(args.workspace,
384-
'pgsql_data'))
385-
386-
# Workspace should not exist as a Namespace key.
387-
delattr(args, 'workspace')
388-
389-
if '<CONFIG_DIRECTORY>' in args.sqlite:
390-
# Replace the placeholder variable with the actual value.
391-
args.sqlite = args.sqlite.replace('<CONFIG_DIRECTORY>',
392-
args.config_directory)
393361

394362
# Convert relative sqlite file path to absolute.
395-
if 'sqlite' in args:
396-
args.sqlite = os.path.abspath(args.sqlite)
363+
args.sqlite = os.path.abspath(args.sqlite)
397364

398365
if 'postgresql' not in args:
399366
# Later called database modules need the argument to be actually
400367
# present, even though the default is suppressed in the optstring.
401368
setattr(args, 'postgresql', False)
402-
403-
# This is not needed by the database starter as we are
404-
# running SQLite.
405-
if 'dbdatadir' in args:
406-
delattr(args, 'dbdatadir')
407369
else:
408370
# If --postgresql is given, --sqlite is useless.
409371
delattr(args, 'sqlite')
@@ -412,6 +374,10 @@ def arg_match(options):
412374
if "list" in args or "stop" in args or "stop_all" in args:
413375
setattr(args, "instance_manager", True)
414376

377+
# Log directories
378+
LOG.info(f"Workspace directory: {args.workspace}")
379+
LOG.info(f"Config directory: {args.config_directory}")
380+
415381
# If everything is fine, do call the handler for the subcommand.
416382
main(args)
417383

@@ -827,7 +793,7 @@ def __instance_management(args):
827793
if 'stop' in args and \
828794
not (i['port'] == args.view_port and
829795
os.path.abspath(i['workspace']) ==
830-
os.path.abspath(args.config_directory)):
796+
os.path.abspath(args.workspace)):
831797
continue
832798

833799
try:
@@ -855,7 +821,7 @@ def __reload_config(args):
855821
if 'reload' in args and \
856822
not (i['port'] == args.view_port and
857823
os.path.abspath(i['workspace']) ==
858-
os.path.abspath(args.config_directory)):
824+
os.path.abspath(args.workspace)):
859825
continue
860826

861827
try:
@@ -909,13 +875,6 @@ def server_init_start(args):
909875
if not host_check.check_zlib():
910876
raise ModuleNotFoundError("zlib is not available on the system!")
911877

912-
# WARNING
913-
# In case of SQLite args.dbaddress default value is used
914-
# for which the is_localhost should return true.
915-
if is_localhost(args.dbaddress) and \
916-
not os.path.exists(args.config_directory):
917-
os.makedirs(args.config_directory)
918-
919878
# Make sure the SQLite file can be created if it not exists.
920879
if 'sqlite' in args and \
921880
not os.path.isdir(os.path.dirname(args.sqlite)):
@@ -926,7 +885,7 @@ def server_init_start(args):
926885
"option. The server will ask for users to authenticate!")
927886

928887
context = webserver_context.get_context()
929-
context.codechecker_workspace = args.config_directory
888+
context.codechecker_workspace = args.workspace
930889
context.db_username = args.dbusername
931890

932891
environ = env.extend(context.path_env_extra,
@@ -1012,8 +971,8 @@ def server_init_start(args):
1012971

1013972
# Create the main database link from the arguments passed over the
1014973
# command line.
1015-
cfg_dir = os.path.abspath(args.config_directory)
1016-
default_product_path = os.path.join(cfg_dir, 'Default.sqlite')
974+
workspace_dir = os.path.abspath(args.workspace)
975+
default_product_path = os.path.join(workspace_dir, 'Default.sqlite')
1017976
create_default_product = 'sqlite' in args and \
1018977
not os.path.exists(default_product_path)
1019978

@@ -1088,6 +1047,7 @@ def server_init_start(args):
10881047

10891048
try:
10901049
server.start_server(args.config_directory,
1050+
args.workspace,
10911051
package_data,
10921052
args.view_port,
10931053
cfg_sql_server,
@@ -1112,20 +1072,21 @@ def main(args):
11121072
Setup a logger server based on the configuration and
11131073
manage the CodeChecker server.
11141074
"""
1115-
workspace = (
1116-
args.config_directory
1117-
if "config_directory" in args and not hasattr(args, "instance_manager")
1118-
else None
1119-
)
11201075

11211076
# Create workspace directory before logging is initialized.
1122-
if workspace and not os.path.exists(args.config_directory):
1123-
LOG.info("Creating non existing config directory: %s",
1124-
args.config_directory)
1125-
os.makedirs(args.config_directory)
1077+
if not hasattr(args, "instance_manager"):
1078+
if not os.path.exists(args.workspace):
1079+
LOG.info("Creating non existing workspace directory: %s",
1080+
args.workspace)
1081+
os.makedirs(args.workspace)
1082+
1083+
if not os.path.exists(args.config_directory):
1084+
LOG.info("Creating non existing config directory: %s",
1085+
args.config_directory)
1086+
os.makedirs(args.config_directory)
11261087

11271088
with logger.LogCfgServer(
1128-
args.verbose if "verbose" in args else None, workspace=workspace
1089+
args.verbose if "verbose" in args else None, workspace=args.workspace
11291090
):
11301091
try:
11311092
cmd_config.check_config_file(args)

web/server/codechecker_server/server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ def __init__(self,
788788
server_address,
789789
RequestHandlerClass,
790790
config_directory,
791+
workspace_directory,
791792
product_db_sql_server,
792793
pckg_data,
793794
context,
@@ -797,6 +798,7 @@ def __init__(self,
797798
LOG.debug("Initializing HTTP server...")
798799

799800
self.config_directory = config_directory
801+
self.workspace_directory = workspace_directory
800802
self.www_root = pckg_data['www_root']
801803
self.doc_root = pckg_data['doc_root']
802804
self.version = pckg_data['version']
@@ -1086,9 +1088,9 @@ class CCSimpleHttpServerIPv6(CCSimpleHttpServer):
10861088
address_family = socket.AF_INET6
10871089

10881090

1089-
def start_server(config_directory, package_data, port, config_sql_server,
1090-
listen_address, force_auth, skip_db_cleanup: bool,
1091-
context, check_env):
1091+
def start_server(config_directory, workspace_directory, package_data, port,
1092+
config_sql_server, listen_address, force_auth,
1093+
skip_db_cleanup: bool, context, check_env):
10921094
"""
10931095
Start http server to handle web client and thrift requests.
10941096
"""
@@ -1166,6 +1168,7 @@ def start_server(config_directory, package_data, port, config_sql_server,
11661168
http_server = server_clazz(server_addr,
11671169
RequestHandler,
11681170
config_directory,
1171+
workspace_directory,
11691172
config_sql_server,
11701173
package_data,
11711174
context,

0 commit comments

Comments
 (0)