-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
5 changed files
with
50 additions
and
19 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
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 |
---|---|---|
|
@@ -5,34 +5,65 @@ | |
|
||
import os | ||
import re | ||
import subprocess | ||
|
||
|
||
def read(prompt, regex): | ||
def read(prompt, regex, default): | ||
""" | ||
Read a string from command line. | ||
The string has to match the given regular expression. | ||
""" | ||
if default: | ||
prompt += f" [{default}]" | ||
prompt += ": " | ||
|
||
while True: | ||
ret = input(prompt) | ||
if not ret and default: | ||
ret = default | ||
match = re.match(regex, ret) | ||
if match is not None: | ||
return ret | ||
print(f"the project name has to match the regular expression: {regex}") | ||
|
||
|
||
def git_config_get(attr): | ||
""" | ||
Get a git config value. | ||
""" | ||
try: | ||
return subprocess.check_output(["git", "config", "--get", attr]).decode().strip() | ||
except subprocess.CalledProcessError: | ||
return None | ||
|
||
def main(): | ||
""" | ||
Rename the project. | ||
""" | ||
project = read("project name: ", r"^[a-z][a-z0-9_]*$") | ||
author = read("author: ", r".+") | ||
email = read("email: ", r".+") | ||
|
||
author = git_config_get("user.name") | ||
email = git_config_get("user.email") | ||
origin = git_config_get("remote.origin.url") | ||
url, project = None, None | ||
|
||
if origin is not None: | ||
match = re.match(r"^.*[:/]([^:/]*)/([^/]*)(\.git)?$", origin) | ||
if match is not None: | ||
org, project = match.group(1), match.group(2) | ||
url = f"https://github.com/{org}/{project}/" | ||
project = project.replace("-", "_") | ||
|
||
project = read("project name", r"^[a-z][a-z0-9_]*$", project) | ||
author = read("author", r".+", author) | ||
email = read("email", r".+", email) | ||
url = read("url", r".+", url) | ||
|
||
replacements = { | ||
"fillname": project, | ||
"[email protected]": email, | ||
"Mister Fillname": author, | ||
"https://fillname.org/": url, | ||
"fillname": project, | ||
} | ||
|
||
def replace(filepath): | ||
|
@@ -48,8 +79,8 @@ def replace(filepath): | |
".pre-commit-config.yaml", | ||
"noxfile.py", | ||
"pyproject.toml", | ||
"setup.cfg", | ||
"CONTRIBUTING.md", | ||
"DEPLOYMENT.md", | ||
"DEVELOPMENT.md", | ||
"LICENSE", | ||
"README.md", | ||
|
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