Skip to content
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

small fixes for path handling in gui #39

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ src/*
__pycache*
build/*
.vscode/*
dist/d/*
dist/*
*.code-workspace
8 changes: 4 additions & 4 deletions docstring_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# import powerapps classes
from powerapps_docstring.documentation import Docstring
from powerapps_docstring.powerapp import PowerApp

# import screen classes
from docstring_gui.screens.result_screen.result_screen import ResultScreen
Expand All @@ -28,11 +29,10 @@ def create_documentation(self):

# Spot check on CanvasManifest.json file. If this exists, it should be
# a correct power apps source path
if not os.path.isfile(self.source.text + "CanvasManifest.json"):
source_path = PowerApp(self.source.text).get_pa_src_path()
if not os.path.isfile(os.path.join(source_path, "CanvasManifest.json")):
self.source.error = True
self.source.helper_text = "Path is not an Power Apps source"
if not self.source.text.endswith("\\"):
self.source.text = self.source.text + "\\"
return
else:
self.source.error = False
Expand All @@ -59,7 +59,7 @@ def create_documentation(self):

# create documentation
# TODO: add try block and show error page if somethin went wrong
docstring = Docstring(self.source.text, self.output.text, config_instance)
docstring = Docstring(source_path, self.output.text, config_instance)
output_file_path = docstring.create_documentation()

# navigate to succeed page
Expand Down
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def main(argv):
# if programm started without arguments, we run the GUI
if len(opts) == 0:
from docstring_gui import main as gui_main
gui_main()
try:
gui_main()
except TypeError:
# when donwstream application is terminated, it will thro a TypeError exception.
pass

sys.exit(1)

Expand Down
13 changes: 5 additions & 8 deletions powerapps_docstring/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class Docstring():
def __init__(self, source, output, config) -> None:
self.source_path = source
self.output_path = output
self.source_path = os.path.normpath(source)
self.output_path = os.path.normpath(output)
self.parser = Parser(self.source_path)
self.config = config
self.manifest_file = self.parser.get_canvas_manifest()
Expand All @@ -18,7 +18,7 @@ def __init__(self, source, output, config) -> None:

def _get_screen_files(self):
screen_files = []
screens_path = self.source_path + "/Src/"
screens_path = os.path.join(self.source_path, "Src")

# read screen order from manifest and check if files exists
screen_order = self.manifest_file["ScreenOrder"]
Expand Down Expand Up @@ -128,7 +128,6 @@ def get_recursively(search_dict, field):
screenflow_list = [":::mermaid", "graph LR"]

screen_files = self._get_screen_files()
screens_path = self.source_path + "/Src/"

for screen in screen_files:
# check if screen has been excluded
Expand Down Expand Up @@ -221,7 +220,6 @@ def _create_chapter_screens(self):
self.md_file.new_line(scr_flow)

# loop thru all screens and create markdown
screens_path = self.source_path + "/Src/"
for file in self._get_screen_files():
screen_objects = self.parser.get_screen_objects(file)
self._extract_screen_content_to_markdown(screen_objects)
Expand All @@ -236,9 +234,8 @@ def create_documentation(self, format=None):
# instantiate the md file
# TODO: get title from docstring variable
app_name = self.manifest_file["PublishInfo"]["AppName"]
output_file = self.output_path + f'/{app_name}-doc'
self.md_file = MdUtils(file_name=self.output_path +
f'/{app_name}-doc', title='Power App Documentation')
output_file = os.path.join(self.output_path, f'{app_name}-doc')
self.md_file = MdUtils(file_name=output_file, title='Power App Documentation')

for chapter in self.config["DocumentStructure"]:
if chapter == "App":
Expand Down
10 changes: 5 additions & 5 deletions powerapps_docstring/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def get_connections(self) -> dict:
"""
connections = {} # create empty dict

connections_file = self.source_path + "Connections/Connections.json"
connections_file = os.path.join(self.source_path, "Connections", "Connections.json")
if os.path.isfile(connections_file):
with open(connections_file, "r") as file:
connections = json.load(file)

return connections

def _get_screen_content(self, screen_name):
screen_path = self.source_path + "src/" + screen_name
screen_path = os.path.join(self.source_path, "src", screen_name)
screen_content = {}

with open(screen_path, "r", encoding='utf8') as file:
Expand All @@ -35,10 +35,10 @@ def get_screen_objects(self, screen_name) -> tuple:
return screen_name, screen_content

def get_canvas_manifest(self):
app_name = "PowerApp_Documentation"
# get name from CanvasManifest.json
if os.path.isfile(self.source_path + "CanvasManifest.json"):
with open(self.source_path + "CanvasManifest.json", "r", encoding="utf-8") as file:
manifest_file = os.path.join(self.source_path, "CanvasManifest.json")
if os.path.isfile(manifest_file):
with open(manifest_file, "r", encoding="utf-8") as file:
canvas_manifest = json.load(file)

return canvas_manifest
7 changes: 1 addition & 6 deletions powerapps_docstring/powerapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ class UnknownSourceException(Exception):

class PowerApp():
def __init__(self, source) -> None:
self.source = source
self.source = os.path.normpath(source)
self.source_type = self._check_source_type()

def get_pa_src_path(self):
source_path = None
if self.source_type == "directory":
# TODO: check if directory contains powerapp content

if self.source[-1] != "/":
self.source = self.source + "/"

source_path = self.source
elif self.source_type == "zip":
# TODO: unzip and unpack msssap to retrieve src folder
Expand Down