From 9d9eb7a631d1b78ae03cfea088af88865eff0ca7 Mon Sep 17 00:00:00 2001 From: danthb Date: Mon, 7 Feb 2022 22:14:52 -0500 Subject: [PATCH 1/3] Set local env, gitignore file --- .gitignore | 175 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 29 ++++++-- aplicacion.sqlite | Bin 24576 -> 24576 bytes 3 files changed, 197 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b86eb24..5e2f459 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,178 @@ .idea/* src/modelo/__pycache__/* src/logica/__pycache__/* +## Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### VisualStudioCode ### +.vscode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope \ No newline at end of file diff --git a/README.md b/README.md index a183dce..2cf9ad7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,25 @@ # Tutorial de SQLAlchemy Para el desarrollo de este tutorial es importante cumplir con los siguientes requisitos: -* Tener Python y pip correctamente instalados y actualizados a una versión reciente. Si aún no los instala, puede descargar las versiones para los diferentes sistemas operativos en https://www.python.org/downloads/ y si es necesario revisar las instrucciones de instalación, se pueden seguir en sitios como https://realpython.com/installing-python/ -* Instalar un IDE. Se recomienda utilizar PyCharm Community Edition (Disponible en: https://www.jetbrains.com/es-es/pycharm/download/) ó Visual Studio Code (Disponible en: https://code.visualstudio.com/download) -* Descargar el código del repositorio https://github.com/MISW-4101-Practicas/TutorialCancionesUnittest -* Iniciar un virtual environment (venv) para separar el uso de librerías de este proyecto de otros proyectos. Si no ha creado un virtual environment, puede seguir las instrucciones del sitio https://docs.python.org/3/library/venv.html -* Instalar SQLAlchemy - -Con estos requisitos ya es posible comenzar con el tutorial. \ No newline at end of file + +- Para Instalar y configurar ambientes virtuales en Python puede usar [virtualenv](https://virtualenv.pypa.io/en/latest/userguide.html) + + ```bash + $ pip install virtualenv + Configuración de ambiente virtual + ``` + + ```bash + python3 -m venv venv + .\venv\Scripts\activate + pip install -r requirements.txt + deactivate + ``` + +- Tener Python y pip correctamente instalados y actualizados a una versión reciente. Si aún no los instala, puede descargar las versiones para los diferentes sistemas operativos en https://www.python.org/downloads/ y si es necesario revisar las instrucciones de instalación, se pueden seguir en sitios como https://realpython.com/installing-python/ +- Instalar un IDE. Se recomienda utilizar PyCharm Community Edition (Disponible en: https://www.jetbrains.com/es-es/pycharm/download/) ó Visual Studio Code (Disponible en: https://code.visualstudio.com/download) +- Descargar el código del repositorio https://github.com/MISW-4101-Practicas/TutorialCancionesUnittest +- Iniciar un virtual environment (venv) para separar el uso de librerías de este proyecto de otros proyectos. Si no ha creado un virtual environment, puede seguir las instrucciones del sitio https://docs.python.org/3/library/venv.html +- Instalar SQLAlchemy + +Con estos requisitos ya es posible comenzar con el tutorial. diff --git a/aplicacion.sqlite b/aplicacion.sqlite index 62993bba7de6f0334901552912f95ef15aab405c..1041c0a95c055df079d19152bb6c9957c0df6f74 100644 GIT binary patch literal 24576 zcmeI4&ub%99Khep%$v!iX`Vd=tu3#VH7!jGWnp3U;xwIhYtvMd>|#&lHJO%KCo|od zNm_ty|@jH`bn{-KNK?*D12gCRM{J!t^ z^S(X2Z)Z|_tL#L!*!P2$jKp>F0-=<=E(9T@2#*F&uc%OopI)K8$_QB`OPe2!=k^K9 zt`Yun&KsY}EkG3u5oDx-mGqHnbjS!Y3+zPr#T<@t!-DWjrB_0H`iS< zFRIp>RkbQ5t0sDC;`y2R6J62sg#vxJmAEF|y>@H2J7u7u4mdb46#Lj+vOC1r&io;R z174gdDvI8!VSd4GLtQ(M;;F8F7D;D9E;D~q)$&^fN*u3g-w*G(aBtj|?Z{8syPf4d zkdvc7mQ>H@^Yr1&+0iF{r3NhRG8!7j&)O+Hzu!g(<3`{dCb8QW z>@BRMZPDRW8O8AfbV}6&v%5`X9K>|ns2_OL^fCP{L5Z!;eYaP_^13sZu2U?!E?}s1qmPl zB!C2v01`j~NB{{S0VIF~kih?ez=WZZNlGV7*FFdwsZN@=UrB4^I;FE~e$cR+V$}%` zAxU7jY%fx>tMG4n$RjkIrvH+zkr$~^Fz-6D;VU)SYTK@;`$1rb6Oej1uNJZk7g7r; zg`sL8eQ;haqz5jf7SaO4)W-M!EdQMFC;T7&m_Oow@Zb2){0II$|BinJ16Ys%5PPC8q0u4GiJms#?l}(mFXZKZ)=EfAPQhDgPb51o#DR|KIY@_?Iw%1qmPlB!C2v z01`j~NB{{S0VIF~kN^_68UngX<4b=wk-9dP$TZ7z+RR9#rlu3As(K=sqIKE|OC((W zHPxUrrD!UJBtS}44Z|4En~?{z1BT#gTJl3)>Tw9Xf@WSHtg w`eGhvQ~D?mv}tXm2W&buay$ixIn^`y8IlF{Vn!-c$|xh1B8@Q`7d+{I0cu&5jQ{`u delta 303 zcmZoTz}Rqrae_3X+C&*=Ry77a` ziB<_4k`jx79QMQLs&jRLssj>BQWNu1@)Zg)Q&Wl(Q4RG2o9d Date: Mon, 7 Feb 2022 22:16:58 -0500 Subject: [PATCH 2/3] Updated README file --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2cf9ad7..b02adf5 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,16 @@ Para el desarrollo de este tutorial es importante cumplir con los siguientes req ```bash $ pip install virtualenv - Configuración de ambiente virtual ``` - ```bash - python3 -m venv venv - .\venv\Scripts\activate - pip install -r requirements.txt - deactivate - ``` +- Configuración de ambiente virtual + +```bash +python3 -m venv venv +.\venv\Scripts\activate +pip install -r requirements.txt +deactivate +``` - Tener Python y pip correctamente instalados y actualizados a una versión reciente. Si aún no los instala, puede descargar las versiones para los diferentes sistemas operativos en https://www.python.org/downloads/ y si es necesario revisar las instrucciones de instalación, se pueden seguir en sitios como https://realpython.com/installing-python/ - Instalar un IDE. Se recomienda utilizar PyCharm Community Edition (Disponible en: https://www.jetbrains.com/es-es/pycharm/download/) ó Visual Studio Code (Disponible en: https://code.visualstudio.com/download) From 324571a1a846b6320ea7d7324dbfd70e8c6b9d71 Mon Sep 17 00:00:00 2001 From: htenezaca Date: Wed, 16 Feb 2022 09:55:18 -0500 Subject: [PATCH 3/3] Added some files to upload, delete and recover data --- actualizacion_datos.py | 17 +++++++++++++++++ borrar_datos.py | 15 +++++++++++++++ recuperar.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 actualizacion_datos.py create mode 100644 borrar_datos.py create mode 100644 recuperar.py diff --git a/actualizacion_datos.py b/actualizacion_datos.py new file mode 100644 index 0000000..d9ebddd --- /dev/null +++ b/actualizacion_datos.py @@ -0,0 +1,17 @@ +from src.modelo.cancion import Cancion +from src.modelo.interprete import Interprete +from src.modelo.declarative_base import Session, engine, Base + + +if __name__ == '__main__': + session = Session() + cancion = session.query(Cancion).get(2) + interprete = session.query(Interprete).get(4) + + cancion.minutos = 5 + cancion.segundos = 30 + cancion.compositor = "Pedro Pérez" + cancion.interpretes.append(interprete) + session.add(cancion) + session.commit() + session.close() \ No newline at end of file diff --git a/borrar_datos.py b/borrar_datos.py new file mode 100644 index 0000000..f156018 --- /dev/null +++ b/borrar_datos.py @@ -0,0 +1,15 @@ +from src.modelo.cancion import Cancion +from src.modelo.interprete import Interprete +from src.modelo.album import Album, Medio +from src.modelo.declarative_base import Session, engine, Base + +if __name__ == '__main__': + session = Session() + cancion2 = session.query(Cancion).get(2) + session.delete(cancion2) + session.commit() + session.close() + + """ En el ejemplo, y según la definición de las clases, se debe tener cuidado con el borrado de intérpretes, dado que, al no estar relacionados a través de la instrucción relationship, + es posible borrarlos y dejar las canciones con una relación a un intérprete inexistente. + Para profundizar en las relaciones se recomienda revisar esta referencia. """ diff --git a/recuperar.py b/recuperar.py new file mode 100644 index 0000000..d4c2253 --- /dev/null +++ b/recuperar.py @@ -0,0 +1,32 @@ +from src.modelo.cancion import Cancion +from src.modelo.interprete import Interprete +from src.modelo.album import Album, Medio +from src.modelo.declarative_base import Session, engine, Base + + +if __name__ == '__main__': + session = Session() + canciones = session.query(Cancion).all() + + print('Las canciones almacenadas son:') + for cancion in canciones: + print("Titulo: " + cancion.titulo + " (00:" + + str(cancion.minutos) + ":" + + str(cancion.segundos) + ")") + + print("Intérpretes") + for interprete in cancion.interpretes: + print(" - " + interprete.nombre) + + for album in cancion.albumes: + print(" -- Presente en el album: " + album.titulo) + + print("") + + + print('Los álbumes almacenados en discos son:') + albumes = session.query(Album).filter(Album.medio == Medio.DISCO).all() + for album in albumes: + print("Album: " + album.titulo) + + session.close() \ No newline at end of file