- logger.debug("uid is %d" % os.getuid())
- dir = args[0]
- try:
- os.chdir(dir)
- except OSError as e:
- if e.errno == errno.EACCES:
- raise _base.PermissionsError(dir)
- elif e.errno == errno.ENOENT:
- raise _base.NoSuchDirectoryError(dir)
- else: raise e
- if os.path.isdir(".git") or os.path.isdir(".scripts"):
- if not options.force:
- raise AlreadyMigratedError(dir)
- else:
- if os.path.isdir(".git"):
- logger.warning("Force removing .git directory")
- if not options.dry_run: shutil.rmtree(".git")
- if os.path.isdir(".scripts"):
- logger.warning("Force removing .scripts directory")
- if not options.dry_run: shutil.rmtree(".scripts")
- try:
- d = deploy.Deployment.fromDir(".")
- version = d.getAppVersion()
- except IOError as e:
- if e.errno == errno.ENOENT:
- raise NotAutoinstallError(dir)
- else: raise e
- # calculate the repository we'll be pulling out of
- application = version.application
- app = application.name
- repo = os.path.join("/afs/athena.mit.edu/contrib/scripts/wizard/srv", app + ".git")
- if not os.path.isdir(repo):
- raise NoRepositoryError(app)
- # begin the command line process
- sh = shell.Shell(logger, options.dry_run)
- # check if the version we're trying to convert exists. We assume
- # a convention here, namely, v1.2.3-scripts is what we want. If
- # you broke the convention... shame on you.
- try:
- tag = "v%s-scripts" % version.version
- sh.call("git", "--git-dir", repo, "rev-parse", tag)
- except shell.CallError:
- raise NoTagError(version)
- did_git_init = False
- did_git_checkout_scripts = False
- # create repository
- sh.call("git", "init")
- did_git_init = True
+ return (options, args)
+
+def perform_force(options):
+ has_git = os.path.isdir(".git")
+ has_scripts = os.path.isdir(".scripts")
+
+ if has_git:
+ logging.warning("Force removing .git directory")
+ if not options.dry_run: backup = util.safe_unlink(".git")
+ logging.info(".git backed up to %s" % backup)
+ if has_scripts:
+ logging.warning("Force removing .scripts directory")
+ if not options.dry_run: backup = util.safe_unlink(".scripts")
+ logging.info(".scripts backed up to %s" % backup)
+
+def make_repository(sh, options, repo, tag):
+ sh.call("git", "init") # create repository