-
-
Notifications
You must be signed in to change notification settings - Fork 126
shared.py
infinition edited this page Jul 5, 2024
·
1 revision
This document describes the detailed step-by-step process of how the SharedData
class works, including the specific methods, classes, and functions used at each step.
- The
SharedData
class imports several modules, including standard libraries (os
,sys
,json
,importlib
,random
,time
,csv
,logging
) and custom modules (Image
,ImageFont
,epd2in13_V2
,Logger
).
- An instance of the
SharedData
class is created to initialize shared resources and data.
- Purpose: Initializes shared data and resources.
-
Key Steps:
-
Initialize Paths:
- Calls the
initialize_paths
method to set up directory and file paths.
- Calls the
-
Initialize Variables:
- Sets initial values for various attributes such as
last_comment_time
,default_config
, andconfig
.
- Sets initial values for various attributes such as
-
Setup Environment:
- Calls the
setup_environment
method to configure necessary directories and files.
- Calls the
-
Create Live Status File:
- Calls the
create_livestatusfile
method to create a file for storing the current status of scans.
- Calls the
-
Load Fonts and Images:
- Calls the
load_fonts
andload_images
methods to load necessary fonts and images.
- Calls the
-
Initialize Paths:
- Purpose: Sets up directory and file paths used by the application.
-
Key Steps:
-
Initialize Directories:
- Sets up paths for various directories such as
configdir
,datadir
,actions_dir
,webdir
,resourcesdir
, and subdirectories.
- Sets up paths for various directories such as
-
Initialize Files:
- Sets up paths for various files such as
shared_config_json
,actions_file
,netkbfile
,livestatusfile
, and others.
- Sets up paths for various files such as
-
Initialize Directories:
- Purpose: Provides the default configuration settings for the application.
-
Key Steps:
-
Return Default Config:
- Returns a dictionary containing default configuration values for various settings.
-
Return Default Config:
- Purpose: Sets up the environment by creating necessary directories and files.
-
Key Steps:
-
Clear Screen:
- Clears the terminal screen.
-
Load Configuration:
- Calls the
load_config
method to load configuration settings.
- Calls the
-
Generate Actions JSON:
- Calls the
generate_actions_json
method to create the actions configuration file.
- Calls the
-
Initialize CSV:
- Calls the
initialize_csv
method to set up the network knowledge base CSV file.
- Calls the
-
Initialize EPD Display:
- Calls the
initialize_epd_display
method to set up the e-paper display.
- Calls the
-
Clear Screen:
- Purpose: Initializes the e-paper display.
-
Key Steps:
-
Set Up Display:
- Sets up the e-paper display and its dimensions.
-
Set Up Display:
- Purpose: Sets initial values for various attributes used by the application.
-
Key Steps:
-
Initialize Flags and Counters:
- Initializes various flags and counters such as
should_exit
,bluetooth_active
,wifi_connected
, and others.
- Initializes various flags and counters such as
-
Initialize Flags and Counters:
- Purpose: Creates a file to store the current status of network scans.
-
Key Steps:
-
Check File Existence:
- Checks if the file exists and creates it if not, writing initial headers and values.
-
Check File Existence:
- Purpose: Creates the actions configuration file.
-
Key Steps:
-
Iterate Over Actions:
- Iterates over action modules to extract necessary attributes and generate the JSON configuration file.
-
Iterate Over Actions:
- Purpose: Sets up the network knowledge base CSV file with headers.
-
Key Steps:
-
Check File Existence:
- Checks if the CSV file exists and creates it if not, writing initial headers and values.
-
Check File Existence:
- Purpose: Loads the configuration from the shared configuration JSON file.
-
Key Steps:
-
Load Configuration File:
- Loads the configuration file and updates attributes with the loaded values.
-
Load Configuration File:
- Purpose: Saves the current configuration to the shared configuration JSON file.
-
Key Steps:
-
Create Configuration Directory:
- Creates the configuration directory if it doesn't exist.
-
Write Configuration File:
- Writes the current configuration to the JSON file.
-
Create Configuration Directory:
- Purpose: Loads the fonts required by the application.
-
Key Steps:
-
Load Individual Fonts:
- Calls the
load_font
method for each font file needed.
- Calls the
-
Load Individual Fonts:
- Purpose: Loads a specific font.
-
Key Steps:
-
Load Font File:
- Loads a font file from the specified path and size.
-
Load Font File:
- Purpose: Loads the images required for the e-paper display.
-
Key Steps:
-
Load Static Images:
- Loads individual static images from the specified directory.
-
Load Image Series:
- Dynamically loads image series for different statuses from subdirectories.
-
Load Static Images:
- Purpose: Updates the status image displayed on the e-paper display.
-
Key Steps:
-
Get Status Image:
- Uses the current status to fetch the corresponding image for display.
-
Get Status Image:
- Purpose: Loads an image from the specified path.
-
Key Steps:
-
Check Image Path:
- Checks if the image file exists and loads it if it does.
-
Check Image Path:
- Purpose: Updates the image randomizer and the image generation variable.
-
Key Steps:
-
Select Random Image:
- Selects a random image from the available images for the current status.
-
Select Random Image:
- Purpose: Wraps text to fit within a specified width when rendered.
-
Key Steps:
-
Split Text into Lines:
- Splits the input text into lines that fit within the specified width.
-
Split Text into Lines:
- Purpose: Reads data from the network knowledge base CSV file.
-
Key Steps:
-
Read CSV File:
- Reads the CSV file and returns the data as a list of dictionaries.
-
Read CSV File:
- Purpose: Writes data to the network knowledge base CSV file.
-
Key Steps:
-
Merge New Data with Existing Data:
- Merges new data with existing data and writes the updated data back to the CSV file.
-
Merge New Data with Existing Data:
- Purpose: Updates the application statistics based on predefined formulas.
-
Key Steps:
-
Calculate Statistics:
- Calculates various statistics such as coin count and level number based on network knowledge base data.
-
Calculate Statistics:
- Purpose: Prints a debug message if debug mode is enabled.
-
Key Steps:
-
Check Debug Mode:
- Checks if debug mode is enabled and prints the message if it is.
-
Check Debug Mode:
The SharedData
class is responsible for managing shared resources and data for different modules in the Bjorn project. It handles the initialization and configuration of paths, logging, fonts, and images, sets up the environment, creates necessary directories and files, and manages the loading and saving of configuration settings. The class also provides utility functions for reading and writing data to CSV files, updating statistics, and wrapping text for display purposes.