def setUp(self): Configuration._Configuration__config = ConfigParser.SafeConfigParser() shutil.rmtree("./tmp", True) shutil.rmtree("./repo", True) Repository.create("./tmp") fs.write("./tmp/a.local.module", "This is a local, raw module.") ModuleInstaller("./tmp").install(["./tmp/a.local.module"])
def testItShouldNotDisableAnUnknownModuleRepository(self): Configuration._Configuration__config = self.mockConfigWithRepos([]) try: Repository.disable("./tmp") assert False, "expected UnknownRepository" except UnknownRepository: pass
def testItShouldDeleteAModuleRepository(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() Repository.create("./tmp") Repository.delete("./tmp") assert not os.path.exists("./tmp") assert Repository.all() == []
def testItShouldEnableAModuleRepository(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() Repository.create("./tmp") Configuration._Configuration__config = self.mockConfigWithoutRepos() Repository.enable("./tmp") assert Repository.all() == ["./tmp"] shutil.rmtree("./tmp")
def testItShouldNotCreateARepositoryOverAnExistingFolder(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() os.mkdir("./tmp") try: Repository.create("./tmp") assert False, "expected NotEmptyException" except NotEmptyException: pass shutil.rmtree("./tmp")
def testItShouldCreateAModuleRepository(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() Repository.create("./tmp") assert os.path.exists("./tmp") assert os.path.exists("./tmp/__init__.py") assert os.path.exists("./tmp/.mercury_repository") assert Repository.all() == ["./tmp"] shutil.rmtree("./tmp")
def do_enable(self, arguments): """enable a previously disabled Module repository""" if len(arguments.options) == 1: path = arguments.options[0] try: Repository.enable(path) print "Enabled repository at %s.\n" % path except UnknownRepository: print "The target (%s) is not a Mercury module repository.\n" % path else: print "usage: mercury module repository enable /path/to/repository\n"
def do_disable(self, arguments): """hide a Module repository, without deleting its contents""" if len(arguments.options) == 1: path = arguments.options[0] try: Repository.disable(path) print "Hidden repository at %s.\n" % path except UnknownRepository: print "The target (%s) is not a Mercury module repository.\n" % path else: print "usage: mercury module repository disable /path/to/repository\n"
def do_create(self, arguments): """create a new Mercury module repository""" if len(arguments.options) == 1: path = arguments.options[0] try: Repository.create(path) print "Initialised repository at %s.\n" % path except NotEmptyException: print "The target (%s) already exists.\n" % path else: print "usage: mercury module repository create /path/to/repository\n"
def do_delete(self, arguments): """remove a Mercury module repository""" if len(arguments.options) == 1: path = arguments.options[0] try: Repository.delete(path) print "Removed repository at %s.\n" % path except UnknownRepository: print "The target (%s) is not a Mercury module repository.\n" % path else: print "usage: mercury module repository delete /path/to/repository\n"
def __choose_repo(self): """ Return the path of a repository, either the only repo or presenting the user with a choice. """ repositories = Repository.all() if len(repositories) == 1: return repositories[0] elif len(repositories) == 0: print "You do not have a Mercury module repository." if self.confirm("Would you like to create one?") == "y": while True: path = self.ask("Path to new repository: ") try: Repository.create(path) print "Initialised repository at %s.\n" % path return Repository.all()[0] except NotEmptyException: print "The target (%s) already exists.\n" % path return None else: return None else: print "You have %d Mercury module repositories. Which would you like to install into?\n" % len( repositories) for i in xrange(len(repositories)): print " %5d %s" % (i + 1, repositories[i]) print while (True): print "repo>", try: idx = int(raw_input().strip()) if idx >= 1 and idx <= len(repositories): print return repositories[idx - 1] else: raise ValueError(idx) except ValueError: print "Not a valid selection. Please enter a number between 1 and %d." % len( repositories)
def testItShouldNotDeleteAnUnknownRepository(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() os.mkdir("./tmp") try: Repository.delete("./tmp") assert False, "expected UnknownRepository" except UnknownRepository: pass assert os.path.exists("./tmp") shutil.rmtree("./tmp")
def testItShouldNotEnableAFolderThatIsnNotAModuleRepository(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() os.mkdir("./tmp") try: Repository.enable("./tmp") assert False, "expected UnknownRepository" except UnknownRepository: pass assert Repository.all() == [] shutil.rmtree("./tmp")
def __choose_repo(self): """ Return the path of a repository, either the only repo or presenting the user with a choice. """ repositories = Repository.all() if len(repositories) == 1: return repositories[0] elif len(repositories) == 0: print "You do not have a Mercury module repository." if self.confirm("Would you like to create one?") == "y": while True: path = self.ask("Path to new repository: ") try: Repository.create(path) print "Initialised repository at %s.\n" % path return Repository.all()[0] except NotEmptyException: print "The target (%s) already exists.\n" % path return None else: return None else: print "You have %d Mercury module repositories. Which would you like to install into?\n" % len(repositories) for i in xrange(len(repositories)): print " %5d %s" % (i + 1, repositories[i]) print while True: print "repo>", try: idx = int(raw_input().strip()) if idx >= 1 and idx <= len(repositories): print return repositories[idx - 1] else: raise ValueError(idx) except ValueError: print "Not a valid selection. Please enter a number between 1 and %d." % len(repositories)
def __list_repositories(self): """ Print a list of Mercury repositories (a) on the local system, and (b) registered as remotes. """ print "Local repositories:" for repo in Repository.all(): print " %s" % repo print
def testItShouldRetrieveNoAdditionalRepositories(self): Configuration._Configuration__config = self.mockConfigWithRepos([]) assert Repository.all() == []
def testItShouldRetrieveAllWithoutAConfigFile(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() assert Repository.all() == []
def testItShouldBuildDroidhgModulesPathAsDefault(self): Configuration._Configuration__config = self.mockConfigWithRepos([]) assert Repository.droidhg_modules_path() == ""
def testItShouldBuildDroidhgModulesPathWithTwoAdditionalRepository(self): Configuration._Configuration__config = self.mockConfigWithRepos(['/usr/local/mercury/modules', '/tmp/modules']) assert Repository.droidhg_modules_path() == "/usr/local/mercury/modules:/tmp/modules"
def testItShouldBuildDroidhgModulesPathWithoutAConfigFile(self): Configuration._Configuration__config = self.mockConfigWithoutRepos() assert Repository.droidhg_modules_path() == ""
def testItShouldRetrieveAnAdditionalRepository(self): Configuration._Configuration__config = self.mockConfigWithRepos(['/usr/local/mercury/modules']) assert Repository.all() == ['/usr/local/mercury/modules']
def setUp(self): Configuration._Configuration__config = ConfigParser.SafeConfigParser() shutil.rmtree("./tmp", True) Repository.create("./tmp")