-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yamldirs command to create yaml file from directory and directory fro…
…m yaml.
- Loading branch information
Showing
5 changed files
with
50 additions
and
5 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,6 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__version__ = '1.1.6' | ||
__version__ = '1.1.7' | ||
|
||
from .filemaker import create_files | ||
|
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import sys | ||
|
||
import yaml | ||
from .filemaker import Filemaker | ||
|
||
|
||
def tree(root): | ||
def _tree(): | ||
for rt, dirs, files in os.walk(root): | ||
for name in files: | ||
if name.endswith('~'): continue | ||
if name.startswith('.'): continue | ||
yield os.path.join(rt, name) | ||
return list(sorted(_tree())) | ||
|
||
|
||
def directory2yaml(dirname): | ||
res = {} | ||
for filename in tree(dirname): | ||
parts = filename.replace('\\', '/').split('/') | ||
cur = res | ||
for part in parts[:-1]: | ||
cur.setdefault(part, {}) | ||
cur = cur[part] | ||
cur[parts[-1]] = open(filename).read().replace('\r\n', '\n').strip() | ||
print yaml.dump(res) | ||
|
||
|
||
def reconstitute_directory(yamlfile): | ||
Filemaker(os.getcwd(), open(yamlfile).read()) | ||
|
||
|
||
def main(): | ||
arg = sys.argv[1] | ||
if arg.endswith('.yaml'): | ||
reconstitute_directory(arg) | ||
else: | ||
directory2yaml(arg) |