<commit_before>import os
import os.path
from path import path

from pythonpackager.exceptions import CommandError
from pythonpackager.commands import Command

class CreateCommand(Command):
    name = "create"
    
    def __init__(self):
        super(CreateCommand, self).__init__()
        
        default_name = path(os.getcwd()).name.lower().replace("-", "")
        
        self.parser.add_option(
            '-n', '--name',
            dest='package_name',
            action='store',
            default=default_name,
            type='str',
            help='The package name. Will default to the current directory name, lower cased, and with dashes stripped.')
        
        self.parser.add_option(
            '-r', '--release',
            dest='version',
            action='store',
            default="0.1.0",
            type='str',
            help='The initial release version. Default is 0.1.0')
        
        self.parser.add_option(
            '-f', '--force',
            dest='force',
            action='store_true',
            default=False,
            help='Force creation even if current directory is not empty.')
        
        self.parser.add_option(
            '-d', '--dry-run',
            dest='dry_run',
            action='store_true',
            default=False,
            help="Don't actually create anything, just show what will be created")
    
    def run(self, options, args):
        project_dir = path(os.getcwd())
        package_name = options.package_name
        version = options.package_name
        
        self.dry_run = options.dry_run
        
        if not options.force and os.listdir(project_dir):
            raise CommandError("Project directory %s is not empty. Use -f for force.")
        
        self.create_dirs(project_dir, package_name)
        self.create_files(project_dir, package_name, version)
    
    def create_dirs(self, project_dir, package_name):
        dirs = [
            project_dir / "bin", 
            project_dir / "docs", 
            project_dir / package_name,
        ]
        
        for dir in dirs:
            if os.path.isdir(dir):
                continue
            elif os.path.exists(dir):
                raise CommandError("File %s exists and is not a directory" % dir)
            else:
                if self.dry_run:
                    print "Would have created directory %s" % dir
                else:
                    os.mkdir(dir, mode=0755)
    
    def create_files(self, project_dir, package_name, version):
        files = [
            (project_dir / "CHANGES.txt", TEMPLATE_CHANGES),
            (project_dir / "LICENSE.txt", TEMPLATE_LICENSE),
            (project_dir / "MANIFEST.in", TEMPLATE_MANIFEST),
            (project_dir / "README.rst", TEMPLATE_README),
            (project_dir / "setup.py", TEMPLATE_SETUP),
            (project_dir / package_name / "__init__.py", TEMPLATE_INIT),
        ]
        
        for file, template in files:
            if os.path.isfile(file):
                continue
            elif os.path.exists(file):
                raise CommandError("File %s exists and is not a regular file" % dir)
            else:
                content = template % {
                    "project_name": project_dir.name,
                    "package_name": package_name,
                    "version": version,
                }
                import pdb; pdb.set_trace();
                if self.dry_run:
                    print "Would have created file %s" % file
                else:
                    with os.open(file, os.O_WRONLY) as f:
                        f.write()
                    os.chmod(file, mode=0644)
        
        if not self.dry_run:
            os.chmod(project_dir / "setup.py", 0755)

CreateCommand()

TEMPLATE_CHANGES = """Change-log for %(project_name)s.

This file will be added to as part of each release

----
"""

TEMPLATE_LICENSE = """Put your license in this file"""

TEMPLATE_MANIFEST = """include *.txt
recursive-include docs *"""

TEMPLATE_README = """Auto generated readme file for %(project_name)s.

Put something informative here"""

TEMPLATE_SETUP = """from distutils.core import setup
from %(package_name)s import __version__

setup(
    name='%(project_name)s',
    version=__version__,
    # Your name & email here
    author='',
    author_email='',
    # If you had %(package_name)s.tests, you would also include that in this list
    packages=['%(package_name)s'],
    # Any executable scripts, typically in 'bin'. E.g 'bin/do-something.py'
    scripts=[],
    url='',
    license='LICENSE.txt',
    description='',
    long_description=open('README.rst').read(),
    # Any requirements here, e.g. "Django >= 1.1.1"
    install_requires=[
        
    ],
)
"""

TEMPLATE_INIT = """__version__ = '%(version)s'
"""<commit_msg>removing debug statement<commit_after>import os
import os.path
from path import path

from pythonpackager.exceptions import CommandError
from pythonpackager.commands import Command

