Created
December 9, 2018 23:35
-
-
Save kieranjol/4da424cc9f854723db7aee3c4618603c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
''' | |
pymm is a python port of mediamicroservices | |
(https://github.com/mediamicroservices/mm) | |
run `pymmconfig` once at setup to initialize config settings | |
or run it again to change or add values | |
''' | |
import os | |
import sys | |
import inspect | |
import ConfigParser | |
def make_config(configPath): | |
if not os.path.isfile(configPath): | |
print('theres no system config file yet... hang on...') | |
with open(configPath,'w+') as config: | |
config.write('''[paths]\noutdir_ingestsip:\naip_staging:\nresourcespace_deliver:\nprores_deliver:\ | |
\n\n[deriv delivery options]\nresourcespace: n\nproresHQ: n\ | |
\n\n[database settings]\nuse_db:\npymm_db:\npymm_db_access:\npymm_db_address:\ | |
\n\n[database users]\nuser: password\ | |
\n\n[logging]\npymm_log_dir:\ | |
\n\n[mediaconch format policies]\nfilm_scan_master:\nvideo_capture_master:\nmagnetic_video_mezzanine:\nfilm_scan_mezzanine:\nlow_res_proxy:\ | |
\n\n[ffmpeg]\nresourcespace_video_opts:["a","b","c"]\nproresHQ_opts:["a","b","c"]\nresourcespace_audio_opts:["a","b","c"] | |
\n\n[bwf constants]\noriginator:\ncoding_history_ANALOG:\ | |
''') | |
def set_value(section, optionToSet,newValue=None): | |
# import pymmFunctions here to use get_system.... | |
# can't import it at top since it makes a circular dependency problem (i.e. if config.ini doesn't exist yet you can't use pymmFunctions) | |
# https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder | |
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) | |
parentdir = os.path.dirname(currentdir) | |
sys.path.insert(0,parentdir) | |
import pymmFunctions | |
if newValue == None: | |
print("So you want to set "+optionToSet) | |
# the replace() call is a kind of stupid hack fix to get around paths with spaces getting an unnecessary escape slash | |
# when you drag a folder into the terminal on Mac.... | |
# @fixme | |
# should add mac functionality to sanitize func.... | |
newValue = input("Please enter a value for "+optionToSet+": ").rstrip().replace("\ "," ") | |
newValue = pymmFunctions.sanitize_dragged_linux_path(newValue) | |
config.set(section,optionToSet,newValue) | |
with open(configPath,'w') as out: | |
config.write(out) | |
def add_db_credentials(): | |
print( | |
"WARNING: This is only for use when the database " | |
"and the user are on the same machine. \n" | |
"You must also create the user with these credentials using \n" | |
"`python3 createPymmDB -m user`." | |
) | |
username = input("Enter the username: ") | |
password = input("Enter the password for the user: ") | |
set_value('database users',username,password) | |
def select_option(): | |
more = '' | |
optionToSet = input("Enter the configuration option you want to set " | |
"OR type 'db' to add credentials for a database user: ") | |
if optionToSet in ('db','DB'): | |
add_db_credentials() | |
more = input("Type 'q' to quit or hit enter to choose another option to set: ") | |
ask_more(more) | |
else: | |
matchingSections = 0 | |
for section in config.sections(): | |
if config.has_option(section,optionToSet): | |
matchingSection = section | |
matchingSections += 1 | |
set_value(section,optionToSet) | |
else: | |
pass | |
if matchingSections == 0: | |
print("\nOops, there is no option matching "+optionToSet+". Check your spelling and try again.\n") | |
more = input("Type 'q' to quit or hit enter to select another option to set: ") | |
ask_more(more) | |
def ask_more(more): | |
if more == 'q': | |
with open(configPath, 'r+') as conf: | |
print('THIS IS WHAT THE CONFIG FILE LOOKS LIKE NOW.') | |
for line in conf.readlines(): | |
print(line.rstrip()) | |
print("NOW EXITING. BYE!!") | |
sys.exit() | |
else: | |
select_option() | |
configPath = os.path.join(os.path.dirname(os.path.abspath(__file__)),'config.ini') | |
# configPath = 'config.ini' | |
make_config(configPath) | |
config = ConfigParser.SafeConfigParser() | |
config.read(configPath) | |
def main(): | |
with open(configPath, 'r+') as conf: | |
print('THIS IS WHAT THE CONFIG FILE LOOKS LIKE NOW.') | |
for line in conf.readlines(): | |
print(line.rstrip()) | |
print("IF YOU WANT TO CHANGE ANYTHING, LET'S GO!!") | |
select_option() | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment