Skip to main content

A manipulation package to change whole folders.

Project description

File manipulation

Explanation:

The idea is to transform a function that transform one text into another text and call it transforming the desired files with that function.

This is not a package made thinking about being used in a project, rather it's a package made to make a programmer's life easier.

INSTRUCTIONS:

Decorator that transforms an [str] = function( [str]:text, *args, **kwargs ) into an function that apllies itself into a folder.

The default values for the new function can be set at the decorator.

at - regex to search target files path - folder with files to change (start folder on recursive mode) recursive - makes the function call itself on all folders inside the start folder ignore - ignore changes on file if function returns any error and continues to the next file test - creates a new file with the changes for test (NOT recommended with: recursive = True) prefix/posfix - strings added before and after test files log - shows on console steps

Default values on decorator are set to avoid writting over important files with broken functions.

!! ATENTION !!

MAKE SURE TO ALWAYS TEST YOUR FUNCTIONS BEFORE APPLYING ANY TRUE CHANGES.

Simple functions:

Imagine you want to comment all prints in your project:

from manip import manip

@manip()
def comment_print(text):
    return text.replace('print(', '# print(')

Now we can call the function on a folder like:

comment_print(path='./target')
comment_print(path='./target', test=False) # to save changes on original files

If you wanna just call a single line function on the command line you can import manipulate:

from manip import manipulate

manipulate(lambda text: text.replace('print(', '# print('), path='./target', test=False)

up to change whole files with json data, maybe:

from manip import manip
import json

@manip(at='.json$')
def join_props(text, prop1='key', prop2='value', new_prop='new'):
    obj = json.loads(text)
    obj[new_prop] = (prop1, prop2)

    del(obj[prop1])
    del(obj[prop2])

    return json.dumps(obj)

More info:

GitHub

<style> p { font-size: 19px; } .params { display: flex; flex-direction: column; margin-left: 3%; font-size: 17px; margin-bottom: 15px; } </style>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manip-0.2.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

manip-0.2-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page