Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
George Ciesinski committed Jan 23, 2020
2 parents 69f8f69 + 756549b commit 92ba60d
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 29 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ 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).

## [Planned Updates]
- Check for duplicate shortcuts & handle
- Ability to correct shortcut typos using arrow keys instead of just backspace

## [Unreleased]

## [1.2.0] - TBA
### Added
- Support for three directories: default, local, and remote
- Usage statistic printout during program start

## [1.1.0] - 2020-01-17
### Added
- Statistics tracking for shortcuts used, total shortcut characters typed, and total textblock characters pasted
- Help and Exit commands have been added

## [1.0.0] - 2020-01-16
### Added
- Debugging print lines removed
- App prints all of the shortcuts and directories during start
### Changed
- Debugging print lines removed
- Better logging to track potential issues

## [0.0.1] - 2020-01-14
Expand Down
8 changes: 4 additions & 4 deletions Config/config.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[TEXTSCRIPT]
version = 1.1.0
version = 1.2.0

[HISTORY]
shortcutsused = 2
shortcutchars = 13
textblockchars = 692
shortcutsused = 0
shortcutchars = 0
textblockchars = 0

[DIRECTORIES]
defaultdirectory = Textblocks/
Expand Down
118 changes: 117 additions & 1 deletion Settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import configparser
from Logger import Logger
import glib
from os import path
import datetime


class Setup:
Expand Down Expand Up @@ -67,15 +69,129 @@ def create_config(self):

self.log.debug(f"{self.config_dir} file created successfully.")

def get_stats(self):
"""
Gets the current usage stats from the config file.
"""

try:

self.config.read(self.config_dir)

shortcuts_used = self.config['HISTORY']['shortcutsused']
shortcut_chars = self.config['HISTORY']['shortcutchars']
textblock_chars = self.config['HISTORY']['textblockchars']

self.print_stats(shortcuts_used, shortcut_chars, textblock_chars)

except:

self.log.exception("Unable to get stats from config file.")
raise

@staticmethod
def print_stats(shortcuts_used, shortcut_chars, textblock_chars):
"""
Prints the usage stats to console.
"""

saved_keystrokes = str(int(textblock_chars) - int(shortcut_chars))
seconds_to_paste = 5
saved_seconds = int(shortcuts_used) * seconds_to_paste
time_saved = datetime.timedelta(seconds=saved_seconds)

print(f"""Your stats:
- Shortcuts used: {shortcuts_used}
- You typed a total of {shortcut_chars} characters
- Text-Script pasted a total of {textblock_chars} characters
- You saved {saved_keystrokes} keystrokes
- If it takes {seconds_to_paste} seconds to copt & paste an item, you saved {time_saved}""")

def shortcut_setup(self, directories):
"""
Extends shortcut_list and file_dir_list from the shortcuts and file_dirs lists.
"""

shortcut_list = []
file_dir_list = []

# For each directory in directories
for directory in directories:

# Appends shortcuts only if directory is not None
if directory is not None:

# Get shortcuts and file_dirs
shortcuts, file_dirs = self.append_directories(directory)

# Print shortcut title
if directory is directories[0]:
print("\nDefault Directory: \n")
self.log.debug("Appending shortcuts from default directory.")
elif directory is directories[1]:
print(f"\nLocal Directory: {directory}\n")
self.log.debug(f"Appending shortcuts from {directory} directory.")
elif directory is directories[2]:
print(f"\nRemote Directory: {directory}\n")
self.log.debug(f"Appending shortcuts from {directory} directory.")

# Print shortcuts
glib.print_shortcuts(file_dirs, shortcuts)

# extends shortcut_list with values in shortcuts
try:
shortcut_list.extend(shortcuts)
except:
self.log.exception("Failed to extend shortcut_list.")
raise
else:
self.log.debug("Successfully extended shortcut_list")

# append file_dirs to file_dir_list
file_dir_list.extend(file_dirs)

self.log.debug("Successfully appended shortcuts and file_dirs.")

return shortcut_list, file_dir_list

def find_directories(self):
"""
Finds the directories in the config file
"""

self.config.read(self.config_dir)
default_directory = self.config['DIRECTORIES']['defaultdirectory']
local_directory = self.config['DIRECTORIES']['localdirectory']
remote_directory = self.config['DIRECTORIES']['remotedirectory']

if default_directory == "None" or default_directory == "":
default_directory = None
self.log.debug("Default directory is set to None.")
if local_directory == "None" or local_directory == "":
local_directory = None
self.log.debug("Local directory is set to None.")
if remote_directory == "None" or remote_directory == "":
remote_directory = None
self.log.debug("Remote directory is set to None.")

directories = [default_directory, local_directory, remote_directory]
self.log.debug(f"Retrieved the following directories from config: {directories}")

return directories

@staticmethod
def append_directories(directory):
"""
Creates shortcuts and file_dirs
"""

files, file_dirs = glib.list_files(directory)

# Creates shortcut list with the same index
shortcuts = glib.list_shortcuts(files)

return default_directory
return shortcuts, file_dirs


class UpdateConfig:
Expand Down
26 changes: 7 additions & 19 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@
from Logger import Logger
from TextController import WordCatcher, KeyboardEmulator


def shortcut_setup():
"""
Creates shortcut_list and file_dir_list
"""

file_list, file_dir_list = glib.list_files(textblock_dir)

# Creates shortcut list with the same index
shortcut_list = glib.list_shortcuts(file_list)

glib.print_shortcuts(file_dir_list, shortcut_list)

return shortcut_list, file_dir_list


if __name__ == "__main__":

# Current app version / / Ensure this is correct during updates
Expand All @@ -43,14 +27,18 @@ def shortcut_setup():
# Check if config file exists
setup.config_exists()

# Gets file_list and file_dir_list
textblock_dir = setup.find_directories()
# Print stats to console
setup.get_stats()

# Gets a list with default, local, and remote directories
directories = setup.find_directories()

"""
Initialize Text Controller
"""

shortcut_list, file_dir_list = shortcut_setup()
# Load shortcuts and file directories
shortcut_list, file_dir_list = setup.shortcut_setup(directories)

# Initializes KeyboardEmulator instance
k = KeyboardEmulator(L)
Expand Down
8 changes: 4 additions & 4 deletions glib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def list_shortcuts(file_list):
return shortcut_list


def print_shortcuts(file_dir_list, shortcut_list):
def print_shortcuts(file_dirs, shortcuts):

for file_dir in file_dir_list:
index = file_dir_list.index(file_dir)
print(f"Shortcut: {shortcut_list[index]} - - - Directory: {file_dir}")
for file_dir in file_dirs:
index = file_dirs.index(file_dir)
print(f"Shortcut: {shortcuts[index]} - - - Directory: {file_dir}")


if __name__ == "__main__":
Expand Down

0 comments on commit 92ba60d

Please sign in to comment.