<s> from flask_script import Command , Option <EOL> import xkcdpass . xkcd_password as xp <EOL> from model import db , User , Move , Sample <EOL> from imports import move_import <EOL> class AddUser ( Command ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_context , app_bcrypt ) : <EOL> self . app_context = app_context <EOL> self . app_bcrypt = app_bcrypt <EOL> def get_options ( self ) : <EOL> return [ <EOL> Option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:username>' , required = True ) , <EOL> Option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:password>' , required = False ) , <EOL> ] <EOL> def run ( self , username , password = None ) : <EOL> with self . app_context ( ) : <EOL> if not password : <EOL> wordfile = xp . locate_wordfile ( ) <EOL> mywords = xp . generate_wordlist ( wordfile = wordfile , min_length = <NUM_LIT:5> , max_length = <NUM_LIT:8> ) <EOL> password = xp . generate_xkcdpassword ( mywords , acrostic = "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % password ) <EOL> assert not User . query . filter_by ( username = username ) . scalar ( ) , "<STR_LIT>" <EOL> user = User ( username = username ) <EOL> user . password = self . app_bcrypt . generate_password_hash ( password , <NUM_LIT:10> ) <EOL> user . active = True <EOL> db . session . add ( user ) <EOL> db . session . commit ( ) <EOL> print ( "<STR_LIT>" % ( user . username , db . engine . url ) ) <EOL> class ImportMove ( Command ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_context ) : <EOL> self . app_context = app_context <EOL> def get_options ( self ) : <EOL> return [ <EOL> Option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:username>' , required = True ) , <EOL> Option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:filename>' , required = True ) , <EOL> ] <EOL> def run ( self , username , filename ) : <EOL> user = User . query . filter_by ( username = username ) . one ( ) <EOL> with open ( filename , '<STR_LIT:r>' ) as f : <EOL> move = move_import ( f , filename , user ) <EOL> if move : <EOL> print ( "<STR_LIT>" % move . id ) <EOL> class DeleteMove ( Command ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_context ) : <EOL> self . app_context = app_context <EOL> def get_options ( self ) : <EOL> return [ <EOL> Option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True ) , <EOL> ] <EOL> def run ( self , move_id ) : <EOL> move = Move . query . filter_by ( id = move_id ) . one ( ) <EOL> Sample . query . filter_by ( move = move ) . delete ( ) <EOL> db . session . delete ( move ) <EOL> db . session . commit ( ) <EOL> print ( "<STR_LIT>" % move . id ) <EOL> class ListMoves ( Command ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_context ) : <EOL> self . app_context = app_context <EOL> def get_options ( self ) : <EOL> return [ ] <EOL> def run ( self ) : <EOL> for move in Move . query : <EOL> print ( "<STR_LIT>" % ( move . id , move . user . username , move . date_time , move . activity ) ) </s>
