Modules¶
kvalikirstu2.arg_parser.py¶
A module for the argument parser class in Kvalikirstu.
-
exception
kvalikirstu2.arg_parser.ConfigFileParsingException[source]¶ Bases:
ExceptionRaised when parsing args fails (during gui run)
kvalikirstu2.argument_parser.py¶
A module for parsing command line arguments and logging.
-
exception
kvalikirstu2.argument_parser.ArgumentsNotParsedException[source]¶ Bases:
Exceptionget_args called before parsing arguments
-
exception
kvalikirstu2.argument_parser.ArgumentsNotSavedException(inner_exception, *args, **kwargs)[source]¶ Bases:
ExceptionException occurred while saving args.
-
exception
kvalikirstu2.argument_parser.ConfigFileParsingException[source]¶ Bases:
ExceptionRaised when parsing args fails (during gui run)
-
class
kvalikirstu2.argument_parser.Settings[source]¶ Bases:
objectClass for command line settings.
Gets arguments that are shared between the GUI and the cmd version
-
parse_command_line(args)[source]¶ Parse command line arguments and assign parser options to settings.
- Parameters:
argv – arguments passed to
configargparse.ArgumentParser- Returns:
parsed arguments.
- Return type:
argparse.Namespace
-
kvalikirstu2.argument_parser.change_setting(setting_title, new_value)[source]¶ Change a single setting
- Parameters:
setting_title – The name of the setting.
new_value – The new value for the setting.
-
kvalikirstu2.argument_parser.register_archive_interface(interface)[source]¶ Called when the package is loaded to allow for data archive specific arguments to be loaded.
- Parameters:
interface (DataArchiveInterface) – The interface.
kvalikirstu2.backup_select_window.py¶
kvalikirstu2.converter.py¶
A module for converting arbitrary text to UTF-8 and converting other files to .odt with Libreoffice. All Libreoffice code is contained inside this module.
-
exception
kvalikirstu2.converter.ConversionException[source]¶ Bases:
ExceptionException that should be raised when an error occurs in data conversion.
-
kvalikirstu2.converter.convert(content)[source]¶ Converts content in arbitrary encoding to UTF-8.
- Parameters:
content (bytes) – The content to be converted.
- Returns:
UTF-8 encoded string
-
kvalikirstu2.converter.convert_file(filepath, out_encoding)[source]¶ Converts a file to the given encoding:
- Parameters:
filepath – The path of the file to be converted.
out_encoding – The encoding to be used.
-
kvalikirstu2.converter.convert_file_encoding_in_folder(folder_path, out_encoding, file_extension)[source]¶ Converts all files to the given encoding.
- Parameters:
folder_path – The path of the folder.
out_encoding – The encoding to be used.
file_extension – The file extension.
-
kvalikirstu2.converter.convert_files_with_libreoffice_to_odt(path, timeout)[source]¶ Converts suitable files with LibreOffice from the path to odt.
- Parameters:
path – The path of the files to be converted.
timeout – The timeout used for Libreoffice.
kvalikirstu2.csv_generator.py¶
A module for generating .csv files out of studies.
-
kvalikirstu2.csv_generator.create_csv(loaded_study: kvalikirstu2.study.Study, language, encoding, csv_filename, header_info, language_codes=None)[source]¶ Creates a .csv file from the study. This function assumes that headers have already been remapped prior to calling this function.
- Parameters:
loaded_study – The study from which the .csv file is generated from.
language – The language of the .csv file.
encoding – The encoding for the .csv file.
csv_filename – The filename for the csv file.
header_info – The header information for the study.
language_codes – The set of possible language codes.
kvalikirstu2.data_archive_interface.py¶
A module for the DataArchiveInterface base class.
-
class
kvalikirstu2.data_archive_interface.Command(func, text, help_text)[source]¶ Bases:
objectA command that can be issued via the GUI.
- Variables:
text – The label of the command.
help_text – The help text associated with the command.
-
class
kvalikirstu2.data_archive_interface.DataArchiveInterface[source]¶ Bases:
objectAn abstract baseclass to isolate any FSD specific functionality out of the main program.
-
add_cli_arguments(argument_parser)[source]¶ Add CLI arguments based on the needs of the data repository.
- Parameters:
argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.
-
add_gui_arguments(argument_parser)[source]¶ Add GUI arguments based on the needs of the data repository.
- Parameters:
argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.
Add shared arguments based on the needs of the data repository. Shared means it’s used for both the CLI and GUI
- Parameters:
argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.
-
create_csv_name(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]¶ Returns the name of the .csv file for the study with the given ID.
- Parameters:
metadata (MetadataInformation) – The metadata of the study.
-
get_commands()[source]¶ Returns a list of commands that can be executed from the GUI.
- Returns:
A list of commands.
-
get_metadata_files(study_path, data_path)[source]¶ Returns a list of files that are metadata files of the study in the data folder.
- Parameters:
study_path (str) – The path of the study.
data_path (str) – The path of the data folder.
-
get_study_data_filename(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]¶ Gets a data file name for the study with the given ID. Used when generating a single data file for a study that consists of external data files such as PDF-files or image files that are not directly readable.
- Parameters:
metadata (MetadataInformation) – The metadata of the study.
-
parse_study_information(study_path, data_path)[source]¶ Parses study metadata from given path.
- Parameters:
study_path – The path of the study folder.
data_path – The path of the data folder.
- Return type:
-
rename_data_files_in_folder(metadata: kvalikirstu2.data_archive_interface.MetadataInformation, data_path: str)[source]¶ Rename data files in a folder to use whatever the standard naming scheme is. In the FSD case this is FSDxxxx_xx.txt/odt/etc.
- Parameters:
metadata – The metadata of the study.
data_path (str) – The path of the data folder.
-
-
class
kvalikirstu2.data_archive_interface.DummyInterface[source]¶ Bases:
kvalikirstu2.data_archive_interface.DataArchiveInterfaceAn dummy class to implement basic functionality so that the program can work.
-
add_cli_arguments(argument_parser)[source]¶ Add CLI arguments based on the needs of the data repository.
- Parameters:
argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.
-
add_gui_arguments(argument_parser)[source]¶ Add GUI arguments based on the needs of the data repository.
- Parameters:
argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.
Add shared arguments based on the needs of the data archive. Shared means it’s used for both the CLI and GUI
- Parameters:
argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.
-
create_csv_name(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]¶ Returns the name of the .csv file for the study with the given ID.
- Parameters:
metadata (MetadataInformation) – The metadata of the study.
-
get_metadata_files(study_path, data_path)[source]¶ Returns a list of files that are metadata files of the study in the data folder.
- Parameters:
study_path (str) – The path of the study.
data_path (str) – The path of the data folder.
-
get_study_data_filename(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]¶ Gets a data file name for the study with the given ID. Used when generating a single data file for a study that consists of external data files such as PDF-files or image files that are not directly readable.
- Parameters:
metadata (MetadataInformation) – The metadata of the study.
-
parse_study_information(study_path, data_path)[source]¶ Parses study metadata from given path.
- Parameters:
study_path – The path of the study folder.
data_path – The path of the data folder.
- Return type:
-
rename_data_files_in_folder(metadata: kvalikirstu2.data_archive_interface.MetadataInformation, data_path: str)[source]¶ Rename data files in a folder to use whatever the standard naming scheme is. In the FSD case this is FSDxxxx_xx.txt/odt/etc.
- Parameters:
metadata – The metadata of the study.
data_path (str) – The path of the data folder.
-
kvalikirstu2.data_file_tempwriter.py¶
A module for writing temporary data files, that can be modified by the user.
kvalikirstu2.exceptions.py¶
A module containing exceptions.
-
exception
kvalikirstu2.exceptions.EncodingError(filepath, msg)[source]¶ Bases:
ExceptionError occurred related to text encoding
-
exception
kvalikirstu2.exceptions.HeaderEditException[source]¶ Bases:
ExceptionException occurred while editing headers.
-
exception
kvalikirstu2.exceptions.InvalidFormatException[source]¶ Bases:
ExceptionInvalid file format was entered by the user.
-
exception
kvalikirstu2.exceptions.InvalidHeaderException[source]¶ Bases:
ExceptionUser gave an invalid header.
-
exception
kvalikirstu2.exceptions.ParagraphParsingException(temp_path, row_min, row_max, msg='')[source]¶ Bases:
ExceptionError occurred during parsing paragraphs.
- Variables:
temp_path – Path of the temp file.
row_min – The first row where the error occurs.
row_max – The last row where the error occurs.
msg – The error message.
kvalikirstu2.folder_backup.py¶
A module for creating backups of folders for reverting changes to the study folder.
-
class
kvalikirstu2.folder_backup.FolderTimestamp(index, timestamp)[source]¶ Bases:
objectFolder timestamp for a backup.
- Variables:
index (int) – The index of the timestamp.
timestamp (float) – The unix timestamp.
-
kvalikirstu2.folder_backup.backup_folder(folder, max_folder_size, max_backups)[source]¶ Create a backup of the folder.
- Parameters:
folder (str) – The folder path.
max_folder_size – The maximum size of the folder.
max_backups – The maximum number of backups.
-
kvalikirstu2.folder_backup.clear_backups(folder)[source]¶ Clear old backups for the folder.
- Parameters:
folder – The path of the folder to clear backups for.
-
kvalikirstu2.folder_backup.folder_too_large(folder, max_folder_size)[source]¶ Is the folder too large to be backed up?
- Parameters:
folder – The path of the folder.
max_folder_size – The maximum size of the folder in bytes.
- Returns:
True/False based on whether or not the folder is too large to be backed up.
-
kvalikirstu2.folder_backup.get_timestamps(folder, max_backups)[source]¶ Get time stamps for a folder.
- Parameters:
folder (str) – Folder path to get backups for.
max_backups – Maximum number of backups.
kvalikirstu2.gui.py¶
kvalikirstu2.gui_model.py¶
The model part of the MVC architecture.
-
class
kvalikirstu2.gui_model.GUIModel[source]¶ Bases:
objectA class that contains the program state for the GUI.
-
add_language_codes(mapping)[source]¶ Adds language codes to files.
- Parameters:
mapping – A dictionary from old file paths to language codes.
-
broadcast_initial_messages()[source]¶ Broadcasts initial messages about program state after the GUI has been initialized. Has to be called manually.
-
change_header_property(indexes, change_func, no_action_condition=None)[source]¶ Changes a property of the headers selected on the listctrl.
- Parameters:
indexes – A list of indexes.
change_func (callable) – A function that changes a header property.
no_action_condition (callable) – When called with a HeaderLine object,
- Returns:
True if the property should not be changed.
-
get_daf_data()[source]¶ Returns a list of dafData instances, where content is a string that corresponds to the text content of the file. The content is an empty string if the file cannot be read.
-
get_headerline(index)[source]¶ Returns the HeaderLine in given index.
- Parameters:
index (int) – The index of the header to get.
- Return type:
-
get_preview(path)[source]¶ Returns a string with the first <20 lines of a file.
- Parameters:
path – The path of the file to preview.
-
get_tempfile_content(path)[source]¶ Gets the content from a temporary file for editing purposes.
- Parameters:
path – The path of the tempfile.
-
move_down(index)[source]¶ Moves header in the index downwards by one.
- Parameters:
index (int) – The index of the header to move.
-
move_up(index)[source]¶ Moves header in the index upwards by one.
- Parameters:
index (int) – The index of the header to move.
-
replace_text(old_text, new_text)[source]¶ Replace text in files.
- Parameters:
old_text – Text to replace.
new_text – Text to replace the old text with.
-
restore_backup(index)[source]¶ Restore backup in index.
- Parameters:
index – The index of the backup to restore to.
-
save_tempfile_content(path, content)[source]¶ Saves tempfile with content.
- Parameters:
path – The path of the tempfile.
content – The content to save into the tempfile.
-
select_index_language(lang)[source]¶ Select language for the index.
- Parameters:
lang (str) – The language to set the index language to.
-
set_row_name(index, value)[source]¶ Sets the name for a header.
- Parameters:
index – The index of the row.
value (str) – New name of the header.
-
set_row_to_headerline(header_line)[source]¶ Replace header.
- Parameters:
header_line (HeaderLine) – The new header.
-
set_study_path(path)[source]¶ Sets study path to given path.
- Parameters:
path – The directory path for the study.
-
set_type_shown(header_type, should_show)[source]¶ Sets whether or not header type should be shown in the list.
- Parameters:
header_type (HeaderType) – The header type.
should_show (bool) – Should the header type be shown in the GUI?
-
-
class
kvalikirstu2.gui_model.HeaderLine(header, header_info)[source]¶ Bases:
objectStores information about each header row in GUIModel
-
class
kvalikirstu2.gui_model.HeaderStatus[source]¶ Bases:
enum.EnumHeader status enum.
SHOW = A header to include in the index file. HIDE = A header not to be included in the index file. NOT_HEADER = Indicates a data paragraph line. DAF_HEADER = The data file header.
-
DAF_HEADER= 4¶
-
HIDE= 2¶
-
NOT_HEADER= 3¶
-
SHOW= 1¶
-
-
class
kvalikirstu2.gui_model.HeaderType[source]¶ Bases:
enum.EnumEnum class representing in which type a header belongs in.
-
BUILTIN= 2¶
-
NORMAL= 1¶
-
NOT_HEADER= 3¶
-
-
class
kvalikirstu2.gui_model.Messages[source]¶ Bases:
objectContains the identifiers for the messages sent by the GUI model.
-
ALL_HEADERS_CHANGED= 'all_headers_changed'¶
-
HEADER_CHANGED= 'header_changed'¶
-
HEADER_TYPE_SHOW= 'header_type_shown'¶
-
INDEX_EXISTS= 'index_exists'¶
-
LANGUAGES= 'languages'¶
-
STUDY_EXISTS= 'study_exists'¶
-
TASK_FINISHED= 'task_finished'¶
-
TASK_PROGRESS= 'task_progress'¶
-
TEMP_EXISTS= 'temp_exists'¶
-
UNDO_REDO_CHANGED= 'undo_redo_changed'¶
-
UNSAVED_CHANGES= 'unsaved_changes'¶
-
kvalikirstu2.gui_utils.py¶
A module for GUI util functions.
-
class
kvalikirstu2.gui_utils.Hotkey(keycode, modifiers, callback)[source]¶ Bases:
objectA class to store information about a certain hotkey for a window.
- Variables:
keycode – The keycode of the key.
modifiers – The bit mask to determine if ctrl/alt/shift should be held down for this key.
callback – The function callback when the key is pressed.
-
class
kvalikirstu2.gui_utils.HotkeyMixin[source]¶ Bases:
objectA mixin class to make adding hotkeys to windows easier.
- Variables:
hotkeys – A list of different hotkeys.
-
kvalikirstu2.gui_utils.add_border_and_fit(panel, sizer, frame=None, max_size=None)[source]¶ Adds a border and fit the frame.
- Parameters:
frame – Frame.
sizer – The sizer of the frame.
panel – The panel of the frame.
max_size – A tuple containing the maximum size of the frame.
-
kvalikirstu2.gui_utils.add_separator_to_ribbon_page(parent_page, padding=1, li_style=wx.LI_VERTICAL)[source]¶ Adds a separator line to wx.ribbon.RibbonPage parent_page.
-
kvalikirstu2.gui_utils.create_bitmap(img_name)[source]¶ Creates a bitmap from a .png image in the icons folder.
- Parameters:
img_name – The name of the .png file without extension.
Adds a new wx.ribbon.RibbonPanel with a wx.ribbon.RibbonButtonBar to a wx.ribbon.RibbonPage.
kvalikirstu2.header_panel.py¶
A module for a panel in the main gui window that contains header related controls.
-
class
kvalikirstu2.header_panel.EditableListCtrl(parent, style, editable_cols, *args, **kwargs)[source]¶ Bases:
wx.ListCtrl,wx.lib.mixins.listctrl.TextEditMixin,wx.lib.mixins.listctrl.ListCtrlAutoWidthMixinA list control class that extends wx.ListCtrl, wx.lib.mixins.listctrl.TextEditMixin and wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin. The list control can be set to resize automatically and its text fields can be set editable.
-
OnChar(event)[source]¶ Catch the TAB, Shift-TAB, cursor DOWN/UP events. Overrides listctrl.EditableListCtrl.OnChar to fix bug with opening the editor at the right col and taking editable rows and cols into account.
-
OnItemSelected(evt)[source]¶ Overwrites OnItemSelected method of listctrl.TextEditMixin so that first item in the list can be selected.
-
OnLeftDown(evt=None)[source]¶ Overwrites OnLeftDown method of listctrl.TextEditMixin so that first item in the list can be selected. Disables editing any other column but the ones specified at init.
-
set_header_item_colours(index, header)[source]¶ Sets text and background colours for header items in the listctrl.
- Parameters:
index (int) – The index of the listctrl row to edit.
header (HeaderLine) – The HeaderLine object that determines the listctrl row colours.
-
-
class
kvalikirstu2.header_panel.HeaderPanel(parent, main_win, model, style=wx.TAB_TRAVERSAL)[source]¶ Bases:
wx.PanelA panel with header editing controls.
-
ID_MOVE_HEADERS¶
-
ID_TOGGLE_SHOW_BUILTIN¶
-
ID_TOGGLE_SHOW_NONHEADER¶
Removes and readds the move headers button with an icon and label according to if moving rows is activated.
Clears the button bar with the show builtin button and adds a new button with an icon and label according to the value of show_builtin_headers.
Clears the button bar with the show non headers button and adds a new button with an icon and label according to the value of show_non_headers.
-
align_selected(alignment)[source]¶ Sets the alignment of selected headers.
- Parameters:
alignment (str) – The new alignment.
-
-
exception
kvalikirstu2.header_panel.StatusError[source]¶ Bases:
ExceptionAn exception class to report issues with setting the status for a header.
-
class
kvalikirstu2.header_panel.ValueEditDlg(parent, value_map, title)[source]¶ Bases:
wx.DialogA Dialog window for editing values associated with a header in a subject.
-
on_close(ret_val=wx.ID_CANCEL)[source]¶ Asks to save unsaved changes when the window is about to close.
-
refresh_listctrl(row_index, new_value)[source]¶ Remaps a value on the given row with a new value.
- Parameters:
row_index (int) – The index of the row of the item to edit.
new_value (str) – The new value for the item.
-
remap_edited_values()[source]¶ Maps edited values to the old values and changes the item text of the corresponding listctrl rows.
Opens the Popup menu when right click detected on a listctrl item.
-
kvalikirstu2.header_scanner.py¶
A module for scanning headers from data files.
kvalikirstu2.kvali_interface.py¶
Contains the interface through which the application communicates with the rest of the program
-
class
kvalikirstu2.kvali_interface.DaFData(filepath, langcode, content)[source]¶ Bases:
objectA class that contains information about a data file.
-
exception
kvalikirstu2.kvali_interface.InvalidProgramStateException[source]¶ Bases:
ExceptionThe program was in an invalid state for the function being called.
-
kvalikirstu2.kvali_interface.add_language_codes(mapping)[source]¶ Adds language codes to files.
- Parameters:
mapping – A dictionary from old file paths to language codes.
-
kvalikirstu2.kvali_interface.add_text_to_dafs(text)[source]¶ Add text to in front of every data file.
- Parameters:
text – The text added.
-
kvalikirstu2.kvali_interface.check_archive_interface()[source]¶ Checks if the archive interface is the dummy plugin.
-
kvalikirstu2.kvali_interface.convertable_files_exist()[source]¶ Returns True if there are convertable files in the selected study.
-
kvalikirstu2.kvali_interface.convertable_formats()[source]¶ Returns a list of convertable file formats.
-
kvalikirstu2.kvali_interface.data_files_and_mef_exist()[source]¶ Returns True if data path has been set, meF is found and data directory contains files.
-
kvalikirstu2.kvali_interface.delete_tempfiles()[source]¶ Deletes the temporary files used for generating the index.
-
kvalikirstu2.kvali_interface.generate_citreq()[source]¶ Generates a citation requirement for a folder
-
kvalikirstu2.kvali_interface.generate_tempfiles()[source]¶ Generates the temporary files for the study
-
kvalikirstu2.kvali_interface.get_all_files_from_data_folder()[source]¶ Returns all files from the data folder except the meF and the data files.
- Returns:
A list of relative paths from the folder.
-
kvalikirstu2.kvali_interface.get_backups()[source]¶ Get backups with timestamps for the study folder.
-
kvalikirstu2.kvali_interface.get_commands()[source]¶ Gets commands that can be executed from the gui.
- Returns:
A list of commands.
-
kvalikirstu2.kvali_interface.get_daf_container_path()[source]¶ Forms and returns the path of the daf container file.
-
kvalikirstu2.kvali_interface.get_daf_data()[source]¶ Returns a list of dafData instances, where content is a string that corresponds to the text content of the file. The content is an empty string if the file cannot be read.
-
kvalikirstu2.kvali_interface.get_data_filepaths()[source]¶ Returns a list of paths of all supported and convertable files in the current study.
-
kvalikirstu2.kvali_interface.get_file_count()[source]¶ Returns the number of supported and convertable files in the current study.
-
kvalikirstu2.kvali_interface.get_headers_json_path()[source]¶ Gets the .json path for the current study
-
kvalikirstu2.kvali_interface.get_index_path()[source]¶ Gets the path where the index will be created.
-
kvalikirstu2.kvali_interface.get_rows_from_file(path, line_ct)[source]¶ Reads the first <line_ct lines from the file in path.
- Parameters:
path – The path of the file.
line_ct – The maximum number of lines to read.
-
kvalikirstu2.kvali_interface.get_study_json_path()[source]¶ Gets the .json path for the current study
-
kvalikirstu2.kvali_interface.get_temp_glob_pattern()[source]¶ Gets the glob pattern for temp files.
- Return type:
str
-
kvalikirstu2.kvali_interface.get_textfile_content(path)[source]¶ Gets the content from a temporary file for editing purposes.
- Parameters:
path (str) – The path of the temp file.
-
kvalikirstu2.kvali_interface.paragraph_files_exist()[source]¶ Do the temporary paragraph files exists for the data files?
-
kvalikirstu2.kvali_interface.register_interface_for_argument_parser()[source]¶ Registers the data archive interface for the argument parser.
-
kvalikirstu2.kvali_interface.replace_text(original_text, new_text)[source]¶ Replace text with new text in data folder.
- Parameters:
original_text – Original text.
new_text – New text to replace the original.
-
kvalikirstu2.kvali_interface.restore_backup(index)[source]¶ Restores a folder to a backup with the given index.
- Parameters:
index – The index of the backup.
-
kvalikirstu2.kvali_interface.save_header_info(header_info)[source]¶ Saves the modified header info.
- Parameters:
header_info (HeaderInfo) – New header info to be set.
-
kvalikirstu2.kvali_interface.save_tempfile_content(path, content)[source]¶ Rewrites the old temp file with new content.
- Parameters:
path (str) – The path of the temp file.
content (str) – The contents of the file.
-
kvalikirstu2.kvali_interface.set_headers(headers, headers_removed, header_indexes=None, header_alignment=None)[source]¶ Sets the header info from the header editing menu.
- Parameters:
headers – A map of old headers to new headers.
headers_removed – A list of headers that should be removed.
header_indexes – A map of header to index.
header_alignment – A map of header to alignment.
-
kvalikirstu2.kvali_interface.set_selected_headers(selected_headers)[source]¶ Set selected headers.
- Parameters:
selected_headers (dict) – A dictionary of str:bool items.
-
kvalikirstu2.kvali_interface.set_study_and_header_info()[source]¶ Sets the current study and loads header info.
-
kvalikirstu2.kvali_interface.set_study_path(path: str)[source]¶ Sets the path for the study
- Parameters:
path – The study path.
-
kvalikirstu2.kvali_interface.setup_external_file_study(headers)[source]¶ Transforms the study into one that contains external files that are linked to from the index. Any text in readable files is marked as data so it won’t be read.
-
kvalikirstu2.kvali_interface.study_exists()[source]¶ Does the study exist, ie. is a valid folder specified?
kvalikirstu2.lang_select_window.py¶
A GUI module for displaying a window for adding language tags to files.
kvalikirstu2.localization.py¶
A module for localization.
-
kvalikirstu2.localization.get_languages(user_locale='en_US')[source]¶ Gets a list of pairs of language codes and their display names in the users locale.
kvalikirstu2.main.py¶
A module for using the application from the command line.
-
kvalikirstu2.main.add_text(args)[source]¶ Adds string to the start of every data file.
- Parameters:
args – The arguments for the application.
-
kvalikirstu2.main.convert(args)[source]¶ Convert data files to default encoding.
- Parameters:
args – The arguments for the application.
-
kvalikirstu2.main.generate_citreq(args)[source]¶ Generates a citation requirement for the given folder.
- Parameters:
args – The arguments for the application.
-
kvalikirstu2.main.generate_index(args)[source]¶ Loads a study, and generates the index.
- Parameters:
args – The arguments for the application.
-
kvalikirstu2.main.parse_study(args)[source]¶ Parses the study files, and prints some information about the study.
- Parameters:
args – The arguments for the application.
-
kvalikirstu2.main.rename_files(args)[source]¶ Renames files in study folder.
- Parameters:
args – The arguments for the application.
kvalikirstu2.odt_reader.py¶
A module for reading .odt files line by line. Does not use Libreoffice, instead uses odfpy.
-
exception
kvalikirstu2.odt_reader.ODTException(inner_exception, *args)[source]¶ Bases:
ExceptionError occurred while reading odt file.
-
class
kvalikirstu2.odt_reader.OdtReader(path: str)[source]¶ Bases:
objectReads .odt files line by line
- Variables:
doc – The .odt document
node_index (int) – Current text node in document
nodes – All the text nodes from the document.
kvalikirstu2.paragraph_analyzer.py¶
A module for parsing paragrahs out of data files.
-
class
kvalikirstu2.paragraph_analyzer.Paragraph(temp_path, par_type=<ParagraphType.UNKNOWN: 5>)[source]¶ Bases:
objectContains a paragraph of text, lines of text not separated by empty lines
- Variables:
lines – A list of lines contained in the paragraph.
par_type (ParagraphType) – The type of the paragraph.
manual_type (bool) – True if the type of the paragraph has been manually specified using BEGINDATA and ENDDATA tokens.
row_min – First row.
row_max – Last row.
temp_path – Temporary filepath.
args – The args of the application.
-
check_valid()[source]¶ Checks if the paragraph is valid. A paragraph is invalid in the case that it is a header paragraph, but contains non-header lines.
-
get_split_point(headers_selected)[source]¶ The split point of a header paragraph.
- Parameters:
headers_selected – A dictionary of which headers should be selected.
- Returns:
The index that the paragraph should be split on.
-
resolve_row(running_row)[source]¶ Resolves the span of rows that the paragraph appears in the file, given the starting row.
- Parameters:
running_row – The current running index of the row.
- Returns:
The new running row.
-
resolve_type(selected_headers: dict = None)[source]¶ Resolves if the paragraph is a header or not. Sets the is_header attribute to its correct value.
- Parameters:
selected_headers – The selected headers dictionary.
-
set_type(par_type)[source]¶ Sets the paragraph type manually.
- Parameters:
par_type (ParagraphType) – The type.
-
should_split(headers_selected)[source]¶ Should split the paragraph?
- Parameters:
headers_selected – A dictionary of which headers should be selected.
-
class
kvalikirstu2.paragraph_analyzer.ParagraphReader(path: str, overwrite_temp: bool = True, selected_headers: dict = None, use_temp: bool = True, study_path: str = None, end_markers=True, split_headers=True)[source]¶ Bases:
objectReads a file into paragraphs
- Variables:
reader – Responsible for reading the file line by line
path (str) – The file path
paragraphs (list(Paragraph)) – Paragraphs contained in the text
overwrite_temp (bool) – Overwrite temporary files.
selected_headers – The selected headers dictionary.
use_temp – Whether or not temp files should be used when reading.
study_path – The path of the study.
end_markers – Whether or not end markers should be inserted in the temp file.
split_headers – Should split the paragraph.
-
get_reader()[source]¶ Gets the reader for a given file extension
- Parameters:
path (str) – The file path of the file to be read.
- Returns:
The reader to be used in the parsing process.
-
read_paragraphs()[source]¶ Reads paragraphs from a text file
- Return type:
list(Paragraph)
- Returns:
List of paragraphs in the text.
-
class
kvalikirstu2.paragraph_analyzer.ParagraphType[source]¶ Bases:
enum.EnumParagraph type enum.
DATA = A normal data paragraph containing text relevant to a certain subject. HEADER = A header paragraph containing headers for a certain subject. BEGINDATA = Indicates the start of a data block. ENDDATA = Indicates the end of a data block. UNKNOWN = Type hasn’t been determined.
-
BEGINDATA= 3¶
-
DATA= 1¶
-
ENDDATA= 4¶
-
HEADER= 2¶
-
UNKNOWN= 5¶
-
-
class
kvalikirstu2.paragraph_analyzer.Subject(data_file: str, temp_path)[source]¶ Bases:
objectA subject and its relevant data in the study.
- Variables:
headers (dict) – A dictionary of (key, value) pairs, often containing metadata about the subject.
paragraphs (list(Paragraph)) – Contains all the text paragraphs relevant to this subject.
int) header_indexes (dict(str,) – A dictionary mapping header names to their index.
data_file (str) – The path to the relevant data file for the subject.
temp_path – The filepath of the temp file.
-
add_data(paragraph)[source]¶ Add a text paragraph for the subject.
- Parameters:
paragraph (Paragraph) – A paragraph containing some text.
-
check_validity()[source]¶ Checks that the subject is valid. Does not return anything, just raises an exception if the subject is invalid.
-
get_header_value(header)[source]¶ Gets the value of a header field.
- Parameters:
header (str) – The header which value is to be retrieved.
-
get_language_code(language_codes)[source]¶ Gets the language code for the given file.
- Parameters:
language_codes – Set of possible language codes.
-
has_headers()[source]¶ Does subject have headers read?
- Return type:
bool
- Returns:
True if subject has headers, False otherwise.
-
remap(header_info)[source]¶ Remaps the headers to their corresponding names.
Iterates through all the subjects headers and maps them to their new values. In some cases there are multiple headers in a study that have the same meaning, but are just different ways of phrasing it. In cases like this they should be all be remapped into the same name. In some cases you may also want to discard some attributes from the index.
If a header is in the dictionary, it means that it should be remapped to a possibly different name.
- Parameters:
header_info (HeaderInfo) – Contains information about the different headers in the study.
-
remap_values(value_mapping: dict)[source]¶ Remaps values to new values.
- Parameters:
value_mapping (dict) – A value mapping dictionary from (key, value) to value.
kvalikirstu2.progress_dialog.py¶
kvalikirstu2.reader.py¶
A module for reading text and ODT files.
-
class
kvalikirstu2.reader.TxtReader(path: str, encoding)[source]¶ Bases:
objectReads .txt files line by line.
- Variables:
fstream – A filestream in read-mode, that reads the file line by line.
kvalikirstu2.study.py¶
Contains the Study and HeaderInfo classes for storing data about a qualitative study.
-
class
kvalikirstu2.study.Align[source]¶ Bases:
objectContains the untranslated alignment strings.
-
CENTER= 'center'¶
-
LEFT= 'left'¶
-
RIGHT= 'right'¶
-
-
class
kvalikirstu2.study.HeaderInfo[source]¶ Bases:
objectContains the header information about the study.
- Variables:
header_mapping – A mapping for headers from name to name
header_indexes – A mapping from header to index
value_mapping – Maps (header, value) pairs to new values
header_enabled – A mapping from header to bool
header_alignment – A mapping from header to alignment
selected_headers – A mapping from header to booleans
deleted_headers – A mapping from header to booleans
-
add_header(header)[source]¶ Adds a new header for the study.
- Parameters:
header – The header to be added.
-
class
kvalikirstu2.study.Study(study_id: str, study_path: str, study_title: str, data_folder=None)[source]¶ Bases:
objectA study containing qualitative data.
- Variables:
study_id (str) – The ID of the study
subjects – Subjects and their data
-
add_subject(subject: kvalikirstu2.paragraph_analyzer.Subject)[source]¶ Add a new subject to the study
- Parameters:
subject (Subject) – The subject to be added.
-
get_full_path()[source]¶ The location where the data for the study is stored in.
- Returns:
The path of the full object.
- Return type:
str
-
get_language_code(language_codes)[source]¶ Gets the language code for the whole study.
- Parameters:
language_codes – The set of possible language codes.
- Returns:
A language code as a three letter string.
-
get_subject_language_code(index, language_codes)[source]¶ Gets the language code for the given subject.
- Parameters:
index – The index of the subject.
language_codes – List of valid language codes.
kvalikirstu2.study_reader.py¶
A module for generating a study out of data files.
-
exception
kvalikirstu2.study_reader.NoSubjectsException[source]¶ Bases:
ExceptionStudy contained no subjects.
-
class
kvalikirstu2.study_reader.StudyReader(study_id: str, study_title: str, overwrite_temp: bool = True, selected_headers: dict = None, study_path: str = None, data_folder_name: str = None, data_file: str = None)[source]¶ Bases:
objectA class for reading studies from a folder.
-
get_files()[source]¶ Get all the files in the folder and subfolders. All the files in the folder that have a compatible file format are matched.
- Return type:
list
- Returns:
A list of files
-
kvalikirstu2.template_generator.py¶
A module for generating html files using Jinja2.
Attributes¶
ENV(Environment): A jinja2 enviroment for generating templates.
-
class
kvalikirstu2.template_generator.HTMLFileMapping[source]¶ Bases:
objectA class that handles the file mapping for HTML files.
-
add_path(key, path)[source]¶ Add a path with a key.
- Parameters:
key – The key of the file.
path – The path of the file.
-
get_html_link(key)[source]¶ Gets link to given key relative to output path.
- Parameters:
key – The key of the file.
-
-
kvalikirstu2.template_generator.generate_index(output_path: str, template_study: kvalikirstu2.study.Study, header_info, metadata)[source]¶ Generates an index file for the study.
- Parameters:
output_path (str) – The output path for the generated html index file.
template_study (Study) – The study from which the template is generated from.
header_info – Contains information about the study’s headers.
metadata – The metadata of the study.
-
kvalikirstu2.template_generator.get_html_path(output_path: str)[source]¶ Gets the folder for all the “under the hood” files for the index document.
- Parameters:
output_path (str) – The path where the index file goes to.
-
kvalikirstu2.template_generator.get_index_path(output_path)[source]¶ - Parameters:
output_path – The path of the output folder.
- Returns:
The path of the index file.
-
kvalikirstu2.template_generator.relpath_with_fwd_slash(path: str, start=None)[source]¶ Produces a relative path with forward slashes
- Parameters:
path (str) – The path for which the relative path should be determined.
start (str) – The path to which the path is relative to. If no argument is given, the current working directory is used.
kvalikirstu2.text_add_window.py¶
A module for the text adding window.
kvalikirstu2.text_replace_window.py¶
kvalikirstu2.tmp_edit_window.py¶
A module for editing files with a text editor.
-
class
kvalikirstu2.tmp_edit_window.ParagraphErrorWindow(model, message, parsing_exception: kvalikirstu2.exceptions.ParagraphParsingException)[source]¶ Bases:
wx.DialogWindow for displaying paragraph errors.
-
class
kvalikirstu2.tmp_edit_window.TmpEditWindow(model, parsing_exception, *args, **kwargs)[source]¶ Bases:
wx.Dialog,kvalikirstu2.gui_utils.HotkeyMixinThe header editing window.
kvalikirstu2.utils.py¶
Module for small utility functions used in various places.
This module contains many small functions that are used in various places of Kvalikirstu.
Attributes¶
HEADER_LINE_REGEX(str): Contains the regex used for detecting header lines from files.
SUPPORTED_FORMATS(list(str)): Contains a list of strings that are the file formats supported by Kvalikirstu.
-
exception
kvalikirstu2.utils.InvalidPathException[source]¶ Bases:
ExceptionUser provided an invalid path.
-
kvalikirstu2.utils.add_language_code_to_path(path, code, codes)[source]¶ Gets the path with the language code.
- Parameters:
path (str) – The old filepath.
code (str) – The language code.
codes (list) – Valid language codes.
-
kvalikirstu2.utils.check_if_any_file_in_use(path: str, file_extensions)[source]¶ Checks if any file is in use in the folder.
- Parameters:
path – Folder path.
file_extensions – List of file extensions.
-
kvalikirstu2.utils.create_folder_if_not_exists(path: str)[source]¶ Creates a folder if one does not already exist.
- Parameters:
path (str) – The path of the folder.
-
kvalikirstu2.utils.delete_file_if_exists(path: str)[source]¶ Delete file if one exists.
- Parameters:
path (str) – The filepath to be deleted.
-
kvalikirstu2.utils.delete_folder_if_exists(path: str)[source]¶ Deletes a folder and its contents if it exists.
- Parameters:
path – The path of the folder.
-
kvalikirstu2.utils.folder_modified_timestamp(folder)[source]¶ Gets the timestamp for when any file in the folder was last modified.
- Parameters:
folder (str) – The folder to get the timestamp for.
-
kvalikirstu2.utils.get_convertable_files(path)[source]¶ Get all the files in the folder and subfolders. All the files in the folder that have a convertable file format are matched.
- Parameters:
path (str) – The path to search for files.
- Return type:
list
- Returns:
A list of files
-
kvalikirstu2.utils.get_files_with_extensions(path, formats)[source]¶ Get files with the given extensions from the path.
- Parameters:
path – The folder path.
formats – List of file extensions.
-
kvalikirstu2.utils.get_filesize(path)[source]¶ Gets the size of a file in kilobytes. Rounded to one decimal point.
- Parameters:
path – The filepath of the entry.
-
kvalikirstu2.utils.get_folder(path)[source]¶ Gets the folder for a file, for a folder returns itself.
- Parameters:
path (str) – The path to the folder/file.
- Return type:
str
-
kvalikirstu2.utils.get_folder_size(folder)[source]¶ Gets the total size of all files in the folder.
- Parameters:
folder – The path of the folder to be examined.
-
kvalikirstu2.utils.get_formatted_header_line(header, value)[source]¶ Formats the header line according to the format specified in configurations.
- Parameters:
header (str) – The header part of the line
value (str) – The value part of the line
- Return type:
str
- Returns:
The formatted header line.
-
kvalikirstu2.utils.get_language_code_from_path(filepath, codes=None)[source]¶ Gets the language code from path.
- Parameters:
filepath (str) – The path of the file.
codes (list) – Valid language codes.
-
kvalikirstu2.utils.get_list_without_duplicates(items: list)[source]¶ Removes duplicates from list.
- Parameters:
items – List to be pruned of duplicates.
- Return type:
list
- Returns:
List without duplicates.
-
kvalikirstu2.utils.get_pair_out_of_string(string_pair)[source]¶ Takes a string containing a pair and parses it and returns it.
- Parameters:
string_pair – A pair inside a string. Expected format is “(‘key’, ‘value’)”
-
kvalikirstu2.utils.get_path_extension(path: str)[source]¶ Returns the filepath with the file extension
- Parameters:
path (str) – The filepath.
- Return type:
str
-
kvalikirstu2.utils.get_path_without_extension(path: str)[source]¶ Returns the filepath without the file extension
- Parameters:
path (str) – The filepath.
- Return type:
str
-
kvalikirstu2.utils.get_supported_files(path)[source]¶ Get all the files in the folder and subfolders.
All the files in the folder that have a compatible file format are matched.
- Parameters:
path (str) – The path to search for files.
- Return type:
list
- Returns:
A list of files
-
kvalikirstu2.utils.get_temp_path(folder_path: str, extension: str)[source]¶ Gets a path for a new temporary file.
- Parameters:
folder_path (str) – The path of the folder where the temp file is created in.
extension (str) – The file extension of the file.
- Return type:
str
-
kvalikirstu2.utils.is_convertable_format(filename: str, formats)[source]¶ Is the text format convertable by Kvalikirstu?
- Parameters:
filename (str) – The filename to be checked
formats – The convertable formats.
- Return type:
bool
- Returns:
True if text format is valid, False otherwise
-
kvalikirstu2.utils.is_header_line(line: str, selected_headers: dict = None)[source]¶ Is the current line a header?
- Parameters:
line (str) – The line to be parsed
selected_headers – A dictionary from header names to booleans that determines if they are selected.
- Return type:
bool
- Returns:
True if line is a header, False otherwise
-
kvalikirstu2.utils.is_image_file(path: str)[source]¶ Tests is the file in the path is an image file
- Parameters:
path (str) – The path to the file.
- Return type:
bool
-
kvalikirstu2.utils.is_temp_file(path: str)[source]¶ Checks if the filename looks like a temporary file for an .odt document.
- Parameters:
path (str) – The filename of the file. Can be the full path or just the name of the file
- Return type:
bool
- Returns:
True if the file is a temp file, False otherwise
-
kvalikirstu2.utils.is_valid_header(header)[source]¶ Is the header a valid header?
- Parameters:
header – The header to be tested for validity.
-
kvalikirstu2.utils.is_valid_text_format(filename: str)[source]¶ Is the text format supported by Kvalikirstu?
- Parameters:
filename (str) – The filename to be checked
- Return type:
bool
- Returns:
True if text format is valid, False otherwise
-
kvalikirstu2.utils.is_windows()[source]¶ Returns True if the user’s OS is a Windows system.
- Return type:
bool
-
kvalikirstu2.utils.json_deserialize(path: str)[source]¶ Deserializes(loads) any object from filename
- Parameters:
path (str) – Where the saved file is located
- Returns:
The deserialized object
-
kvalikirstu2.utils.json_serialize(obj, path: str)[source]¶ Serializes(saves) any object to a file
- Parameters:
obj – Any python object you want to serialize
path (str) – Where the file should be saved
-
kvalikirstu2.utils.natsorted_glob(pathname, extensions=None, files_only=True)[source]¶ Return files from pathname in a naturally sorted order.
- Parameters:
pathname – The search path to use for glob.glob.
extensions – The set of allowed extensions. None for any extension.
files_only – Whether or not only files should be returned.
- Returns:
A list of filenames in natural sort order.
kvalikirstu2.warning_handler.py¶
A module for the warning handler in the GUI.
-
class
kvalikirstu2.warning_handler.WarningHandler(stream=None)[source]¶ Bases:
logging.StreamHandlerA handler class which gives pop-ups on logger warnings, does not give pop-ups on errors(errors should be handled separately).
-
emit(record)[source]¶ Emit a record.
If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.
-
kvalikirstu2.writer.py¶
A module for writing odt and txt files.
-
kvalikirstu2.writer.add_text_to_file(path: str, output_path: str, text: str)[source]¶ Adds text to the start of the file, and saves it to a new path. Note: You can also ovewrite the original by setting output_path same as path.
- Parameters:
path (str) – The original filepath.
output_path (str) – The output filepath.
text – The text to be added.
-
kvalikirstu2.writer.add_text_to_folder(path: str, text: str, check_for_duplicate=False)[source]¶ Adds text to all .odt and .txt files in the folder
- Parameters:
path (str) – The path of the folder.
text (str) – The text to be added.
check_for_duplicate – Whether or not to check for duplicate text at the start of the file.
-
kvalikirstu2.writer.rename_headers_in_folder(path: str, header_info, encoding=None)[source]¶ Rename headers in folder path.
- Parameters:
path – The path of the folder.
header_info – Header info for the study.
encoding – Encoding to be used in the data files.
-
kvalikirstu2.writer.replace_in_folder(path, original_text, new_text, encoding=None)[source]¶ Replace text in a folder.
- Parameters:
path – The path of the folder.
original_text – The original text.
new_text – The new text.
encoding – The encoding used.