# Path: support/distribution/commercial.py
# GPL_NOTICE_LINENR = 19
# COMMERCIAL_LICENSE_NOTICE = """
# This is a release of MySQL Connector/Python, Oracle's dual-
# license Python Driver for MySQL. For the avoidance of
# doubt, this particular copy of the software is released
# under a commercial license and the GNU General Public
# License does not apply. MySQL Connector/Python is brought
# to you by Oracle.
# 
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
# 
# This distribution may include materials developed by third
# parties. For license and attribution notices for these
# materials, please refer to the documentation that accompanies
# this distribution (see the "Licenses for Third-Party Components"
# appendix) or view the online documentation at 
# <http://dev.mysql.com/doc/>
# """
# COMMERCIAL_SETUP_PY = """#!/usr/bin/env python
# # -*- coding: utf-8 -*-
# # MySQL Connector/Python - MySQL driver written in Python.
# # Copyright (c) 2012, %d, Oracle and/or its affiliates. All rights reserved.
# 
# import os
# from distutils.core import setup
# from distutils.command.build import build
# from distutils.dir_util import copy_tree
# 
# class Build(build):
#     def run(self):
#         copy_tree('mysql', os.path.join(self.build_lib, 'mysql'))
# 
# LONG_DESCRIPTION = \"\"\"
# {long_description}
# \"\"\"
# 
# setup(
#     name = '{name}',
#     version = '{version}',
#     description = '{description}',
#     long_description = LONG_DESCRIPTION,
#     author = '{author}',
#     author_email = '{author_email}',
#     license = '{license}',
#     keywords = '{keywords}',
#     url = '{url}',
#     download_url = '{download_url}',
#     package_dir = {{ '': '' }},
#     packages = ['mysql', 'mysql.connector',
#        'mysql.connector.locales', 'mysql.connector.locales.eng'],
#     classifiers = {classifiers},
#     cmdclass = {{
#         'build': Build,
#     }}
# )
# 
# """ % (date.today().year)
# def remove_gpl(pyfile, dry_run=0):


import os
import time
import re
import tempfile
import filecmp
import difflib
import support.tests
from datetime import datetime
from distutils.errors import DistutilsError
from support.distribution import commercial
        for base, dirs, files in os.walk(django_dir):
            for file_ in files:
                if file_.endswith('.py'):
                    pyfile = os.path.join(base, file_)
                    if os.path.getsize(pyfile) > 10:
                        self._check_copyright_absence(pyfile)
                        self._check_gpl_absence(pyfile)


class DebianTests(support.tests.SupportTests):
    """Test Debian packaging"""
    def test_changelog_version(self):
        ver = self.get_connector_version(no_suffix=True)
        debian_folders = ['commercial', 'gpl']
        for debian_folder in debian_folders:
            changelog = os.path.join('support', 'Debian', debian_folder,
                                     'changelog')
            content = open(changelog, 'r').read()
            self.assertTrue(ver in content,
                            "Version %s not found in %s" % (ver, changelog))

        
class CommercialTests(support.tests.SupportTests):
    """Test functionality regarding commercial releases"""
    def test_remove_gpl(self):
        pyfile = 'python2/mysql/connector/connection.py'

        # Succesfully remove GPL
        tmpfile = tempfile.NamedTemporaryFile(mode='w+')
        tmpfile.write(open(pyfile, 'r').read())

# Path: support/distribution/commercial.py
# GPL_NOTICE_LINENR = 19
# COMMERCIAL_LICENSE_NOTICE = """
# This is a release of MySQL Connector/Python, Oracle's dual-
# license Python Driver for MySQL. For the avoidance of
# doubt, this particular copy of the software is released
# under a commercial license and the GNU General Public
# License does not apply. MySQL Connector/Python is brought
# to you by Oracle.
# 
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
# 
# This distribution may include materials developed by third
# parties. For license and attribution notices for these
# materials, please refer to the documentation that accompanies
# this distribution (see the "Licenses for Third-Party Components"
# appendix) or view the online documentation at 
# <http://dev.mysql.com/doc/>
# """
# COMMERCIAL_SETUP_PY = """#!/usr/bin/env python
# # -*- coding: utf-8 -*-
# # MySQL Connector/Python - MySQL driver written in Python.
# # Copyright (c) 2012, %d, Oracle and/or its affiliates. All rights reserved.
# 
# import os
# from distutils.core import setup
# from distutils.command.build import build
# from distutils.dir_util import copy_tree
# 
# class Build(build):
#     def run(self):
#         copy_tree('mysql', os.path.join(self.build_lib, 'mysql'))
# 
# LONG_DESCRIPTION = \"\"\"
# {long_description}
# \"\"\"
# 
# setup(
#     name = '{name}',
#     version = '{version}',
#     description = '{description}',
#     long_description = LONG_DESCRIPTION,
#     author = '{author}',
#     author_email = '{author_email}',
#     license = '{license}',
#     keywords = '{keywords}',
#     url = '{url}',
#     download_url = '{download_url}',
#     package_dir = {{ '': '' }},
#     packages = ['mysql', 'mysql.connector',
#        'mysql.connector.locales', 'mysql.connector.locales.eng'],
#     classifiers = {classifiers},
#     cmdclass = {{
#         'build': Build,
#     }}
# )
# 
# """ % (date.today().year)
# def remove_gpl(pyfile, dry_run=0):


# Path: support/tests/test_distribution.py
import os
import time
import re
import tempfile
import filecmp
import difflib
import support.tests
from datetime import datetime
from distutils.errors import DistutilsError
from support.distribution import commercial

        for base, dirs, files in os.walk(django_dir):
            for file_ in files:
                if file_.endswith('.py'):
                    pyfile = os.path.join(base, file_)
                    if os.path.getsize(pyfile) > 10:
                        self._check_copyright_absence(pyfile)
                        self._check_gpl_absence(pyfile)


class DebianTests(support.tests.SupportTests):
    """Test Debian packaging"""
    def test_changelog_version(self):
        ver = self.get_connector_version(no_suffix=True)
        debian_folders = ['commercial', 'gpl']
        for debian_folder in debian_folders:
            changelog = os.path.join('support', 'Debian', debian_folder,
                                     'changelog')
            content = open(changelog, 'r').read()
            self.assertTrue(ver in content,
                            "Version %s not found in %s" % (ver, changelog))

        
class CommercialTests(support.tests.SupportTests):
    """Test functionality regarding commercial releases"""
    def test_remove_gpl(self):
        pyfile = 'python2/mysql/connector/connection.py'

        # Succesfully remove GPL
        tmpfile = tempfile.NamedTemporaryFile(mode='w+')
        tmpfile.write(open(pyfile, 'r').read())

        commercial.remove_gpl(tmpfile.name)