Skip to content

Commit

Permalink
Merge pull request #282 from toonarmycaptain/development
Browse files Browse the repository at this point in the history
Add temp dir, cleanup codebase, ready for release 0.6.0
  • Loading branch information
toonarmycaptain authored Apr 1, 2020
2 parents 28f5651 + 83c1000 commit dc9d99f
Show file tree
Hide file tree
Showing 28 changed files with 1,382 additions and 1,121 deletions.
94 changes: 94 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "HCamberos",
"name": "HCamberos",
"avatar_url": "https://avatars2.githubusercontent.com/u/56201325?v=4",
"profile": "https://github.com/HCamberos",
"contributions": [
"code"
]
},
{
"login": "mbarakaja",
"name": "José María Domínguez",
"avatar_url": "https://avatars0.githubusercontent.com/u/7861175?v=4",
"profile": "https://github.com/mbarakaja",
"contributions": [
"infra"
]
},
{
"login": "destag",
"name": "Przemysław Pietras",
"avatar_url": "https://avatars2.githubusercontent.com/u/16159069?v=4",
"profile": "https://github.com/destag",
"contributions": [
"infra",
"doc"
]
},
{
"login": "malexanderboyd",
"name": "M. Alex Boyd",
"avatar_url": "https://avatars2.githubusercontent.com/u/2465264?v=4",
"profile": "https://github.com/malexanderboyd",
"contributions": [
"code",
"test"
]
},
{
"login": "Ginkooo",
"name": "Piotr Czajka",
"avatar_url": "https://avatars3.githubusercontent.com/u/11911709?v=4",
"profile": "https://github.com/Ginkooo",
"contributions": [
"code",
"test"
]
},
{
"login": "toonarmycaptain",
"name": "toonarmycaptain",
"avatar_url": "https://avatars3.githubusercontent.com/u/29956894?v=4",
"profile": "https://github.com/toonarmycaptain",
"contributions": [
"code",
"doc",
"design",
"ideas",
"maintenance"
]
},
{
"login": "schedutron",
"name": "Saurabh Chaturvedi",
"avatar_url": "https://avatars1.githubusercontent.com/u/22810216?v=4",
"profile": "https://stackoverflow.com/story/samchats",
"contributions": [
"code"
]
},
{
"login": "AbdullahElagha",
"name": "AbdullahElagha",
"avatar_url": "https://avatars3.githubusercontent.com/u/20312723?v=4",
"profile": "https://github.com/AbdullahElagha",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
"projectName": "dionysus",
"projectOwner": "toonarmycaptain",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true
}
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0-alpha] - 2020-04-01
### Added
- Implemented `temp` directory created in `APP_DATA` by `data_folder_check` on app start and removed on app exit (if it contains files).
- `NewClass` subclass of `Class` using `temp` directory to hold files before writing to database.
- Initially holds avatars as user enters during class creation.
- Add [AllContributors](https://allcontributors.org/) badge to `README.md`, recognising project contributors, `.all-contributorsrc` with contributer data.
### Changed
- Separate UI/logic/persistence concerns in `create_classlist`.
- New functions `move_avatars_to_class_data`, `move_avatar_to_class_data` utilise `NewClass` to move avatars from `temp` to database.
- `write_classlist_to_file` now returns `None` instead of the path written to. Future persistence layer may be a Database rather than a path.
- `create_classlist_data` takes a `NewClass` object.
- Refactor `new_chart`/`assemble_chart_data` to take `Class`/`NewClass` object instead of a class name.
- Supports passing in class directly from `create_class` without reloading class from database.
- Move logic prompting user to choose a class from `assemble_chart_data` to `new_chart`.
- More tests converted to Pytest style tests, test coverage improved (eg `class_registry_functions.py`).
- Improved type hinting, extend passing/use of `Path`s rather than strings/`os/path` (eg in `UI_functions.py`, `initialise_app.py`).

## [0.5.0-alpha] - 2020-01-23
### Added
- Improved test coverage, type hinting across application.
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## dionysus - Avatar chart generator
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![Build Status](https://travis-ci.org/toonarmycaptain/dionysus.svg?branch=master)](https://travis-ci.org/toonarmycaptain/dionysus)
[![CircleCI](https://circleci.com/gh/toonarmycaptain/dionysus/tree/master.svg?style=svg)](https://circleci.com/gh/toonarmycaptain/dionysus/tree/master)
[![Build status](https://ci.appveyor.com/api/projects/status/yb33uwd13tkv7l79?svg=true)](https://ci.appveyor.com/project/toonarmycaptain/dionysus)
Expand Down Expand Up @@ -36,3 +39,30 @@ Either click on `app_main.py` in the project folder, or navigate to the folder a
#### Versioning
As much as possible this project will follow [Semantic Versioning](https://semver.org/).


## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/toonarmycaptain"><img src="https://avatars3.githubusercontent.com/u/29956894?v=4" width="100px;" alt=""/><br /><sub><b>toonarmycaptain</b></sub></a><br /><a href="https://github.com/toonarmycaptain/dionysus/commits?author=toonarmycaptain" title="Code">💻</a> <a href="https://github.com/toonarmycaptain/dionysus/commits?author=toonarmycaptain" title="Documentation">📖</a> <a href="#design-toonarmycaptain" title="Design">🎨</a> <a href="#ideas-toonarmycaptain" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-toonarmycaptain" title="Maintenance">🚧</a></td>
<td align="center"><a href="https://github.com/destag"><img src="https://avatars2.githubusercontent.com/u/16159069?v=4" width="100px;" alt=""/><br /><sub><b>Przemysław Pietras</b></sub></a><br /><a href="#infra-destag" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/toonarmycaptain/dionysus/commits?author=destag" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/Ginkooo"><img src="https://avatars3.githubusercontent.com/u/11911709?v=4" width="100px;" alt=""/><br /><sub><b>Piotr Czajka</b></sub></a><br /><a href="https://github.com/toonarmycaptain/dionysus/commits?author=Ginkooo" title="Code">💻</a> <a href="https://github.com/toonarmycaptain/dionysus/commits?author=Ginkooo" title="Tests">⚠️</a></td>
<td align="center"><a href="https://stackoverflow.com/story/samchats"><img src="https://avatars1.githubusercontent.com/u/22810216?v=4" width="100px;" alt=""/><br /><sub><b>Saurabh Chaturvedi</b></sub></a><br /><a href="https://github.com/toonarmycaptain/dionysus/commits?author=schedutron" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/malexanderboyd"><img src="https://avatars2.githubusercontent.com/u/2465264?v=4" width="100px;" alt=""/><br /><sub><b>M. Alex Boyd</b></sub></a><br /><a href="https://github.com/toonarmycaptain/dionysus/commits?author=malexanderboyd" title="Code">💻</a> <a href="https://github.com/toonarmycaptain/dionysus/commits?author=malexanderboyd" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/mbarakaja"><img src="https://avatars0.githubusercontent.com/u/7861175?v=4" width="100px;" alt=""/><br /><sub><b>José María Domínguez</b></sub></a><br /><a href="#infra-mbarakaja" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center"><a href="https://github.com/HCamberos"><img src="https://avatars2.githubusercontent.com/u/56201325?v=4" width="100px;" alt=""/><br /><sub><b>HCamberos</b></sub></a><br /><a href="https://github.com/toonarmycaptain/dionysus/commits?author=HCamberos" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/AbdullahElagha"><img src="https://avatars3.githubusercontent.com/u/20312723?v=4" width="100px;" alt=""/><br /><sub><b>AbdullahElagha</b></sub></a><br /><a href="https://github.com/toonarmycaptain/dionysus/commits?author=AbdullahElagha" title="Documentation">📖</a></td>
</tr>
</table>


<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
3 changes: 2 additions & 1 deletion app_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import definitions

from dionysus_app.class_registry_functions import cache_class_registry, check_registry_on_exit
from dionysus_app.initialise_app import app_init
from dionysus_app.initialise_app import app_init, clear_temp
from dionysus_app.UI_menus.main_menu import run_main_menu
from dionysus_app.settings_functions import load_chart_save_folder

Expand All @@ -20,6 +20,7 @@ def quit_app():
:return: None
"""
check_registry_on_exit() # Dump cached registry to disk if different class_registry.index.
clear_temp() # Clear temp files.
sys.exit()


Expand Down
7 changes: 5 additions & 2 deletions data_version_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dionysus_app.class_ import Class
from dionysus_app.class_functions import write_classlist_to_file
from dionysus_app.data_folder import DataFolder
from dionysus_app.data_folder import DataFolder, CLASSLIST_DATA_FILE_TYPE
from dionysus_app.file_functions import load_from_json_file
from dionysus_app.student import Student
from dionysus_app.UI_menus.UI_functions import select_file_dialogue
Expand Down Expand Up @@ -112,7 +112,10 @@ def transform_old_cld_file(filepath: Path):
class_name = filepath.stem
new_class = transform_data(class_name, old_class_data)

new_class_data_path_name = write_classlist_to_file(new_class)
write_classlist_to_file(new_class)

new_filename = class_name + CLASSLIST_DATA_FILE_TYPE
new_class_data_path_name = CLASSLIST_DATA_PATH.joinpath(class_name, new_filename)

print(f'Transformed {new_class.name} data file '
f'to new data format in {new_class_data_path_name}')
Expand Down
70 changes: 41 additions & 29 deletions dionysus_app/UI_menus/UI_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

from pathlib import Path
from tkinter import filedialog
from typing import Optional, Union, List, Tuple


def clear_screen(num_lines=50):
def clear_screen(num_lines: int = 50) -> None:
clear_seq = '\n' * num_lines

print(clear_seq)
Expand All @@ -17,7 +18,7 @@ def clear_screen(num_lines=50):
# User input and string processing functions:


def input_is_essentially_blank(subject_string: str):
def input_is_essentially_blank(subject_string: str) -> bool:
"""
Return True if string is empty or primarily composed of spaces, underscores,
special characters (eg brackets, punctuation).
Expand All @@ -35,7 +36,7 @@ def input_is_essentially_blank(subject_string: str):
return False


def clean_for_filename(some_string: str):
def clean_for_filename(some_string: str) -> str:
"""
Cleans a string for use as a filename.
eg student or classlist name
Expand All @@ -52,7 +53,7 @@ def clean_for_filename(some_string: str):
return cleaned_filename


def scrub_candidate_filename(dirty_string: str):
def scrub_candidate_filename(dirty_string: str) -> str:
"""
Cleans string of non-alpha-numeric characters, but leaves spaces, dashes,
and underscores, stripping trailing spaces.
Expand All @@ -70,22 +71,21 @@ def scrub_candidate_filename(dirty_string: str):
:return: str
"""
allowed_special_characters = [' ', '_', '-', ]
cleaned_string = "".join([c
if c.isalnum()
or c in allowed_special_characters
cleaned_string = "".join([c if c.isalnum()
or c in allowed_special_characters
else '_'
for c in dirty_string
]).rstrip()

return cleaned_string


def save_as_dialogue(title_str=None,
default_file_extension=None,
filetypes=None,
suggested_filename=None,
start_dir=None
):
def save_as_dialogue(title_str: str = None,
default_file_extension: str = None,
filetypes: List[Tuple[str, str]] = None,
suggested_filename: str = None,
start_dir: Union[Path, str] = '..'
) -> Optional[Path]:
"""
Prompts user to select a directory and filename to save a file to.
Calls tkinter filedialog.asksaveasfilename with title (if provided), and
Expand Down Expand Up @@ -114,7 +114,10 @@ def save_as_dialogue(title_str=None,
Returns None instead of empty string if no file is selected.
Default starting directory is directory above application directory.
If start_dir is unresolvable, or '' or None, the dialog will default to
starting at the last directory selected.
See https://www.tcl.tk/man/tcl8.6/TkCmd/chooseDirectory.htm
NB When default_file_extension is given, but not in filetypes, if
the first filetype in filetypes is NOT ("all files", "*.*"), that
Expand All @@ -125,9 +128,9 @@ def save_as_dialogue(title_str=None,
:param title_str: str
:param default_file_extension: list
:param suggested_filename: str
:param filetypes: list
:param start_dir: str
:return: str
:param filetypes: List[Tuple[str, str]]
:param start_dir: Path or str
:return: Path
"""
root = tk.Tk()
root.withdraw()
Expand All @@ -150,29 +153,35 @@ def save_as_dialogue(title_str=None,

if filepath_str == '':
return None
return filepath_str
return Path(filepath_str)


def select_file_dialogue(title_str=None,
filetypes=None,
start_dir=None,
):
def select_file_dialogue(title_str: str = None,
filetypes: List[Tuple[str, str]] = None,
start_dir: Union[Path, str] = '..',
) -> Optional[Path]:
"""
Prompts user to select a file. Calls tkinter filedialog.askopenfilename
with title (if provided), and filetype argument (if provided) eg '*.png'.
filetypes is a list of tuples with 2 values, a label and a pattern
eg for png and all files: [('.png', '*.png'), ("all files", "*.*")]
Default starting directory is directory above application directory.
If start_dir is unresolvable, or '' or None, the dialog will default to
starting at the last directory selected on recent versions of Windows,
current working directory on old Windows/other OS.
See https://www.tcl.tk/man/tcl8.6/TkCmd/chooseDirectory.htm
Returns None instead of empty string if no file is selected.
NB If no title is passed to filedialog.askopenfilename, the window
title will be "Open".
:param title_str: str
:param filetypes: list
:param filetypes: List[Tuple[str, str]]
:param start_dir: str
:return: str
:return: Path or None
"""
root = tk.Tk()
root.withdraw()
Expand All @@ -190,19 +199,22 @@ def select_file_dialogue(title_str=None,
return Path(filepath_str)


def select_folder_dialogue(title_str=None, start_dir='..'):
def select_folder_dialogue(title_str: str = None, start_dir: Union[Path, str] = '..'):
"""
Prompts user to select a file. Calls tkinter filedialog.askopenfilename
with title (if provided), and filetype argument (if provided) eg '*.png'.
filetypes is a list of tuples with 2 values, a label and a pattern
eg for png and all files: [('.png', '*.png'), ("all files", "*.*")]
Default starting directory is directory above application directory.
If start_dir is unresolvable, or '' or None, the dialog will default to
starting at the last directory selected on recent versions of Windows,
current working directory on old Windows/other OS.
See https://www.tcl.tk/man/tcl8.6/TkCmd/chooseDirectory.htm
Returns None instead of empty string if no file is selected.
:param title_str: str
:param start_dir: str - Path for dialogue to start in.
:return: str
:param start_dir: Path or str - Path for dialogue to start in.
:return: Path
"""
root = tk.Tk()
root.withdraw()
Expand Down
5 changes: 3 additions & 2 deletions dionysus_app/UI_menus/class_functions_UI.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""UI elements for class_functions"""
from typing import Union
from pathlib import Path
from typing import Optional, Union

from dionysus_app.class_ import Class
from dionysus_app.class_registry_functions import classlist_exists
Expand Down Expand Up @@ -183,7 +184,7 @@ def take_student_selection(student_options: dict):
return selected_student


def select_avatar_file_dialogue():
def select_avatar_file_dialogue() -> Optional[Path]:
"""
Prompts user to select an avatar file. Currently only displays PNG files by
default.
Expand Down
Loading

0 comments on commit dc9d99f

Please sign in to comment.