py_knife package¶
Submodules¶
py_knife.aes module¶
AES Encrypt/Decrypt Library
-
py_knife.aes.
decrypt
(in_filename, out_filename, password)¶ External Decrypt function
-
py_knife.aes.
encrypt
(in_filename, out_filename, password)¶ External Encrypt function
py_knife.com_port module¶
Serial(COM) Port Functions
-
py_knife.com_port.
available_ports
()¶ Returns list of available serial ports
py_knife.database module¶
Database Classes Classes that save/load python content to/from the hard drive(or other means of non-volatile memory). Make sure to provide pickle-able data, no objects, classes or anything that might be hard to convert to a string Please do not use DatabaseEntry directly, nor DatabaseDictBase. Those are exposed for overloading purposes. Use DatabaseList, DatabaseDict or DatabaseOrderedDict!
-
class
py_knife.database.
DatabaseDict
(**kwargs)¶ Bases:
py_knife.database.DatabaseDictBase
DatabaseDict class
-
class
py_knife.database.
DatabaseDictBase
(*args, **kwargs)¶ Bases:
py_knife.database.DatabaseEntry
Some Dictionary Specific Methods
-
clear
()¶ Allows using clear method
-
items
()¶ Allows using items method
-
keys
()¶ Allows using keys method
-
update
(value)¶ Allows using update method
-
values
()¶ Allows using values method
-
-
class
py_knife.database.
DatabaseEntry
(entry_data_type, db_file=None, defaults=None)¶ Bases:
object
DatabaseEntry class
-
delete
()¶ Deletes database file
-
load
()¶ External Load
-
pop
(index)¶ Allows using pop method
-
save
(db_content=None)¶ Saves main to a file
-
-
class
py_knife.database.
DatabaseList
(**kwargs)¶ Bases:
py_knife.database.DatabaseEntry
DatabaseList class
-
append
(value)¶ Allows using append method
-
extend
(value)¶ Allows using extend method
-
insert
(index, value)¶ Allows using insert method
-
-
class
py_knife.database.
DatabaseOrderedDict
(**kwargs)¶ Bases:
py_knife.database.DatabaseDictBase
DatabaseOrderedDict class
-
insert_after
(existing_key, key_value)¶ Allows using insert_after method
-
insert_before
(existing_key, key_value)¶ Allows using insert_before method
-
py_knife.decorators module¶
Collection of decorators to make our life a little easier Simple Decorator is based on a recipe from here: https://wiki.python.org/moin/PythonDecoratorLibrary
-
py_knife.decorators.
multiple_attempts
(f)¶ Decorator to perform multiple attempts
-
py_knife.decorators.
simple_decorator
(decorator)¶ This decorator can be used to turn simple functions into well-behaved decorators, so long as the decorators are fairly simple. If a decorator expects a function and returns a function (no descriptors), and if it doesn’t modify function attributes or docstring, then it is eligible to use this. Simply apply @simple_decorator to your decorator and it will automatically preserve the docstring and function attributes of functions to which it is applied.
-
py_knife.decorators.
time_it
(f)¶ Decorator to time function execution
py_knife.file_system module¶
This module functionality consist of:
- File Manipulation Functions
- Directory Manipulation Functions
- File/Folder Memory Space/Size Functions
- Open/Write/Read File Functions
- Time Stamp Functions
-
py_knife.file_system.
copy_dir
(source_path, destination_path)¶
-
py_knife.file_system.
copy_file
(source_file, destination_file, permissions=None, dos2unix=True)¶ Copying File :param source_file: Source File Path :param destination_file: Destination File Path :param permissions: Permissions string (for unix only) :param dos2unix: Conversion to unix format (for unix only) :return: True if copying is successful, False otherwise
-
py_knife.file_system.
create_time_stamp
(time_stamp_format)¶
-
py_knife.file_system.
empty_dir
(dir_path)¶ Empty directory :param dir_path: Path of the directory :return: True if empty successful (such directory existed in the first place), False otherwise
-
py_knife.file_system.
fetch_file
(file_path)¶ Fetches files, specified by path/filter
-
py_knife.file_system.
get_free_space
(path)¶ Return free space in bytes Taken from here, slightly modified: http://stackoverflow.com/questions/51658/cross-platform-space-remaining-on-volume-using-python
-
py_knife.file_system.
get_size
(path)¶ Taken from here http://stackoverflow.com/questions/1392413/calculating-a-directory-size-using-python
-
py_knife.file_system.
make_dir
(dir_path)¶ Creating directory :param dir_path: Path of the new directory :return: True if folder has been created, False if folder exists already
-
py_knife.file_system.
make_file
(file_path)¶ Creating empty file
-
py_knife.file_system.
open_file
(file_path, mode, encoding=None)¶ Tries reading file. Returns false if failed
-
py_knife.file_system.
print_memory_size
(size)¶ Taken from here http://stackoverflow.com/questions/1392413/calculating-a-directory-size-using-python
-
py_knife.file_system.
remove_dir
(dir_path)¶ Removing directory :param dir_path: Path of the directory :return: True if remove successful (such directory existed in the first place), False otherwise
-
py_knife.file_system.
remove_file
(file_path)¶
-
py_knife.file_system.
remove_files
(files_path, exclude_paths=None)¶ Removes files, specified by path/filter
-
py_knife.file_system.
save_file
(file_path, file_content, encoding=None, permissions=None)¶ Tries to open file for writing
-
py_knife.file_system.
write_file
(file_instance, file_content)¶ Tries writing file
py_knife.logger module¶
Logger Class
To use logger simply:
import sys
sys.stdout = Logger(log_file_path)
py_knife.ordered_dict module¶
Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy. Passes Python2.7’s test suite and incorporates all the latest updates.
Reference links:
py_knife.pickle module¶
Pickle/Unpickle Functions
-
py_knife.pickle.
pickle_file
(file_path, data_to_pickle)¶ Pickle file
-
py_knife.pickle.
unpickle_file
(file_path)¶ Unpickle file
py_knife.platforms module¶
Determine current platform Uses python platform module to determine if run this script on Windows, MAC, Ubuntu or Debian Linux Or ‘Raspberry Pi’ or ‘Synapse E10’ system
py_knife.py_install module¶
Python Distribution Install Functions
-
py_knife.py_install.
install_package
(package_name, package_path=None)¶ Runs install inside of install
py_knife.py_setup module¶
Python Distribution Package Utilities
Used quite a few recipes from here: https://wiki.python.org/moin/Distutils/Cookbook Some hints on how to extend commands http://stackoverflow.com/questions/1321270/how-to-extend-distutils-with-a-simple-post-install-script/1321345#1321345
-
py_knife.py_setup.
find_packages
(path, base='')¶ Find all packages in path
-
py_knife.py_setup.
generate_docs
(doc_packages)¶ Generates documentation. Performed before generating distribution on host (Windows) system
-
py_knife.py_setup.
is_package
(path)¶
-
py_knife.py_setup.
non_python_files
(path, ignore_dirs=None)¶ Return all non-python-file file names in path
-
py_knife.py_setup.
package_data_files
(path, ignore_dirs=None)¶ Returns all file names in path in package data format
py_knife.upload module¶
Web Upload Functions
-
py_knife.upload.
save_upload
(upload_folder_path, upload_data)¶ Tries to open Upload File
py_knife.zip module¶
Zip Archive Functions
-
py_knife.zip.
create_zip
(zip_path, files_path)¶ Creates Zip Archive
-
py_knife.zip.
extract_zip
(zip_path, extract_path=None, password=None)¶ Opens Zip Archive in order to extract files
Module contents¶
Swiss Army Knife of Python