-
-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a82d09e
commit 3c9e809
Showing
3 changed files
with
87 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,58 @@ | ||
# Copyright (C) Ivan Kravets <[email protected]> | ||
# See LICENSE for details. | ||
|
||
from os import makedirs | ||
from os import getcwd, makedirs | ||
from os.path import isdir, isfile, join | ||
from shutil import copyfile | ||
|
||
from click import command, secho | ||
import click | ||
|
||
from platformio.exception import ProjectInitialized | ||
from platformio.util import get_source_dir | ||
|
||
|
||
@command("init", short_help="Initialize new PlatformIO based project") | ||
def cli(): | ||
@click.command("init", short_help="Initialize new PlatformIO based project") | ||
@click.option("--project-dir", "-d", default=getcwd(), | ||
type=click.Path(exists=True, file_okay=False, dir_okay=True, | ||
writable=True, resolve_path=True)) | ||
def cli(project_dir): | ||
|
||
if isfile("platformio.ini") and isdir("src"): | ||
project_file = join(project_dir, "platformio.ini") | ||
src_dir = join(project_dir, "src") | ||
lib_dir = join(project_dir, "lib") | ||
if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): | ||
raise ProjectInitialized() | ||
for d in ("lib", "src"): | ||
if not isdir(d): | ||
makedirs(d) | ||
if not isfile("platformio.ini"): | ||
copyfile(join(get_source_dir(), "projectconftpl.ini"), | ||
"platformio.ini") | ||
secho("Project has been initialized!\n" | ||
"Please put your source code to `src` directory, " | ||
"external libraries to `lib` and " | ||
"setup environments in `platformio.ini` file.\n" | ||
"Then process project with `platformio run` command.", | ||
fg="green") | ||
|
||
if project_dir == getcwd(): | ||
click.secho("The current working directory", fg="yellow", nl=False) | ||
click.secho(" %s " % project_dir, fg="blue", nl=False) | ||
click.secho( | ||
"will be used for the new project.\n" | ||
"You can specify another project directory via\n" | ||
"`platformio init -d %PATH_TO_PROJECT_DIR%` command.\n", | ||
fg="yellow" | ||
) | ||
|
||
click.echo("The next files/directories will be created in %s" % | ||
click.style(project_dir, fg="blue")) | ||
click.echo("%s - Project Configuration File" % | ||
click.style("platformio.ini", fg="cyan")) | ||
click.echo("%s - a source directory. Put your source code here" % | ||
click.style("src", fg="cyan")) | ||
click.echo("%s - a directory for the project specific libraries" % | ||
click.style("lib", fg="cyan")) | ||
|
||
if click.confirm("Do you want to continue?"): | ||
for d in (src_dir, lib_dir): | ||
if not isdir(d): | ||
makedirs(d) | ||
if not isfile(project_file): | ||
copyfile(join(get_source_dir(), "projectconftpl.ini"), | ||
project_file) | ||
click.secho( | ||
"Project has been successfully initialized!\n" | ||
"Now you can process it with `platformio run` command.", | ||
fg="green" | ||
) | ||
else: | ||
click.secho("Aborted by user", fg="red") |