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(entry_data_type, db_file=None, defaults=None)

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.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)

Removes files, specified by path/filter

py_knife.file_system.save_file(file_path, file_content, encoding=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

class py_knife.logger.Logger(filename=None)

Bases: object

write(message)

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:

class py_knife.ordered_dict.OrderedDict(*args, **kwds)

Bases: dict

Dictionary that remembers insertion order

clear() → None. Remove all items from od.
copy() → a shallow copy of od
classmethod fromkeys(S[, v]) → New ordered dictionary with keys from S

and values equal to v (which defaults to None).

insert_after(existing_key, key_value)
insert_before(existing_key, key_value)
items() → list of (key, value) pairs in od
iteritems()

od.iteritems -> an iterator over the (key, value) items in od

iterkeys() → an iterator over the keys in od
itervalues()

od.itervalues -> an iterator over the values in od

keys() → list of keys in od
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), return and remove a (key, value) pair.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(k[, d]) → od.get(k,d), also set od[k]=d if k not in od
update(E, **F) → None. Update od from dict/iterable E and F.

If E is a dict instance, does: for k in E: od[k] = E[k] If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] Or if E is an iterable of items, does: for k, v in E: od[k] = v In either case, this is followed by: for k, v in F.items(): od[k] = v

values() → list of values in od
viewitems() → a set-like object providing a view on od's items
viewkeys() → a set-like object providing a view on od's keys
viewvalues() → an object providing a view on od's values

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.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.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