diff --git a/pmb/chroot/zap.py b/pmb/chroot/zap.py index bb9f2b0a..f03a5155 100644 --- a/pmb/chroot/zap.py +++ b/pmb/chroot/zap.py @@ -23,7 +23,7 @@ import pmb.chroot import pmb.helpers.run -def zap(args): +def zap(args, confirm=True, packages=False, http=False): pmb.chroot.shutdown(args) patterns = [ "chroot_native", @@ -33,14 +33,14 @@ def zap(args): # Only ask for removal, if the user specificed the extra '-p' switch. # Deleting the packages by accident is really annoying. - if args.packages: + if packages: patterns += ["packages"] - if args.http: + if http: patterns += ["cache_http"] for pattern in patterns: pattern = os.path.realpath(args.work + "/" + pattern) matches = glob.glob(pattern) for match in matches: - if pmb.helpers.cli.confirm(args, "Remove " + match + "?"): + if not confirm or pmb.helpers.cli.confirm(args, "Remove " + match + "?"): pmb.helpers.run.root(args, ["rm", "-rf", match]) diff --git a/pmb/config/init.py b/pmb/config/init.py index 7140eb54..b4770780 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -17,12 +17,14 @@ You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see . """ import logging +import glob import os import pmb.config import pmb.helpers.cli import pmb.helpers.devices import pmb.helpers.ui +import pmb.chroot.zap def ask_for_work_path(args): @@ -39,7 +41,7 @@ def ask_for_work_path(args): ret = os.path.expanduser(pmb.helpers.cli.ask( args, "Work path", None, args.work, False)) os.makedirs(ret, 0o700, True) - os.makedirs(ret + "/chroot_native", 0o755, True) + os.makedirs(ret + "/cache_http", 0o700, True) return ret except OSError: logging.fatal("ERROR: Could not create this folder, or write" @@ -102,9 +104,18 @@ def init(args): # Save config pmb.config.save(args, cfg) + if len(glob.glob(args.work + "/chroot_*")) and pmb.helpers.cli.confirm(args, "Zap existing chroots to apply configuration?", default=True): + if not os.path.exists(args.aports + "/device/device-" + args.device + "/deviceinfo"): + setattr(args, "deviceinfo", None) + else: + setattr(args, "deviceinfo", pmb.parse.deviceinfo(args)) + # Do not zap any existing packages or cache_http directories + pmb.chroot.zap(args, confirm=False) + logging.info( "WARNING: The applications in the chroots do not get updated automatically.") logging.info("Run 'pmbootstrap zap' to delete all chroots once a day before" " working with pmbootstrap!") logging.info("It only takes a few seconds, and all packages are cached.") + logging.info("Done!") diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index b0a4be51..ed10bd35 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -164,4 +164,4 @@ def log_distccd(args): def zap(args): - pmb.chroot.zap(args) + pmb.chroot.zap(args, packages=args.packages, http=args.http)