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

Unzip flat directory #8208

Merged
merged 14 commits into from Dec 20, 2020
Merged

Unzip flat directory #8208

merged 14 commits into from Dec 20, 2020

Conversation

lasote
Copy link
Contributor

@lasote lasote commented Dec 14, 2020

Changelog: Feature: The tools.get, tools.unzip and tools.untargz now accept a new argument strip_root=True to unzip moving all the files to the parent folder when all of them belongs to a single folder.
Docs: conan-io/docs#1967

Closes #6479

When a zip file structure is the following:

- folder/file
- folder/file2
- folder/folder2/file3

If you use the flat_folder=True it will extract:

- file
- file2
- folder2/file3
  • If there is more than one folder in the zip it will raise.
  • If there is a file in the root folder it will raise.

@lasote lasote added this to the 1.33 milestone Dec 14, 2020
conans/test/unittests/util/files/flat_extract_test.py Outdated Show resolved Hide resolved
conans/client/tools/files.py Outdated Show resolved Hide resolved
conans/client/tools/files.py Outdated Show resolved Hide resolved
@SSE4
Copy link
Contributor

SSE4 commented Dec 15, 2020

what do you think on returning the flat directory, so it could be chained like:

with chdir(get(URL)):
    do_something()

@lasote
Copy link
Contributor Author

lasote commented Dec 15, 2020

But this feature removes the directory... why do you want to return it?
If you are thinking of another feature to return the directory but not "flat" it, I don't think that is the correct way to operate. We should avoid as much as possible to change directories in the recipes and declare everything as a recipe layout.

@@ -72,17 +71,6 @@
"""


def zipdir(path, zipfilename):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to test utils

@memsharded memsharded self-assigned this Dec 15, 2020
conans/client/tools/files.py Outdated Show resolved Hide resolved
conans/client/tools/files.py Show resolved Hide resolved
@@ -55,7 +55,8 @@ def human_size(size_bytes):
return "%s%s" % (formatted_size, suffix)


def unzip(filename, destination=".", keep_permissions=False, pattern=None, output=None):
def unzip(filename, destination=".", keep_permissions=False, pattern=None, output=None,
flat_folder=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flat_folder name could be improved?, I would read it as getting rid of all levels of subfolders, not just dropping the first level one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, suggestions? crop_first_folder, flat_first....?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore_root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip_root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flat_root?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conans/client/tools/files.py Outdated Show resolved Hide resolved
Co-authored-by: James <james@conan.io>
conans/client/tools/files.py Outdated Show resolved Hide resolved
conans/client/tools/files.py Outdated Show resolved Hide resolved
conans/client/tools/files.py Outdated Show resolved Hide resolved
conans/client/tools/files.py Outdated Show resolved Hide resolved
@@ -55,7 +55,8 @@ def human_size(size_bytes):
return "%s%s" % (formatted_size, suffix)


def unzip(filename, destination=".", keep_permissions=False, pattern=None, output=None):
def unzip(filename, destination=".", keep_permissions=False, pattern=None, output=None,
flat_folder=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lasote and others added 2 commits December 15, 2020 18:39
Co-authored-by: James <james@conan.io>
@memsharded memsharded requested a review from SSE4 December 15, 2020 17:56
@memsharded memsharded merged commit 9bb4768 into conan-io:develop Dec 20, 2020
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.

[feature] Automatic directory management in source unpack support
3 participants