Skip to content

ConfigParser only stores config data #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ The config file needs to specify the following sections and parameters:
- `path`: `organization/repository` part of GitHub URL
- `url`: the full URL of the repository to clone from (may be local path)
- `local_path`: local directory to clone the repository to (without the repository name itself)
- Technology profiles: same as in [example config](config/config.ini)
- DFD: empty section
- `commit`: hash of the commit to checkout and analyze; repository will be returned to the same commit it was in before analysis; if commit not provided, attempts to checkout `HEAD`
- Analysis Settings (optional)
- `development_mode`: boolean, turns on development mode
- `commit`: hash of the commit to checkout and analyze; repository will be returned to the same commit it was in before analysis; if commit not provided, attempts to checkout `HEAD`

It is possible to provide these parameters also by command line, see `python3 code2DFD.py --help` for exact usage

Expand Down
62 changes: 20 additions & 42 deletions code2DFD.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,12 @@
# Author: Simon Schneider, 2023
# Contact: simon.schneider@tuhh.de
import os
from configparser import ConfigParser
from datetime import datetime
import argparse

from core.dfd_extraction import perform_analysis
from output_generators.logger import logger
import tmp.tmp as tmp

CONFIG_SECTIONS = ["Analysis Settings", "Repository", "Technology Profiles", "DFD"]
COMMUNICATIONS_TECH_LIST = '[("RabbitMQ", "rmq"), ("Kafka", "kfk"), ("RestTemplate", "rst"),\
("FeignClient", "fgn"), ("Implicit Connections", "imp"),\
("Database Connections", "dbc"), ("HTML", "html"),\
("Docker-Compose", "dcm")]'
DEFAULT_CONFIG = ConfigParser()
for section in CONFIG_SECTIONS:
DEFAULT_CONFIG.add_section(section)
DEFAULT_CONFIG.set("Analysis Settings", "development_mode", "False")
DEFAULT_CONFIG.set("Technology Profiles", "communication_techs_list", COMMUNICATIONS_TECH_LIST)
from core.config import code2dfd_config


def api_invocation(url: str, commit: str) -> dict:
Expand All @@ -32,18 +20,14 @@ def api_invocation(url: str, commit: str) -> dict:
start_time = datetime.now()

logger.info("*** New execution ***")
logger.debug("Initializing config to tmp file")
for section in CONFIG_SECTIONS: # Copying what is needed from default to temp
tmp.tmp_config.add_section(section)
for entry in DEFAULT_CONFIG[section]:
tmp.tmp_config.set(section, entry, DEFAULT_CONFIG[section][entry])
logger.debug("Initializing config")

# Overwrite repo_path from config file with the one from the API call
tmp.tmp_config.set("Repository", "url", url)
tmp.tmp_config.set("Repository", "local_path",
os.path.join(os.getcwd(), "analysed_repositories"))
code2dfd_config.set("Repository", "url", url)
code2dfd_config.set("Repository", "local_path",
os.path.join(os.getcwd(), "analysed_repositories"))
if commit is not None:
tmp.tmp_config.set("Analysis Settings", "commit", commit)
code2dfd_config.set("Repository", "commit", commit)

# Call extraction
codeable_models, traceability = perform_analysis()
Expand All @@ -69,8 +53,8 @@ def cli_invocation():
repository.add_argument("--repo_url", type=str, help="URL to clone the repository from (might be local path)")
repository.add_argument("--repo_local_path", type=str, help="Location to clone repository to (default: 'analysed_repositories' in CWD)")
repository.add_argument("--github_handle", type=str, help="Handle of a GitHub repository containing the application to be analyzed")
repository.add_argument("--commit", type=str, help="Analyze repository at this commit")
settings = parser.add_argument_group("Analysis Settings", "Parameters for additional analysis settings")
settings.add_argument("--commit", type=str, help="Analyze repository at this commit")
settings.add_argument("--development_mode", action='store_true', help="Switch on development mode")

args = parser.parse_args()
Expand All @@ -79,37 +63,31 @@ def cli_invocation():

