Commit 71340d69 authored by Klint Youngmeyer's avatar Klint Youngmeyer
Browse files

Initial commit

EMAC Micropython Helper Scripts
These scripts are useful while developing on the REPL or for repetetive tasks within a larger script.
This script is mostly intended to be used from the REPL to verify the contents of files.
### Usage
Just pass the file name, as a string, to the `cat` function.
### Example
>>> from cat import cat
>>> cat('filename.txt')
This is what is in the file.
This script houses the `tar_extract` function, which is intented to be used with the []( and []( modules to make archive extraction easier. The `tar_extract` function will create a directory (if necessary) and extract the files to that (or the current) directory.
### Usage
import os
import extract
"""Contains the cat functuion"""
def cat(file_name):
"""Prints the contents of a file to the screen"""
with open(file_name, 'r') as file_descriptor:
"""This module houses helper functions for extracting archive files"""
import os
# and can be obtained
# from
import shutil
import utarfile
# This function, and by extension the module, is only intended to
# be used on a tar archive, without any compression. The tar file should be
# saved to non-volatile memory, as a file. Use os.chdir(directory) to move to
# the desired destination for the extracted files, before extracting.
def tar_extract(file_name):
"""This function extracts an uncompressed tar file into the directory name
it was archived from"""
tar = utarfile.TarFile(file_name)
for i in tar:
if i.type == utarfile.DIRTYPE:
if != './':
sub_file = tar.extractfile(i)
with open(, "wb") as dest:
shutil.copyfileobj(sub_file, dest)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment