Skip to content

Commit

Permalink
Made ready for pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
prchristie committed Mar 10, 2020
1 parent f1931a8 commit 0b68a79
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.egg*
__pycache__
.vscode
Empty file added LICENCE.txt
Empty file.
Empty file added README.md
Empty file.
65 changes: 52 additions & 13 deletions mdtemplater/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,83 @@ def make_dirs_to(filename):
if not os.path.exists(os.path.dirname(filename)):
try:
os.makedirs(os.path.dirname(filename))
except OSError as exc: # Guard against race condition
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise


def _write_header(file, size, header):
for _ in range(size):
file.write("#")
file.write(" " + header)
file.write("\n")


def write_link(file, link, link_text):
file.write("[" + link_text + "]")
file.write("(" + link + ")")
file.write("\n")


def write_title(file, title):
_write_header(file, 1, title)


def write_table_of_contents(file):
file.write("[TOC]\n")


def write_terms_header(file):
_write_header(file, 2, "Terms")


def md_template(filename, title, link=None):
with open(filename, "a+") as f:
if os.stat(filename).st_size != 0:
print(filename + " is not empty. Skipping")
return
write_title(f, title)
write_table_of_contents(f)
if link:
write_link(f, link, "Corresponding material")

f.write("\n\n\n\n")
write_terms_header(f)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--filename", metavar="", dest="filename", required=True, type=str, help="Name and path of the file. Generally add the .md suffix. Required")
parser.add_argument("-t", "--title", metavar="", dest="title", required=True, type=str, help="Title used for the file. Required")
parser.add_argument("-l", "--link", metavar="", dest="link", type=str, help="The link to the corresponding material")
parser.add_argument(
"-f",
"--filename",
metavar="",
dest="filename",
required=True,
type=str,
help="Name and path of the file. Generally add the .md suffix. Required",
)
parser.add_argument(
"-t",
"--title",
metavar="",
dest="title",
required=True,
type=str,
help="Title used for the file. Required",
)
parser.add_argument(
"-l",
"--link",
metavar="",
dest="link",
type=str,
help="The link to the corresponding material",
)

args = parser.parse_args()

make_dirs_to(args.filename)
with open(args.filename, "a+") as f:
write_title(f, args.title)
write_table_of_contents(f)
if args.link:
write_link(f, args.link, "Corresponding material")


md_template(args.filename, args.title, args.link)


if __name__ == "__main__":
main()
main()
Empty file added setup.cfg
Empty file.
15 changes: 8 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

setuptools.setup(
name="mdtemplater",
version="0.0.1",
version="0.1",
licence="MIT",
description="Creates a markdown file for note taking",
author="CoolDudde4150",
url="https://github.com/CoolDudde4150/mdtemplater",
download_url="https://github.com/CoolDudde4150/mdtemplater/archive/v_01.tar.gz",
packages=setuptools.find_packages(),
entry_points={
"console_scripts": [
"templater = mdtemplater.templater:main"
]
}
)
entry_points={"console_scripts": ["mdtemplater = mdtemplater.templater:main"]},
)

0 comments on commit 0b68a79

Please sign in to comment.