if args.config_path:
# Copy config to tmp file
logger.debug("Copying config file to tmp file")
tmp.tmp_config.read(args.config_path)
else:
logger.debug("Copying config file to internal config")
code2dfd_config.read(args.config_path)
# global ini_config
logger.debug("Initializing tmp file with default config")
for section in CONFIG_SECTIONS: # Copying what is needed from default to temp
tmp.tmp_config.add_section(section)
for entry in DEFAULT_CONFIG[section]:
tmp.tmp_config.set(section, entry, DEFAULT_CONFIG[section][entry])

if args.repo_url:
tmp.tmp_config.set("Repository", "url", args.repo_url)
code2dfd_config.set("Repository", "url", args.repo_url)
elif args.github_handle:
tmp.tmp_config.set("Repository", "url", f"https://github.com/{args.github_handle.strip('/')}")
elif not tmp.tmp_config.has_option("Repository", "url"):
code2dfd_config.set("Repository", "url", f"https://github.com/{args.github_handle.strip('/')}")
elif not code2dfd_config.has_option("Repository", "url"):
raise AttributeError("Parameter [Repository][url] must be provided either in config file or by --repo_url")

if args.repo_local_path:
tmp.tmp_config.set("Repository", "local_path", args.local_path)
elif not tmp.tmp_config.has_option("Repository", "local_path"):
tmp.tmp_config.set("Repository", "local_path", os.path.join(os.getcwd(), "analysed_repositories"))
code2dfd_config.set("Repository", "local_path", args.local_path)
elif not code2dfd_config.has_option("Repository", "local_path"):
code2dfd_config.set("Repository", "local_path", os.path.join(os.getcwd(), "analysed_repositories"))

if args.development_mode:
tmp.tmp_config.set("Analysis Settings", "development_mode", "True")
code2dfd_config.set("Analysis Settings", "development_mode", "True")

if args.commit is not None:
commit = args.commit[:7]
tmp.tmp_config.set("Analysis Settings", "commit", commit)
elif tmp.tmp_config.has_option("Analysis Settings", "commit"):
commit = tmp.tmp_config.get("Analysis Settings", "commit")[:7]
tmp.tmp_config.set("Analysis Settings", "commit", commit)
code2dfd_config.set("Repository", "commit", commit)
elif code2dfd_config.has_option("Repository", "commit"):
commit = code2dfd_config.get("Repository", "commit")[:7]
code2dfd_config.set("Repository", "commit", commit)

perform_analysis()

Expand Down
8 changes: 1 addition & 7 deletions config/config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Repository]
url = https://github.com/apssouza22/java-microservice
commit = 056414c4c938e536f467a3f37532194b860d96a3
;url = https://github.com/callistaenterprise/blog-microservices
;url = https://github.com/fernandoabcampos/spring-netflix-oss-microservices
;url = https://github.com/georgwittberger/apache-spring-boot-microservice-example
Expand All @@ -17,12 +18,5 @@ url = https://github.com/apssouza22/java-microservice
;url = https://github.com/rohitghatol/spring-boot-microservices
;url = https://github.com/yidongnan/spring-cloud-netflix-example

[Technology Profiles]
communication_techs_list = [("RabbitMQ", "rmq"), ("Kafka", "kfk"), ("RestTemplate", "rst"), ("FeignClient", "fgn"), ("Implicit Connections", "imp"), ("Database Connections", "dbc"), ("HTML", "html"), ("Docker-Compose", "dcm")]

[Analysis Settings]
development_mode = False
; commit for apssouza22/java-microservice
;commit = 056414c4c938e536f467a3f37532194b860d96a3

[DFD]
8 changes: 8 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from configparser import ConfigParser

code2dfd_config = ConfigParser()

CONFIG_SECTIONS = ["Analysis Settings", "Repository"]
for section in CONFIG_SECTIONS:
code2dfd_config.add_section(section)
code2dfd_config.set("Analysis Settings", "development_mode", "False")
Loading