def test_version_sort(): versions = Version_dict() versions['0.1'] = 'create-databases' versions['0.2'] = 'create-tables' versions['1.0'] = 'feature-cool' versions['1.0.1'] = 'hotfix-your-mom' versions['2.0'] = 'release-beta' versions['2.5'] = 'halfway-super-pack' versions['3.0'] = 'upgraded-armory' versions['10.0.2'] = 'coolio-bigalo' start = versions.slice(start='2.0') assert len(start) == 4 assert start.keys() == ['2.0', '2.5', '3.0', '10.0.2'] stop = versions.slice(stop='2.0') assert len(stop) == 5 assert stop.keys() == ['0.1', '0.2', '1.0', '1.0.1', '2.0'] startstop = versions.slice('1.0', '2.0') assert len(startstop) == 3 assert startstop.keys() == ['1.0', '1.0.1', '2.0']
def test_version_sort(): versions = Version_dict() versions['0.1'] = 'create-databases' versions['0.2'] = 'create-tables' versions['1.0'] = 'feature-cool' versions['1.0.1'] = 'hotfix-your-mom' versions['2.0'] = 'release-beta' versions['2.5'] = 'halfway-super-pack' versions['3.0'] = 'upgraded-armory' versions['10.0.2'] = 'coolio-bigalo' start = versions.slice( start='2.0' ) assert len(start) == 4 assert start.keys() == ['2.0', '2.5', '3.0', '10.0.2'] stop = versions.slice( stop='2.0' ) assert len(stop) == 5 assert stop.keys() == ['0.1', '0.2', '1.0', '1.0.1', '2.0'] startstop = versions.slice( '1.0', '2.0' ) assert len(startstop) == 3 assert startstop.keys() == ['1.0', '1.0.1', '2.0']
def __init__( self, host="localhost", port=3306, user=None, password=None, packages=None, ): assert packages is not None, "packages argument must be a list of package file paths. (preferably named with the .pack extension)" self._conn = MySQLdb.connect( host=host, port=port, user=user, passwd=password, cursorclass=MySQLdb.cursors.DictCursor, ) self._cursor = self._conn.cursor() self.quiet = False # From: <path>/<version>_<name>.<ext> # To: self[<version>] = ( <name>, <path> ) self._packs = Version_dict() for pack in packages: f, ext = os.path.splitext(os.path.basename(pack)) v, name = f.split('_', 1) self._packs[v] = (pack, name)
def __init__( self, host = "localhost", port = 3306, user = None, password = None, packages = None, ): assert packages is not None, "packages argument must be a list of package file paths. (preferably named with the .pack extension)" self._conn = MySQLdb.connect( host = host, port = port, user = user, passwd = password, cursorclass = MySQLdb.cursors.DictCursor, ) self._cursor = self._conn.cursor() self.quiet = False # From: <path>/<version>_<name>.<ext> # To: self[<version>] = ( <name>, <path> ) self._packs = Version_dict() for pack in packages: f, ext = os.path.splitext( os.path.basename( pack )) v, name = f.split('_', 1) self._packs[v] = ( pack, name )
class MySQL_database(object): def __init__( self, host = "localhost", port = 3306, user = None, password = None, packages = None, ): assert packages is not None, "packages argument must be a list of package file paths. (preferably named with the .pack extension)" self._conn = MySQLdb.connect( host = host, port = port, user = user, passwd = password, cursorclass = MySQLdb.cursors.DictCursor, ) self._cursor = self._conn.cursor() self.quiet = False # From: <path>/<version>_<name>.<ext> # To: self[<version>] = ( <name>, <path> ) self._packs = Version_dict() for pack in packages: f, ext = os.path.splitext( os.path.basename( pack )) v, name = f.split('_', 1) self._packs[v] = ( pack, name ) def packages( self, start=None, stop=None ): return self._packs.slice( start, stop ) def upgrade( self, version ): packages = self._packs.slice( stop=version ) for version in packages.keys(): self.install(version) return packages def downgrade( self, version ): packages = self._packs.slice( start=version ) packages.pop(version, None) packages.reverse() for version in packages.keys(): self.uninstall(version) return packages def load( self, version ): assert version in self._packs, "There is no package with version %s" % (version,) path, name = self._packs[version] pack = imp.load_source(name, path) os.remove( path+'c' ) # remove compiled file return pack, name def install( self, version ): pack, name = self.load( version ) if not pack.check( self._conn, self._cursor ): self.quiet or print( white("""Installing: v{: <8} -- {:<40}""".format( version, name.replace('-', ' ').title() ))) pack.upgrade( self._conn, self._cursor ) def uninstall( self, version ): pack, name = self.load( version ) if pack.check( self._conn, self._cursor ): self.quiet or print( white("""Uninstalling: v{: <8} -- {:<40}""".format( version, name.replace('-', ' ').title() ))) pack.downgrade( self._conn, self._cursor )
class MySQL_database(object): def __init__( self, host="localhost", port=3306, user=None, password=None, packages=None, ): assert packages is not None, "packages argument must be a list of package file paths. (preferably named with the .pack extension)" self._conn = MySQLdb.connect( host=host, port=port, user=user, passwd=password, cursorclass=MySQLdb.cursors.DictCursor, ) self._cursor = self._conn.cursor() self.quiet = False # From: <path>/<version>_<name>.<ext> # To: self[<version>] = ( <name>, <path> ) self._packs = Version_dict() for pack in packages: f, ext = os.path.splitext(os.path.basename(pack)) v, name = f.split('_', 1) self._packs[v] = (pack, name) def packages(self, start=None, stop=None): return self._packs.slice(start, stop) def upgrade(self, version): packages = self._packs.slice(stop=version) for version in packages.keys(): self.install(version) return packages def downgrade(self, version): packages = self._packs.slice(start=version) packages.pop(version, None) packages.reverse() for version in packages.keys(): self.uninstall(version) return packages def load(self, version): assert version in self._packs, "There is no package with version %s" % ( version, ) path, name = self._packs[version] pack = imp.load_source(name, path) os.remove(path + 'c') # remove compiled file return pack, name def install(self, version): pack, name = self.load(version) if not pack.check(self._conn, self._cursor): self.quiet or print( white("""Installing: v{: <8} -- {:<40}""".format( version, name.replace('-', ' ').title()))) pack.upgrade(self._conn, self._cursor) def uninstall(self, version): pack, name = self.load(version) if pack.check(self._conn, self._cursor): self.quiet or print( white("""Uninstalling: v{: <8} -- {:<40}""".format( version, name.replace('-', ' ').title()))) pack.downgrade(self._conn, self._cursor)