civilpy.general package

Subpackages

Submodules

civilpy.general.database_tools module

CivilPy Copyright (C) 2019-2026 - Dane Parks

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

civilpy.general.database_tools.ssh_into_postgres(creds)[source]

Function to open an ssh tunnel directly to a postgres database to gather data from it

Parameters:

creds – dictionary of necessary parameters to connect to the database

Returns:

civilpy.general.jupyter module

CivilPy Copyright (C) 2019-2026 - Dane Parks

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

civilpy.general.jupyter.notebook_converter(notebook_path, format='webpdf')[source]

civilpy.general.photos module

CivilPy Copyright (C) 2019-2026 - Dane Parks

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

class civilpy.general.photos.CivImageMap(file_path, output='show')[source]

Bases: Image

__init__(file_path, output='show')[source]

Civil Engineering Image class to display one or multiple photos on a map, multiple input and output options available

Parameters:

file_path

build_image_list_from_path(path=None)[source]
get_exif()[source]
get_geo()[source]
civilpy.general.photos.add_timestamp(image, date)[source]

Adds a timestamp with date and time extracted from an image’s metadata (if available) to the bottom right of the image.

Parameters:

image (PIL.Image.Image) – An Image object.

Returns:

The modified image with the timestamp.

Return type:

PIL.Image.Image

civilpy.general.photos.convert_filenames_from_excel(excel_file=None, root_folder=None, project_name=None, keep_existing_fns=False)[source]

Function that copies a series of file paths from column ‘A’ of an Excel file (sheet 0, with no header) and changes the file names to the new filename values held in column ‘B’. The function uses Django’s slugify function to remove illegal or confusing characters like ‘/’, ‘’, ‘,’, or ‘#’

Parameters:
  • excel_file (str - Path to Excel file containing file paths and new file names)

  • root_folder (str - Path to the folder the Renamed_Photos folder is located)

  • project_name (str - Name of the project to be included within the photo names)

  • keep_existing_fns (bool - Option to either append the original file names to the new name or not)

Return type:

None - creates the files within the new renamed folder

civilpy.general.photos.create_folder_for_renamed_files(path=None)[source]

Creates a folder named “Renamed_Photos” to store the new photos in

Parameters:

path (str - A string representation of the root folder for photos where you want the "Renamed_Photos" folder to be) – created

Return type:

None - Creates a folder in the designated location

civilpy.general.photos.get_list_of_files_from_folder(path='C:\\Users\\dane\\Desktop\\test_photos')[source]

Builds a list of files given a root folder, can be given a folder with multiple sub-folders

Parameters:

path (str - A string representation of a file path, for windows paths, either has to be passed in as a raw string,) – or with escaped/converted ‘’ characters. Once inside the function, the string is converted using the pathlib Path() module, eliminating further issues with windows paths.

Returns:

return_list

Return type:

list - A full list of every file found by the function

civilpy.general.photos.get_photo_creation_date(img)[source]

Extracts the creation date of a photo from its EXIF metadata and returns it in MM/DD/YYYY format.

Parameters:

file_path – Path to the image file

Returns:

Creation date in MM/DD/YYYY format, or None if not available

civilpy.general.photos.get_photos_from_file_list(file_list=None)[source]

Takes a list of file paths and uses regex to only return files with photo related file types (svg, heif, bmp, tiff, webp, jpeg, png, jpg). Not case-sensitive.

Parameters:

file_list (list - a list of files to be filtered for Photos)

Returns:

photos

Return type:

list - a filtered list containing only the paths from the original list that are photos

civilpy.general.photos.photo_renaming_tool(root_folder=None, excel_file=None, project_name=None)[source]

Function to simplify the above functions, given a root folder, returns a list of files and searches for an Excel file to use with the renaming tool function

Parameters:
  • root_folder (str - Path to folder containing photos and Excel file defining new names)

  • excel_file (str - Path override for if the function can't find the correct file or if it's) – in a different folder

  • project_name (str - Name of the project to be included in the photo names)

Return type:

None - prints list of photo files found and renames them into another folder

civilpy.general.photos.resize_image(img, width=1024, height=768, bar_color=(0, 0, 0))[source]

Resize an image while preserving the aspect ratio and add vertical (or horizontal) bars to fit the image in the specified width and height.

Parameters:
  • img (PIL.Image) – Path to the input image.

  • width (int) – Target width of the final image.

  • height (int) – Target height of the final image.

  • bar_color (tuple) – RGB color for the bars (default is black).

civilpy.general.photos.slugify(value, allow_unicode=False)[source]

Taken from https://github.com/django/django/blob/master/django/utils/text.py Convert to ASCII if ‘allow_unicode’ is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren’t alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.

Parameters:
  • value (str - the original value containing potentially illegal characters)

  • allow_unicode (bool - Defaults to False, prevents things like language characters and emojis from being used in) – file names

Return type:

str - a string stripped of all illegal characters for use in file names

Module contents

CivilPy Copyright (C) 2019-2026 - Dane Parks

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

class civilpy.general.PrintColors[source]

Bases: object

BOLD = '\x1b[1m'
ENDC = '\x1b[0m'
FAIL = '\x1b[91m'
HEADER = '\x1b[95m'
OKBLUE = '\x1b[94m'
OKCYAN = '\x1b[96m'
OKGREEN = '\x1b[92m'
UNDERLINE = '\x1b[4m'
WARNING = '\x1b[93m'
civilpy.general.get_table_as_df(conn, schema, table)[source]