(self, app_or_project, name, target=None, **options)
| 86 | ) |
| 87 | |
| 88 | def handle(self, app_or_project, name, target=None, **options): |
| 89 | self.app_or_project = app_or_project |
| 90 | self.a_or_an = "an" if app_or_project == "app" else "a" |
| 91 | self.paths_to_remove = [] |
| 92 | self.verbosity = options["verbosity"] |
| 93 | |
| 94 | self.validate_name(name) |
| 95 | |
| 96 | # if some directory is given, make sure it's nicely expanded |
| 97 | if target is None: |
| 98 | top_dir = os.path.join(os.getcwd(), name) |
| 99 | try: |
| 100 | os.makedirs(top_dir) |
| 101 | except FileExistsError: |
| 102 | raise CommandError("'%s' already exists" % top_dir) |
| 103 | except OSError as e: |
| 104 | raise CommandError(e) |
| 105 | else: |
| 106 | top_dir = os.path.abspath(os.path.expanduser(target)) |
| 107 | if app_or_project == "app": |
| 108 | self.validate_name(os.path.basename(top_dir), "directory") |
| 109 | if not os.path.exists(top_dir): |
| 110 | try: |
| 111 | os.makedirs(top_dir) |
| 112 | except OSError as e: |
| 113 | raise CommandError(e) |
| 114 | |
| 115 | # Find formatters, which are external executables, before input |
| 116 | # from the templates can sneak into the path. |
| 117 | formatter_paths = find_formatters() |
| 118 | |
| 119 | extensions = tuple(handle_extensions(options["extensions"])) |
| 120 | extra_files = [] |
| 121 | excluded_directories = [".git", "__pycache__"] |
| 122 | for file in options["files"]: |
| 123 | extra_files.extend(map(lambda x: x.strip(), file.split(","))) |
| 124 | if exclude := options.get("exclude"): |
| 125 | for directory in exclude: |
| 126 | excluded_directories.append(directory.strip()) |
| 127 | if self.verbosity >= 2: |
| 128 | self.stdout.write( |
| 129 | "Rendering %s template files with extensions: %s" |
| 130 | % (app_or_project, ", ".join(extensions)) |
| 131 | ) |
| 132 | self.stdout.write( |
| 133 | "Rendering %s template files with filenames: %s" |
| 134 | % (app_or_project, ", ".join(extra_files)) |
| 135 | ) |
| 136 | base_name = "%s_name" % app_or_project |
| 137 | base_subdir = "%s_template" % app_or_project |
| 138 | base_directory = "%s_directory" % app_or_project |
| 139 | camel_case_name = "camel_case_%s_name" % app_or_project |
| 140 | camel_case_value = "".join(x for x in name.title() if x != "_") |
| 141 | |
| 142 | context = Context( |
| 143 | { |
| 144 | **options, |
| 145 | base_name: name, |
nothing calls this directly
no test coverage detected