# Path: arbalest/s3.py
# def normalize_path(path):
#     return posixpath.normpath(path)
# 
# Path: arbalest/sql.py
# class Database(object):
#     cursor = None
# 
#     def __init__(self, connection):
#         self.connection = connection
# 
#     def open(self):
#         if self.cursor is None:
#             self.cursor = self.connection.cursor()
# 
#     def execute(self, sql, params=None):
#         try:
#             return self.cursor.execute(sql, params)
#         except ValueError, e:
#             if params is None:
#                 return self.cursor.execute(sql, '')
#             else:
#                 raise ValueError(e)
# 
#     def fetchall(self):
#         for row in self.cursor:
#             yield row
# 
#     def commit(self):
#         return self.connection.commit()
# 
#     def rollback(self):
#         return self.connection.rollback()
# 
#     def close(self):
#         return self.connection.close()


import json
from arbalest.s3 import normalize_path
from arbalest.sql import Database


class Manifest(object):
    def __init__(self, metadata, source, schema, bucket):
        self.metadata = metadata
        self.source = source
        self.schema = schema
        self.bucket = bucket
        self.file_name = '{0}_manifest.json'.format(schema.table)
        self.journal_file_name = '{0}_journal.json'.format(schema.table)

    @property
    def all_keys(self):
        return [k.name for k in self.bucket.list(self.source) if
                not k.name.endswith('/')]

    @property
    def manifest_key(self):
        return normalize_path('{0}/{1}'.format(self.metadata, self.file_name))

    @property
    def journal_key(self):

# Path: arbalest/s3.py
# def normalize_path(path):
#     return posixpath.normpath(path)
# 
# Path: arbalest/sql.py
# class Database(object):
#     cursor = None
# 
#     def __init__(self, connection):
#         self.connection = connection
# 
#     def open(self):
#         if self.cursor is None:
#             self.cursor = self.connection.cursor()
# 
#     def execute(self, sql, params=None):
#         try:
#             return self.cursor.execute(sql, params)
#         except ValueError, e:
#             if params is None:
#                 return self.cursor.execute(sql, '')
#             else:
#                 raise ValueError(e)
# 
#     def fetchall(self):
#         for row in self.cursor:
#             yield row
# 
#     def commit(self):
#         return self.connection.commit()
# 
#     def rollback(self):
#         return self.connection.rollback()
# 
#     def close(self):
#         return self.connection.close()


# Path: arbalest/redshift/manifest.py
import json
from arbalest.s3 import normalize_path
from arbalest.sql import Database



class Manifest(object):
    def __init__(self, metadata, source, schema, bucket):
        self.metadata = metadata
        self.source = source
        self.schema = schema
        self.bucket = bucket
        self.file_name = '{0}_manifest.json'.format(schema.table)
        self.journal_file_name = '{0}_journal.json'.format(schema.table)

    @property
    def all_keys(self):
        return [k.name for k in self.bucket.list(self.source) if
                not k.name.endswith('/')]

    @property
    def manifest_key(self):
        return normalize_path('{0}/{1}'.format(self.metadata, self.file_name))

    @property
    def journal_key(self):

        return normalize_path(