latest version stuff
This commit is contained in:
parent
a689ba1758
commit
749c140a16
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "notesync"
|
name = "notesync"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = [
|
authors = [
|
||||||
{name = "James Ravenscroft", email = "ravenscroftj@gmail.com"},
|
{name = "James Ravenscroft", email = "ravenscroftj@gmail.com"},
|
||||||
|
|
|
@ -1,18 +1,34 @@
|
||||||
|
from unittest import skip
|
||||||
import frontmatter
|
import frontmatter
|
||||||
import click
|
import click
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
import shutil
|
import shutil
|
||||||
|
import fnmatch
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--input-dir", "-i", required=True)
|
@click.option("--input-dir", "-i", required=True)
|
||||||
@click.option('--output-dir','-o', required=True)
|
@click.option('--output-dir','-o', required=True)
|
||||||
def main(input_dir: str, output_dir):
|
@click.option('--ignore', default=None, required=False, multiple=True)
|
||||||
|
@click.option('--dry-run/--no-dry-run', default=False)
|
||||||
|
def main(input_dir: str, output_dir, ignore=None, dry_run=False):
|
||||||
|
|
||||||
public_files = []
|
public_files = []
|
||||||
|
|
||||||
for file in glob.glob(os.path.join(input_dir,"**","*.md")):
|
for file in glob.glob(os.path.join(input_dir,"**","*.md")):
|
||||||
|
|
||||||
|
|
||||||
|
if ignore is not None:
|
||||||
|
skip_file = False
|
||||||
|
|
||||||
|
for pattern in ignore:
|
||||||
|
if fnmatch.fnmatch(file, pattern):
|
||||||
|
skip_file = True
|
||||||
|
|
||||||
|
if skip_file:
|
||||||
|
continue
|
||||||
|
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
data = frontmatter.load(f)
|
data = frontmatter.load(f)
|
||||||
|
|
||||||
|
@ -20,16 +36,20 @@ def main(input_dir: str, output_dir):
|
||||||
print(f"public file {file}")
|
print(f"public file {file}")
|
||||||
public_files.append(file)
|
public_files.append(file)
|
||||||
|
|
||||||
|
|
||||||
for file in public_files:
|
for file in public_files:
|
||||||
path = file[len(input_dir):]
|
path = file[len(input_dir):]
|
||||||
out_path = os.path.join(os.path.abspath(output_dir), path)
|
out_path = os.path.join(os.path.abspath(output_dir), path)
|
||||||
|
|
||||||
if not os.path.exists(os.path.dirname(out_path)):
|
if not os.path.exists(os.path.dirname(out_path)):
|
||||||
print(f"mkdir {os.path.dirname(out_path)}")
|
print(f"mkdir {os.path.dirname(out_path)}")
|
||||||
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
|
||||||
|
|
||||||
shutil.copy(file, out_path)
|
if not dry_run:
|
||||||
|
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
||||||
|
|
||||||
|
print(f"{file} => {out_path}")
|
||||||
|
if not dry_run:
|
||||||
|
shutil.copy(file, out_path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue