Skip to content

Commit

Permalink
Reorganiza fuentes en packages para invocar querier desde gui y consola
Browse files Browse the repository at this point in the history
  • Loading branch information
JCMiguel committed Aug 7, 2023
1 parent 17ec717 commit dee352a
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 46 deletions.
5 changes: 5 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from gui.App import App

if __name__ == "__main__":
app = App()
app.mainloop()
12 changes: 12 additions & 0 deletions config/template_querier_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ repos:
enabled: true
logger: 'default'

pubmed:
url: ''
apikey: WRITE YOUR API KEY HERE!
enabled: true
logger: 'default'

springer:
url: ''
apikey: WRITE YOUR API KEY HERE!
enabled: true
logger: 'default'

params:
tool-name: repository-reviewer
version: 0.1.2
Expand Down
1 change: 1 addition & 0 deletions engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = ["querier"]
45 changes: 45 additions & 0 deletions engine/querier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
# -*- coding: utf8

import yaml
import logging
import logging.config
import traceback
from repos import *


def read_yaml(file_path):
with open(file_path, "r") as f:
return yaml.safe_load(f)


def querier(debug: bool, query: str = "", content: str = "", from_year: str = "",
to_year: str = "", title: str = "", abstract: str = "", redirect_logs = False):
print("Cargando archivo de configuración")
cfg = read_yaml("config/querier_config.yml") # TODO: Pendiente hacer chequeo de errores

if debug:
print("El debug esta habilitado")

print("Cargando clases de repositorios")
for repo in cfg['repos'].keys():
try:
# La línea siguiente invoca a la clase dentro del package.
# Ejemplo: invoca al constructor ieee() de repos.ieee_def
if cfg['repos'][repo]['enabled'] is True:
id = getattr(globals()[repo + '_def'], repo)(cfg['repos'][repo], cfg['params'], debug)
if id is not None:
id.say_hello()
if query == "" or query is None:
id.add_query_param(content, 'content')
id.add_query_param(from_year, 'from_year')
id.add_query_param(title, 'title')
id.add_query_param(to_year, 'to_year')
id.add_query_param(abstract, 'abstract')
else:
id.load_query(args.query)
id.search()
del id
except Exception:
traceback.print_exc()
print("Fin de ejecución")
38 changes: 17 additions & 21 deletions gui/gui.py → gui/App.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import customtkinter as ctk
from querier_page import QuerierPage
from history_page import HistoryPage
from log_frame import LogsFrame
from indexer_page import IndexerPage

from .history_page import HistoryPage
from .indexer_page import IndexerPage
from .log_frame import LogsFrame
from .querier_page import QuerierPage

ctk.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
ctk.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
Expand Down Expand Up @@ -44,7 +45,7 @@ def __init__(self):

# Results and logs
self.log_frame = LogsFrame(parent=container, controller=self)
self.log_frame.grid(row=1, column=0, sticky="nsew", pady=(10,0))
self.log_frame.grid(row=1, column=0, sticky="nsew", pady=(10, 0))

# Sidebar
# FIXME: Intente encapsularlo pero no me gusta como quedo. Hm....
Expand All @@ -62,19 +63,19 @@ def create_sidebar(self, sidebar_frame: ctk.CTkFrame):
sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")
sidebar_frame.grid_rowconfigure(5, weight=1)
logo_label = ctk.CTkLabel(sidebar_frame, text="Stages",
font=ctk.CTkFont(size=20, weight="bold"))
font=ctk.CTkFont(size=20, weight="bold"))
logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
sidebar_button_1 = ctk.CTkButton(sidebar_frame, text="Querier",
command=self.sidebar_querier_button_event)
command=self.sidebar_querier_button_event)
sidebar_button_1.grid(row=1, column=0, padx=20, pady=10)
sidebar_button_2 = ctk.CTkButton(sidebar_frame, text="Quality check",
command=self.sidebar_dummy_button_event)
command=self.sidebar_dummy_button_event)
sidebar_button_2.grid(row=2, column=0, padx=20, pady=10)
sidebar_button_3 = ctk.CTkButton(sidebar_frame, text="Indexer",
command=self.sidebar_indexer_button_event)
command=self.sidebar_indexer_button_event)
sidebar_button_3.grid(row=3, column=0, padx=20, pady=10)
sidebar_button_4 = ctk.CTkButton(sidebar_frame, text="History",
command=self.sidebar_history_button_event)
command=self.sidebar_history_button_event)
sidebar_button_4.grid(row=4, column=0, padx=20, pady=10)

