<commit_before>import os
import sys
from imp import find_module
from django.core.management.base import CommandError, AppCommand, _make_writeable
from optparse import make_option

class Command(AppCommand):
    option_list = AppCommand.option_list + (
    )

    help = ("Creates a Django jobs command directory structure for the given app name"
            " in the current directory.")
    args = "[appname]"
    label = 'application name'

    requires_model_validation = False
    # Can't import settings during this command, because they haven't
    # necessarily been created.
    can_import_settings = True

    def handle_app(self, app, **options):
        parts = app.__name__.split('.')[0:-1]
        parts.reverse()
        app_dir = None
        original_parts = list(parts)
        paths = list(sys.path)
        while parts:
            part = parts.pop()
            
            # A part may be missing if namespace packages are being used.
            # Try to import, and if it fails, boot the whole failing app_dir out 
            # of our path search list. Reraise the import error if we run out of
            # paths to try.
            try:
                f, app_dir, descr = find_module(part, app_dir and [app_dir] or paths)
            except ImportError:
                paths = [p for p in paths if not app_dir.startswith(p)]
                if not paths:
                    raise
                app_dir = None
                parts = list(original_parts)
        
        if not os.path.exists(app_dir):
            try:
                os.mkdir(app_dir)
            except OSError, e:
                raise CommandError(e)
        
        copy_template('jobs_template', app_dir)
            
def copy_template(template_name, copy_to):
    """copies the specified template directory to the copy_to location"""
    import django_extensions
    import re
    import shutil
    
    template_dir = os.path.join(django_extensions.__path__[0], 'conf', template_name)

    # walks the template structure and copies it
    for d, subdirs, files in os.walk(template_dir):
        relative_dir = d[len(template_dir)+1:]
        if relative_dir and not os.path.exists(os.path.join(copy_to, relative_dir)):
            os.mkdir(os.path.join(copy_to, relative_dir))
        for i, subdir in enumerate(subdirs):
            if subdir.startswith('.'):
                del subdirs[i]
        for f in files:
            if f.endswith('.pyc') or f.startswith('.DS_Store'):
                continue
            path_old = os.path.join(d, f)
            path_new = os.path.join(copy_to, relative_dir, f)
            if os.path.exists(path_new):
                path_new = os.path.join(copy_to, relative_dir, f)
                if os.path.exists(path_new):
                    continue<commit_msg>applied justin's patch for issue 47<commit_after>import os
import sys
from django.core.management.base import CommandError, AppCommand, _make_writeable

class Command(AppCommand):
    help = ("Creates a Django jobs command directory structure for the given app name in the current directory.")
    args = "[appname]"
    label = 'application name'

    requires_model_validation = False
    # Can't import settings during this command, because they haven't
    # necessarily been created.
    can_import_settings = True

    def handle_app(self, app, **options):
        app_dir = os.path.dirname(app.__file__)
        copy_template('jobs_template', app_dir)

def copy_template(template_name, copy_to):
    """copies the specified template directory to the copy_to location"""
    import django_extensions
    import re
    import shutil
    
    template_dir = os.path.join(django_extensions.__path__[0], 'conf', template_name)

    # walks the template structure and copies it
    for d, subdirs, files in os.walk(template_dir):
        relative_dir = d[len(template_dir)+1:]
        if relative_dir and not os.path.exists(os.path.join(copy_to, relative_dir)):
            os.mkdir(os.path.join(copy_to, relative_dir))
        for i, subdir in enumerate(subdirs):
            if subdir.startswith('.'):
                del subdirs[i]
        for f in files:
            if f.endswith('.pyc') or f.startswith('.DS_Store'):
                continue
            path_old = os.path.join(d, f)
            path_new = os.path.join(copy_to, relative_dir, f)
            if os.path.exists(path_new):
                path_new = os.path.join(copy_to, relative_dir, f)
                if os.path.exists(path_new):
                    continue
{'fraction_non_alphanumeric': 0.08736795774647887, 'fraction_numerical': 0.0017605633802816902, 'mean_word_length': 2.230277185501066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7584609', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1270, 'n_words': 379}