#!/usr/bin/env python import os import sys from net.Lliurex.Classroom.MovingProfiles import MovingProfiles def print_usage(): print "Lliurex moving editor" print "Usage: llxcfg-moving " print "Available commands:" print "list: List current moving rules" print "set : Sets a rule for include/exclude" def main(): if len(sys.argv)>1: cmd=sys.argv[1] if cmd=="list": mp=MovingProfiles() for item in mp.cfg.items("include"): name,value=item print "include "+str(name)+" "+str(value) for item in mp.cfg.items("exclude"): name,value=item print "exclude "+str(name)+" "+str(value) sys.exit(0) if cmd=="set": if len(sys.argv)>4: type=sys.argv[2] name=sys.argv[3] rule=sys.argv[4] mp=MovingProfiles() if type=="include": if mp.cfg.has_option("exclude",name): mp.cfg.remove_option("exclude",name) mp.cfg.set("include",name,regex) if type=="exclude": if mp.cfg.has_option("include",name): mp.cfg.remove_option("include",name) mp.cfg.set("exclude",name,regex) mp.Save() else: print_usage() sys.exit(0) if cmd=="del": mp=MovingProfiles() if len(sys.argv)>3: type=sys.argv[2] name=sys.argv[3] if mp.cfg.has_option(type,name): mp.cfg.remove_option(type,name) sys.exit(0) else: print_usage() if cmd=="check": mp=MovingProfiles() if len(sys.argv)>2: example=sys.argv[2] include=mp.isInclude(example) if not include==None: for item in include: print "include "+item exclude=mp.isExclude(example) if not exclude==None: for item in exclude: print "exclude "+item sys.exit(0) print_usage() if __name__=="__main__": main()