class CreateCommand(Command):
    name = "create"
    
    def __init__(self):
        super(CreateCommand, self).__init__()
        
        default_name = path(os.getcwd()).name.lower().replace("-", "")
        
        self.parser.add_option(
            '-n', '--name',
            dest='package_name',
            action='store',
            default=default_name,
            type='str',
            help='The package name. Will default to the current directory name, lower cased, and with dashes stripped.')
        
        self.parser.add_option(
            '-r', '--release',
            dest='version',
            action='store',
            default="0.1.0",
            type='str',
            help='The initial release version. Default is 0.1.0')
        
        self.parser.add_option(
            '-f', '--force',
            dest='force',
            action='store_true',
            default=False,
            help='Force creation even if current directory is not empty.')
        
        self.parser.add_option(
            '-d', '--dry-run',
            dest='dry_run',
            action='store_true',
            default=False,
            help="Don't actually create anything, just show what will be created")
    
    def run(self, options, args):
        project_dir = path(os.getcwd())
        package_name = options.package_name
        version = options.package_name
        
        self.dry_run = options.dry_run
        
        if not options.force and os.listdir(project_dir):
            raise CommandError("Project directory %s is not empty. Use -f for force.")
        
        self.create_dirs(project_dir, package_name)
        self.create_files(project_dir, package_name, version)
    
    def create_dirs(self, project_dir, package_name):
        dirs = [
            project_dir / "bin", 
            project_dir / "docs", 
            project_dir / package_name,
        ]
        
        for dir in dirs:
            if os.path.isdir(dir):
                continue
            elif os.path.exists(dir):
                raise CommandError("File %s exists and is not a directory" % dir)
            else:
                if self.dry_run:
                    print "Would have created directory %s" % dir
                else:
                    os.mkdir(dir, mode=0755)
    
    def create_files(self, project_dir, package_name, version):
        files = [
            (project_dir / "CHANGES.txt", TEMPLATE_CHANGES),
            (project_dir / "LICENSE.txt", TEMPLATE_LICENSE),
            (project_dir / "MANIFEST.in", TEMPLATE_MANIFEST),
            (project_dir / "README.rst", TEMPLATE_README),
            (project_dir / "setup.py", TEMPLATE_SETUP),
            (project_dir / package_name / "__init__.py", TEMPLATE_INIT),
        ]
        
        for file, template in files:
            if os.path.isfile(file):
                continue
            elif os.path.exists(file):
                raise CommandError("File %s exists and is not a regular file" % dir)
            else:
                content = template % {
                    "project_name": project_dir.name,
                    "package_name": package_name,
                    "version": version,
                }
                
                if self.dry_run:
                    print "Would have created file %s" % file
                else:
                    with os.open(file, os.O_WRONLY) as f:
                        f.write()
                    os.chmod(file, mode=0644)
        
        if not self.dry_run:
            os.chmod(project_dir / "setup.py", 0755)

CreateCommand()

TEMPLATE_CHANGES = """Change-log for %(project_name)s.

This file will be added to as part of each release

----
"""

TEMPLATE_LICENSE = """Put your license in this file"""

TEMPLATE_MANIFEST = """include *.txt
recursive-include docs *"""

TEMPLATE_README = """Auto generated readme file for %(project_name)s.

Put something informative here"""

TEMPLATE_SETUP = """from distutils.core import setup
from %(package_name)s import __version__

setup(
    name='%(project_name)s',
    version=__version__,
    # Your name & email here
    author='',
    author_email='',
    # If you had %(package_name)s.tests, you would also include that in this list
    packages=['%(package_name)s'],
    # Any executable scripts, typically in 'bin'. E.g 'bin/do-something.py'
    scripts=[],
    url='',
    license='LICENSE.txt',
    description='',
    long_description=open('README.rst').read(),
    # Any requirements here, e.g. "Django >= 1.1.1"
    install_requires=[
        
    ],
)
"""

TEMPLATE_INIT = """__version__ = '%(version)s'
"""
{'fraction_non_alphanumeric': 0.11193798449612404, 'fraction_numerical': 0.004341085271317829, 'mean_word_length': 1.811156304474143, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2211066', 'n_tokens_mistral': 2826, 'n_tokens_neox': 2718, 'n_words': 689}