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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file manip-0.2.tar.gz.

File metadata

  • Download URL: manip-0.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for manip-0.2.tar.gz
Algorithm Hash digest
SHA256 7928e1964d95ab40ec4410555d254857bccdde583a1d3249060bffdfefcdde02
MD5 f9bf9336e0906598556907540be0b662
BLAKE2b-256 526d41c9f3ce1dd6e02c915c158023aece6b12a333392d81948af3afd1a09ba3

See more details on using hashes here.

File details

Details for the file manip-0.2-py3-none-any.whl.

File metadata

  • Download URL: manip-0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for manip-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8386cf1e6fd303c867280ce712c892ea431fe18eb85ff03f8edd94d8100f533
MD5 f6e7a207225c47bd2c93e2b8fabbb693
BLAKE2b-256 a2350855ee4a37dfa62ffa7cb2831e84adc737e1c7163cc9eef931d0b083a1c2

See more details on using hashes here.

Supported by

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