mirror of
https://github.com/platformio/platformio-core.git
synced 2025-08-01 19:04:29 +02:00
Extend package filters
This commit is contained in:
@@ -28,6 +28,7 @@ from platformio.package.unpack import FileUnpacker
|
|||||||
|
|
||||||
|
|
||||||
class PackagePacker(object):
|
class PackagePacker(object):
|
||||||
|
INCLUDE_DEFAULT = ManifestFileType.items().values()
|
||||||
EXCLUDE_DEFAULT = [
|
EXCLUDE_DEFAULT = [
|
||||||
# PlatformIO internal files
|
# PlatformIO internal files
|
||||||
PackageItem.METAFILE_NAME,
|
PackageItem.METAFILE_NAME,
|
||||||
@@ -44,12 +45,20 @@ class PackagePacker(object):
|
|||||||
".git/",
|
".git/",
|
||||||
".hg/",
|
".hg/",
|
||||||
".svn/",
|
".svn/",
|
||||||
|
# Tests
|
||||||
|
"tests?",
|
||||||
# Docs
|
# Docs
|
||||||
|
"doc",
|
||||||
"docs",
|
"docs",
|
||||||
"mkdocs",
|
"mkdocs",
|
||||||
"**/*.[pP][dD][fF]",
|
"**/*.[pP][dD][fF]",
|
||||||
"**/*.[dD][oO][cC]?",
|
"**/*.[dD][oO][cC]?",
|
||||||
"**/*.[pP][pP][tT]?",
|
"**/*.[pP][pP][tT]?",
|
||||||
|
"**/*.[dD][oO][xX]",
|
||||||
|
"**/*.[hH][tT][mM]?",
|
||||||
|
"**/*.[tT][eE][xX]",
|
||||||
|
"**/*.[jJ][sS]",
|
||||||
|
"**/*.[cC][sS][sS]",
|
||||||
# Binary files
|
# Binary files
|
||||||
"**/*.[jJ][pP][gG]",
|
"**/*.[jJ][pP][gG]",
|
||||||
"**/*.[jJ][pP][eE][gG]",
|
"**/*.[jJ][pP][eE][gG]",
|
||||||
@@ -57,8 +66,29 @@ class PackagePacker(object):
|
|||||||
"**/*.[gG][iI][fF]",
|
"**/*.[gG][iI][fF]",
|
||||||
"**/*.[zZ][iI][pP]",
|
"**/*.[zZ][iI][pP]",
|
||||||
"**/*.[gG][zZ]",
|
"**/*.[gG][zZ]",
|
||||||
|
"**/*.3[gG][pP]",
|
||||||
|
"**/*.[mM][oO][vV]",
|
||||||
|
"**/*.[mM][pP][34]",
|
||||||
|
"**/*.[pP][sS][dD]",
|
||||||
|
"**/*.[wW][aA][wW]",
|
||||||
|
]
|
||||||
|
EXCLUDE_LIBRARY_EXTRA = [
|
||||||
|
"assets",
|
||||||
|
"extra",
|
||||||
|
"resources",
|
||||||
|
"html",
|
||||||
|
"media",
|
||||||
|
"doxygen",
|
||||||
|
"**/build/",
|
||||||
|
"**/*.flat",
|
||||||
|
"**/*.[jJ][aA][rR]",
|
||||||
|
"**/*.[eE][xX][eE]",
|
||||||
|
"**/*.[bB][iI][nN]",
|
||||||
|
"**/*.[hH][eE][xX]",
|
||||||
|
"**/*.[dD][bB]",
|
||||||
|
"**/*.[dD][aA][tT]",
|
||||||
|
"**/*.[dD][lL][lL]",
|
||||||
]
|
]
|
||||||
INCLUDE_DEFAULT = ManifestFileType.items().values()
|
|
||||||
|
|
||||||
def __init__(self, package, manifest_uri=None):
|
def __init__(self, package, manifest_uri=None):
|
||||||
self.package = package
|
self.package = package
|
||||||
@@ -149,16 +179,28 @@ class PackagePacker(object):
|
|||||||
json.dump(manifest_updated, fp, indent=2, ensure_ascii=False)
|
json.dump(manifest_updated, fp, indent=2, ensure_ascii=False)
|
||||||
include = None
|
include = None
|
||||||
|
|
||||||
src_filters = self.compute_src_filters(include, exclude)
|
src_filters = self.compute_src_filters(src, include, exclude)
|
||||||
with tarfile.open(dst, "w:gz") as tar:
|
with tarfile.open(dst, "w:gz") as tar:
|
||||||
for f in fs.match_src_files(src, src_filters, followlinks=False):
|
for f in fs.match_src_files(src, src_filters, followlinks=False):
|
||||||
tar.add(os.path.join(src, f), f)
|
tar.add(os.path.join(src, f), f)
|
||||||
return dst
|
return dst
|
||||||
|
|
||||||
def compute_src_filters(self, include, exclude):
|
def compute_src_filters(self, src, include, exclude):
|
||||||
|
exclude_default = self.EXCLUDE_DEFAULT[:]
|
||||||
|
# extend with library extra filters
|
||||||
|
if any(
|
||||||
|
os.path.isfile(os.path.join(src, name))
|
||||||
|
for name in (
|
||||||
|
ManifestFileType.LIBRARY_JSON,
|
||||||
|
ManifestFileType.LIBRARY_PROPERTIES,
|
||||||
|
ManifestFileType.MODULE_JSON,
|
||||||
|
)
|
||||||
|
):
|
||||||
|
exclude_default.extend(self.EXCLUDE_LIBRARY_EXTRA)
|
||||||
|
|
||||||
result = ["+<%s>" % p for p in include or ["*", ".*"]]
|
result = ["+<%s>" % p for p in include or ["*", ".*"]]
|
||||||
result += ["-<%s>" % p for p in exclude or []]
|
result += ["-<%s>" % p for p in exclude or []]
|
||||||
result += ["-<%s>" % p for p in self.EXCLUDE_DEFAULT]
|
result += ["-<%s>" % p for p in exclude_default]
|
||||||
# automatically include manifests
|
# automatically include manifests
|
||||||
result += ["+<%s>" % p for p in self.INCLUDE_DEFAULT]
|
result += ["+<%s>" % p for p in self.INCLUDE_DEFAULT]
|
||||||
return result
|
return result
|
||||||
|
Reference in New Issue
Block a user