Organize directories

This commit is contained in:
Darren Clarke 2023-02-13 13:10:48 +00:00
parent 8a91c9b89b
commit 4898382f78
433 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,46 @@
#!/usr/bin/env python3
import pathlib
import os
import json
import glob
import inflection
from datetime import datetime
from collections import OrderedDict
migration_template = """class {} < ActiveRecord::Migration[5.2]
def self.up
# add your code here
end
def self.down
# add your code here
end
end
"""
def load_skeleton():
t = glob.glob('*.szpm.template')
if len(t) != 1:
raise Exception("Cannot find szpm template")
with open(t[0], 'r', encoding='utf-8') as f:
skeleton = json.load(f, object_pairs_hook=OrderedDict)
return skeleton
def main():
skeleton = load_skeleton()
name = skeleton["name"].lower()
raw_name = input("Enter migration name (no spaces, no symbols!): ")
migration_base_name = "{}_{}".format(name, inflection.underscore(raw_name))
migration_name = inflection.camelize(migration_base_name, uppercase_first_letter=True)
contents = migration_template.format(migration_name)
time = datetime.utcnow().strftime("%Y%m%d%H%M%S")
migration_file_name = "{}_{}.rb".format(time, migration_base_name)
dir_path = os.path.join("src/db/addon", name)
pathlib.Path(dir_path).mkdir(parents=True, exist_ok=True)
with open(os.path.join(dir_path, migration_file_name), 'w') as f:
f.write(contents)
main()