show_logs_checkbox = self.log_frame.Get_enabling_checkBox(sidebar_frame)
Expand All @@ -83,14 +84,14 @@ def create_sidebar(self, sidebar_frame: ctk.CTkFrame):
appearance_mode_label = ctk.CTkLabel(sidebar_frame, text="Appearance Mode:", anchor="w")
appearance_mode_label.grid(row=7, column=0, padx=20, pady=(10, 0))
appearance_mode_optionemenu = ctk.CTkOptionMenu(sidebar_frame,
values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event)
values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event)
appearance_mode_optionemenu.grid(row=8, column=0, padx=20, pady=(10, 10))
scaling_label = ctk.CTkLabel(sidebar_frame, text="UI Scaling:", anchor="w")
scaling_label.grid(row=9, column=0, padx=20, pady=(10, 0))
scaling_optionemenu = ctk.CTkOptionMenu(sidebar_frame,
values=["80%", "90%", "100%", "110%", "120%"],
command=self.change_scaling_event)
values=["80%", "90%", "100%", "110%", "120%"],
command=self.change_scaling_event)
scaling_optionemenu.grid(row=10, column=0, padx=20, pady=(10, 20))

# set default values
Expand All @@ -117,12 +118,12 @@ def sidebar_querier_button_event(self):
# FIXME: Esto es solo un botón de juguete para probar funcionalidades
print("QUERIER BUTOOTN click")
self.show_frame("QuerierPage")
#if self.status == False:
# if self.status == False:
# print(f'status is {self.status}')
# self.checkbox_slider_frame.destroy()
# self.slider_progressbar_frame._draw()
# self.status = True
#else:
# else:
# print(f'status is {self.status}')
# self.slider_progressbar_frame.destroy()
# self.status = False
Expand All @@ -136,8 +137,3 @@ def sidebar_history_button_event(self):
# FIXME: Esto es solo un botón de juguete para probar funcionalidades
print("HISTORY BUTOOTN click")
self.show_frame("HistoryPage")


if __name__ == "__main__":
app = App()
app.mainloop()
1 change: 1 addition & 0 deletions gui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = ["App.py", "history_page", "indexer_page", "log_frame", "misc", "querier_page"]
2 changes: 1 addition & 1 deletion gui/log_frame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import customtkinter as ctk
from misc import StdoutRedirector
from .misc import StdoutRedirector


class LogsFrame(ctk.CTkFrame):
Expand Down
11 changes: 9 additions & 2 deletions gui/querier_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import customtkinter as ctk
from misc import execute
from .misc import execute
from datetime import datetime
from engine.querier import querier


class QuerierPage(ctk.CTkFrame):
Expand Down Expand Up @@ -58,7 +59,13 @@ def querier_tab_search_btn_event(self):
texto += f'Content({self.querier_tab_entry_content.get()})'
# HACK: If search is empty then show help. Just a demo of subproces run
if texto == 'Title() - Abs() - Key() - Content()':
execute("python querier.py -h")
# execute("python querier.py -h")
querier(True, title="xai", content="xai")
# querier(debug = false, "",
# self.querier_tab_entry_content.get(),
# self.querier_tab_entry_title.get(),
# self.querier_tab_entry_abs.get())
# querier(debug: bool, query: str, content: str, from_year: str, title: str, arguments = None)
else:
print(f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} - BUSCAAAARRR\n{texto}\n')
#print("BUSCAARRR!!!!")
Expand Down
35 changes: 13 additions & 22 deletions querier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,13 @@ def read_yaml(file_path):
with open(file_path, "r") as f:
return yaml.safe_load(f)

if __name__ == "__main__" :
args = parser.parse_args()

if args.debug:
print("El debug esta habilitado")
__debug_flag = True
else:
__debug_flag = False


def querier(debug: bool, query: str = "", content: str = "", from_year: str = "", title: str = "", arguments = None):
print("Cargando archivo de configuración")
cfg = read_yaml("config/querier_config.yml") # TODO: Pendiente hacer chequeo de errores
#TODO: validar errores en el config.yml. hay que asegurar que exista todo lo necesario.
# Ejemplo: url, params, apikey, etc.
# Y que exista una clase llamada como en el config.yml

# FIXME: Deberia borrar esto porque fue una prueba
# # Cargamos el diccionario
#logging.config.dictConfig((cfg['params'])['logs'])
# # Creamos el logger definido en el archivo de configuración
#logger = logging.getLogger('Logger_Example')

print(debug)
print("Cargando clases de repositorios")
#repos = [ 'ieee', 'scopus' ]
#print(globals())
for repo in cfg['repos'].keys():
try:
# La línea siguiente invoca a la clase dentro del package.
Expand All @@ -69,6 +51,15 @@ def read_yaml(file_path):
del id
except Exception:
traceback.print_exc()
#del repos
print("Fin de ejecución")


if __name__ == "__main__" :
args = parser.parse_args()

if args.debug:
__debug_flag = True
else:
__debug_flag = False

print("Fin de ejecución")
querier(__debug_flag, args.query, args.content, args.fromYear, args.title)

1 comment on commit dee352a

@bassimat
Copy link
Collaborator

@bassimat bassimat commented on dee352a Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parece que pasó un huracan por este commit, ja! Todo cambio de lugar, parece que llevó bastante trabajo al final reacomodar el proyecto.
Luego me lo voy a bajar para ejecutar y ver que todo sigue funcionando en mi ambiente.
Avanti @JCMiguel !

Please sign in to comment.