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

ak sparse: keep all dirs appart addons #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions ak/ak_sparse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""AK."""

from plumbum import cli, local
from plumbum.cmd import (git)
from plumbum.cmd import git
import yaml

from .ak_build import SPEC_YAML, get_repo_key_from_spec
Expand All @@ -12,13 +13,13 @@
class AkSparse(AkSub):
"git sparse-checkout with modules"

disable = cli.Flag(
'--disable', help="disable sparse-checkout", group="IO")
disable = cli.Flag("--disable", help="disable sparse-checkout", group="IO")
config = cli.SwitchAttr(
["c", "config"], default=SPEC_YAML, help="Config file", group="IO")
["c", "config"], default=SPEC_YAML, help="Config file", group="IO"
)
directory = cli.SwitchAttr(
["d", "directory"], group="IO",
help="Only work in specified directory")
["d", "directory"], group="IO", help="Only work in specified directory"
)

def _generate_sparse_checkout(self, config):
"'Hide' modules, folder"
Expand All @@ -29,7 +30,7 @@ def _generate_sparse_checkout(self, config):
for key, repo in spec.items():
if self.directory and self.directory != key:
continue
modules = repo.pop('modules', False)
modules = repo.pop("modules", False)
if modules:
self._set_sparse_checkout(key, modules)

Expand All @@ -41,19 +42,23 @@ def _set_sparse_checkout(self, key, paths):
# do nothing
return
with local.cwd(repo_path):
if key == 'odoo':
directories = [
dir.name for dir in local.path().list()
if dir.is_dir() and dir.name[0] != '.' and dir.name != 'addons'
# remove files, hiddens (.git), addons
]
paths = ['addons/%s' % path for path in paths]
if key == "odoo":
cmd = (
# may be we can write a better cone filter
# we want everything appart /addons
git["ls-tree"]["-d"]["--name-only"]["HEAD"]
)

# ls-files gives us all the files
Copy link

Choose a reason for hiding this comment

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

do you mean "ls-tree gives us all the directories" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, I changed the command but not the comment

directories = cmd().splitlines()
paths = ["addons/%s" % path for path in paths]
paths += directories
paths.remove("addons") # remove ./addons/

if self.disable:
git['sparse-checkout', 'disable']()
git["sparse-checkout", "disable"]()
else:
git['sparse-checkout', "set", paths]()
git["sparse-checkout", "set", paths]()

def main(self, *args):
config_file = self.config
Expand Down