def __init__(self, connection): self.dba = DBA(connection) self.parser = PlSqlParser() self.fs = SchemaIO() self.packages = []
class Schema(): def __init__(self, connection): self.dba = DBA(connection) self.parser = PlSqlParser() self.fs = SchemaIO() self.packages = [] def generate_packages(self): """Dump PLSQL packages to filesystem""" self.fs.check_packages_storage() self._save_packages() def _save_packages(self): """ Get packages, parse package specification, generate py and save """ raw_packages = self.dba.get_packages() for package in raw_packages: package = Package(package) if package.name in settings.PLSQL_PACKAGES: # parse package to get package members members = self._get_package_members(package) package.set_members(members) self.packages.append(package) # save package to fs self.fs.save_package( package.name.lower(), package.get_py_source() ) def _get_package_members(self, package): """ Function to get package members Parameters: package - instance of Package class """ source = self.dba.get_spec_source(package.name) functions, procedures, constants = self.parser.get_package_members(source) members = [] for proc in procedures: # create Procedure member = Procedure(proc['name'], package) for arg in proc['args']: member.add_argument( Argument.create(arg['name'], arg['type'], arg['oratype']) ) members.append(member) for func in functions: # create Function member = Function(func['name'], func['oratype'], package) for arg in func['args']: member.add_argument( Argument.create(arg['name'], arg['type'], arg['oratype']) ) members.append(member) for const in constants: members.append(Constant(const['name'], const['value'])) return members