Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding suffix methods and properties #198

Merged
merged 2 commits into from
Jul 10, 2015
Merged

Conversation

henryiii
Copy link
Collaborator

@henryiii henryiii commented Jul 9, 2015

The suffix, suffixes properties andwith_name, with_suffix methods were added
(names chosen to be similar to other packages, like the builtin pathlib). One
difference vs. pathlib is an optional parameter for the with_suffix method that
allows simple manipulation of extended suffixes, like .tar.gz.

These additions are useful for working with multiple files of the same name,
such as when compiling programs or documents, and for packing/changing
compressed files.

Documentation, local and remote (and base class) support, unittests, and an
example were added.

As a quick example, here is .tar.gz -> .zip conversion, adopted from the bash script at http://stackoverflow.com/questions/6301885/convert-tar-gz-to-zip :

from plumbum import local
from plumbum.cmd import tar, zip, mkdir, rm
files = local.cwd // "*.tar.gz"
for file in files:
    tmpfolder = file.with_suffix(".tmp", 0) # .tar.gz.tmp temporary folder
    mkdir(tmpfolder)
    tar("-C", tmpfolder, "-xvzf", file)
    with local.cwd(tmpfolder):
        zip("-r", file.with_suffix(".zip", 2), ".")
    rm("-rf", tmpfolder)

And this would compile a tex file and remove the extra files generated:

from plumbum.cmd import pdflatex
from plumbum.path.utils import delete
from plumbum import local, FG
item = local.cwd / "document.tex"
pdflatex[item] & FG
delete(item.with_suffix(".log"), item.with_suffix(".aux"))

Henry Schreiner (Muon Linux) added 2 commits July 9, 2015 10:26
The suffix, suffixes properties and with_name, with_suffix methods were added
(names chosen to be similar to other packages, like the builtin pathlib). One
difference vs. pathlib is an optional parameter for the with_suffix method that
allows simple manipulation of extended suffixes, like .tar.gz.

These additions are useful for working with multiple files of the same name,
such as when compiling programs or documents, and for packing/changing
compressed files.

Documentation, local and remote (and base class) support, unittests, and an
example were added.
tomerfiliba added a commit that referenced this pull request Jul 10, 2015
Adding suffix methods and properties
@tomerfiliba tomerfiliba merged commit f96134d into tomerfiliba:master Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants