# Path: lib/cuckoo/common/config.py
# class Config:
#     """Configuration file parser."""
# 
#     def __init__(self, file_name="cuckoo", cfg=None):
#         """
#         @param file_name: file name without extension.
#         @param cfg: configuration file path.
#         """
#         config = ConfigParser.ConfigParser()
# 
#         if cfg:
#             config.read(cfg)
#         else:
#             config.read(os.path.join(CUCKOO_ROOT, "conf", "%s.conf" % file_name))
# 
#         for section in config.sections():
#             setattr(self, section, Dictionary())
#             for name, raw_value in config.items(section):
#                 try:
#                     # Ugly fix to avoid '0' and '1' to be parsed as a
#                     # boolean value.
#                     # We raise an exception to goto fail^w parse it
#                     # as integer.
#                     if config.get(section, name) in ["0", "1"]:
#                         raise ValueError
# 
#                     value = config.getboolean(section, name)
#                 except ValueError:
#                     try:
#                         value = config.getint(section, name)
#                     except ValueError:
#                         value = config.get(section, name)
# 
#                 setattr(getattr(self, section), name, value)
# 
#     def get(self, section):
#         """Get option.
#         @param section: section to fetch.
#         @raise CuckooOperationalError: if section not found.
#         @return: option value.
#         """
#         try:
#             return getattr(self, section)
#         except AttributeError as e:
#             raise CuckooOperationalError("Option %s is not found in "
#                                          "configuration, error: %s" %
#                                          (section, e))


import os
import sys
import sqlalchemy as sa
import lib.cuckoo.core.database as db
from datetime import datetime
    from dateutil.parser import parse
    from alembic import op
    from pymongo.connection import Connection
    from pymongo.errors import ConnectionFailure
from lib.cuckoo.common.config import Config
                sa.Column("id", sa.Integer(), nullable=False),
                sa.Column("target", sa.String(length=255), nullable=False),
                sa.Column("category", sa.String(length=255), nullable=False),
                sa.Column("timeout", sa.Integer(), server_default="0", nullable=False),
                sa.Column("priority", sa.Integer(), server_default="1", nullable=False),
                sa.Column("custom", sa.String(length=255), nullable=True),
                sa.Column("machine", sa.String(length=255), nullable=True),
                sa.Column("package", sa.String(length=255), nullable=True),
                sa.Column("options", sa.String(length=255), nullable=True),
                sa.Column("platform", sa.String(length=255), nullable=True),
                sa.Column("memory", sa.Boolean(), nullable=False, default=False),
                sa.Column("enforce_timeout", sa.Boolean(), nullable=False, default=False),
                sa.Column("clock", sa.DateTime(timezone=False), server_default=sa.func.now(), nullable=False),
                sa.Column("added_on", sa.DateTime(timezone=False), nullable=False),
                sa.Column("started_on", sa.DateTime(timezone=False), nullable=True),
                sa.Column("completed_on", sa.DateTime(timezone=False), nullable=True),
                sa.Column("status", sa.Enum("pending", "running", "completed", "reported", "recovered", name="status_type"), server_default="pending", nullable=False),
                sa.Column("sample_id", sa.Integer, sa.ForeignKey("samples.id"), nullable=True),
                sa.PrimaryKeyConstraint("id")
            )

            # Insert data.
            op.bulk_insert(db.Task.__table__, tasks_data)

    # Migrate mongo.
    mongo_upgrade()

def mongo_upgrade():
    """Migrate mongodb schema and data."""
    # Read reporting.conf to fetch mongo configuration.

# Path: lib/cuckoo/common/config.py
# class Config:
#     """Configuration file parser."""
# 
#     def __init__(self, file_name="cuckoo", cfg=None):
#         """
#         @param file_name: file name without extension.
#         @param cfg: configuration file path.
#         """
#         config = ConfigParser.ConfigParser()
# 
#         if cfg:
#             config.read(cfg)
#         else:
#             config.read(os.path.join(CUCKOO_ROOT, "conf", "%s.conf" % file_name))
# 
#         for section in config.sections():
#             setattr(self, section, Dictionary())
#             for name, raw_value in config.items(section):
#                 try:
#                     # Ugly fix to avoid '0' and '1' to be parsed as a
#                     # boolean value.
#                     # We raise an exception to goto fail^w parse it
#                     # as integer.
#                     if config.get(section, name) in ["0", "1"]:
#                         raise ValueError
# 
#                     value = config.getboolean(section, name)
#                 except ValueError:
#                     try:
#                         value = config.getint(section, name)
#                     except ValueError:
#                         value = config.get(section, name)
# 
#                 setattr(getattr(self, section), name, value)
# 
#     def get(self, section):
#         """Get option.
#         @param section: section to fetch.
#         @raise CuckooOperationalError: if section not found.
#         @return: option value.
#         """
#         try:
#             return getattr(self, section)
#         except AttributeError as e:
#             raise CuckooOperationalError("Option %s is not found in "
#                                          "configuration, error: %s" %
#                                          (section, e))


# Path: utils/db_migration/versions/from_0_6_to_1_1.py
import os
import sys
import sqlalchemy as sa
import lib.cuckoo.core.database as db
from datetime import datetime
    from dateutil.parser import parse
    from alembic import op
    from pymongo.connection import Connection
    from pymongo.errors import ConnectionFailure
from lib.cuckoo.common.config import Config

                sa.Column("id", sa.Integer(), nullable=False),
                sa.Column("target", sa.String(length=255), nullable=False),
                sa.Column("category", sa.String(length=255), nullable=False),
                sa.Column("timeout", sa.Integer(), server_default="0", nullable=False),
                sa.Column("priority", sa.Integer(), server_default="1", nullable=False),
                sa.Column("custom", sa.String(length=255), nullable=True),
                sa.Column("machine", sa.String(length=255), nullable=True),
                sa.Column("package", sa.String(length=255), nullable=True),
                sa.Column("options", sa.String(length=255), nullable=True),
                sa.Column("platform", sa.String(length=255), nullable=True),
                sa.Column("memory", sa.Boolean(), nullable=False, default=False),
                sa.Column("enforce_timeout", sa.Boolean(), nullable=False, default=False),
                sa.Column("clock", sa.DateTime(timezone=False), server_default=sa.func.now(), nullable=False),
                sa.Column("added_on", sa.DateTime(timezone=False), nullable=False),
                sa.Column("started_on", sa.DateTime(timezone=False), nullable=True),
                sa.Column("completed_on", sa.DateTime(timezone=False), nullable=True),
                sa.Column("status", sa.Enum("pending", "running", "completed", "reported", "recovered", name="status_type"), server_default="pending", nullable=False),
                sa.Column("sample_id", sa.Integer, sa.ForeignKey("samples.id"), nullable=True),
                sa.PrimaryKeyConstraint("id")
            )

            # Insert data.
            op.bulk_insert(db.Task.__table__, tasks_data)

    # Migrate mongo.
    mongo_upgrade()

def mongo_upgrade():
    """Migrate mongodb schema and data."""
    # Read reporting.conf to fetch mongo configuration.

    config = Config(cfg=os.path.join("..", "..", "conf", "reporting.conf"))