58 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
### create new initial database
 | 
						|
from    schema import User, State, Production_Line, Order,Action, db, orm
 | 
						|
import  datetime
 | 
						|
 | 
						|
def get_state () :
 | 
						|
    state = State.get ()
 | 
						|
    if not state :
 | 
						|
        state = State \
 | 
						|
            ( imos_export_dir = "?"
 | 
						|
            , pgiq_import_dir = "?"
 | 
						|
            , last_directory_scan = datetime.datetime.fromtimestamp (0)
 | 
						|
            )
 | 
						|
    return state
 | 
						|
# end def get_state
 | 
						|
 | 
						|
if __name__ == "__main__" :
 | 
						|
    import argparse
 | 
						|
    parser = argparse.ArgumentParser ()
 | 
						|
    parser.add_argument ("database",    type = str)
 | 
						|
    parser.add_argument ("-u", "--user",  type = str)
 | 
						|
    parser.add_argument ("-p", "--password",    type = str)
 | 
						|
    parser.add_argument ("--check", action = "store_true")
 | 
						|
    parser.add_argument ("-i", "--imos_dir",    type = str)
 | 
						|
    parser.add_argument ("-P", "--pgiq_dir",    type = str)
 | 
						|
    parser.add_argument ("-l", "--line",        type = str)
 | 
						|
    cmd    = parser.parse_args ()
 | 
						|
    
 | 
						|
    db.bind (provider = "sqlite", filename = cmd.database, create_db = True)
 | 
						|
    db.generate_mapping (create_tables = True)
 | 
						|
    with orm.db_session :
 | 
						|
        breakpoint ()
 | 
						|
        if cmd.user :
 | 
						|
            u = User.get (username = cmd.user)
 | 
						|
            if not u :
 | 
						|
                u = User (username = cmd.user, password = cmd.password)
 | 
						|
                print (f"Add new user {cmd.user} to the database")
 | 
						|
            else :
 | 
						|
                if cmd.check :
 | 
						|
                    print (f"Check password for user {cmd.user}: "
 | 
						|
                           f"{u.check_password (cmd.password)}"
 | 
						|
                          ) 
 | 
						|
                else:
 | 
						|
                    print (f"Set new password for user {cmd.user}")
 | 
						|
                    u.change_password (cmd.password)
 | 
						|
        state = get_state ()
 | 
						|
        if cmd.imos_dir :
 | 
						|
            state.imos_export_dir = cmd.imos_dir
 | 
						|
        if cmd.pgiq_dir :
 | 
						|
            state.pgiq_import_dir = cmd.pgiq_dir
 | 
						|
        print (state)
 | 
						|
        if cmd.line :
 | 
						|
            short, name = cmd.line.split (":")
 | 
						|
            line = Production_Line.get (short = short)
 | 
						|
            if not line :
 | 
						|
                line = Production_Line (short = short, name = name)
 | 
						|
            else :
 | 
						|
                line.name = name
 | 
						|
            print (line) |