# Path: pg_export/pg_items/item.py
# class Item (object):
#     template = None
#     directory = None
#     ext = '.sql'
# 
#     def __init__(self, src, renderer):
#         self.__dict__.update(src)
#         self.renderer = renderer
#         if 'schema' in self.__dict__ and 'name' in self.__dict__:
#             self.full_name = filters.get_full_name(self.schema, self.name)
# 
#     def dump(self, root):
#         if not os.path.isdir(os.path.join(root, self.schema, self.directory)):
#             os.mkdir(os.path.join(root, self.schema, self.directory))
#         self.renderer.render_to_file(
#             self.template,
#             self.__dict__,
#             (root, self.schema, self.directory,
#              self.name.replace('"', '') + self.ext))
# 
#     def render(self, template):
#         return self.renderer.render(template, self.__dict__)
# 
# Path: pg_export/acl.py
# def acl_to_grants(acl, obj_type, obj_name, subobj_name=''):
#     if not acl:
#         return ''
# 
#     res = []
#     if obj_type in ['function', 'procedure']:
#         for fpa in function_public_acl:
#             if fpa in acl:
#                 acl.remove(fpa)
#                 break
#         else:
#             res.append(
#                 'revoke all on %(obj_type)s %(obj_name)s from public;'
#                 % locals())
#     for a in sorted('public' + i if i.startswith('=') else i
#                     for i in acl):
#         role, perm = a.split('/')[0].split('=')  # format: role=perm/grantor
#         if role in ['postgres', 'gpadmin']:
#             continue
# 
#         if subobj_name:  # column
#             subobj_name = '(%s) ' % subobj_name
# 
#         perm, gr_opt = resolve_perm(obj_type, perm)
#         if obj_type == 'column':
#             obj_type = 'table'
#         res.append(
#             'grant %(perm)s %(subobj_name)son %(obj_type)s '
#             '%(obj_name)s to %(role)s;'
#             % locals())
#     return '\n'.join(res)


from pg_export.pg_items.item import Item
from pg_export.acl import acl_to_grants


class Sequence (Item):
    template = 'out/sequence.sql'
    directory = 'sequences'

    def __init__(self, src, version):
        super(Sequence, self).__init__(src, version)

# Path: pg_export/pg_items/item.py
# class Item (object):
#     template = None
#     directory = None
#     ext = '.sql'
# 
#     def __init__(self, src, renderer):
#         self.__dict__.update(src)
#         self.renderer = renderer
#         if 'schema' in self.__dict__ and 'name' in self.__dict__:
#             self.full_name = filters.get_full_name(self.schema, self.name)
# 
#     def dump(self, root):
#         if not os.path.isdir(os.path.join(root, self.schema, self.directory)):
#             os.mkdir(os.path.join(root, self.schema, self.directory))
#         self.renderer.render_to_file(
#             self.template,
#             self.__dict__,
#             (root, self.schema, self.directory,
#              self.name.replace('"', '') + self.ext))
# 
#     def render(self, template):
#         return self.renderer.render(template, self.__dict__)
# 
# Path: pg_export/acl.py
# def acl_to_grants(acl, obj_type, obj_name, subobj_name=''):
#     if not acl:
#         return ''
# 
#     res = []
#     if obj_type in ['function', 'procedure']:
#         for fpa in function_public_acl:
#             if fpa in acl:
#                 acl.remove(fpa)
#                 break
#         else:
#             res.append(
#                 'revoke all on %(obj_type)s %(obj_name)s from public;'
#                 % locals())
#     for a in sorted('public' + i if i.startswith('=') else i
#                     for i in acl):
#         role, perm = a.split('/')[0].split('=')  # format: role=perm/grantor
#         if role in ['postgres', 'gpadmin']:
#             continue
# 
#         if subobj_name:  # column
#             subobj_name = '(%s) ' % subobj_name
# 
#         perm, gr_opt = resolve_perm(obj_type, perm)
#         if obj_type == 'column':
#             obj_type = 'table'
#         res.append(
#             'grant %(perm)s %(subobj_name)son %(obj_type)s '
#             '%(obj_name)s to %(role)s;'
#             % locals())
#     return '\n'.join(res)


# Path: pg_export/pg_items/sequence.py
from pg_export.pg_items.item import Item
from pg_export.acl import acl_to_grants



class Sequence (Item):
    template = 'out/sequence.sql'
    directory = 'sequences'

    def __init__(self, src, version):
        super(Sequence, self).__init__(src, version)

        self.grants = acl_to_grants(self.acl, 'sequence', self.full_name)