def execute(light_utils, argument=None): length = 50 if not argument or argument is True else int(argument) for x in range(0, length): color = random.choice(light_utils.colors.keys()) light_utils.set_light(color) time.sleep(0.5) Default.execute(light_utils)
class Commands: cmds = { "attach": lambda: Attach(), "detach": lambda: Detach(), "clean": lambda: Clean(), "sync": lambda: Sync(), "clone": lambda: Clone(), } forbiddance = ["rm"] def __init__(self, cmd_name): if cmd_name in self.forbiddance: print "The %s is forbidden command in mgit! Please use git." % cmd_name self.cmd = None return if cmd_name in self.cmds.keys(): self.cmd = self.cmds[cmd_name]() else: self.cmd = Default() def print_usages(self): for k, v in self.cmds.items(): if v: v().print_usage() def run(self, args): if not self.cmd: return self.cmd.run(args)
def execute(light_utils, argument=None): length = 50 if not argument or argument is True else int(argument) for x in range(1, length): brightness = random.randrange(1,100) color = random.choice(light_utils.colors.keys()) light_utils.set_light(color, transition = 10, brightness = brightness) time.sleep(1.3) Default.execute(light_utils)
def execute(light_utils, argument=None): length = 50 if not argument or argument is True else int(argument) for x in range(1, length): brightness = random.randrange(1, 100) color = random.choice(light_utils.colors.keys()) light_utils.set_light(color, transition=10, brightness=brightness) time.sleep(1.3) Default.execute(light_utils)
def execute(light_utils, argument=None): for x in range(0, 7): light_utils.set_light("Blue") time.sleep(0.7) light_utils.set_light("Moccasin") time.sleep(0.7) light_utils.set_light("Red") time.sleep(0.5) Default.execute(light_utils)
def set_strategy(self, strategy): if "default" in strategy: # MEC default = Default() self.strategy_name = strategy self.strategy = default self.strategy.replica_manager = self.replica_manager self.strategy.pm_manager = self.pm_manager self.strategy.dc_manager = self.dc_manager if "mec_power" in strategy: # COHM mec_power = MEC_POWER() self.strategy_name = strategy self.strategy = mec_power self.strategy.replica_manager = self.replica_manager self.strategy.pm_manager = self.pm_manager self.strategy.dc_manager = self.dc_manager if "mec_low_off" in strategy: # Sleep mec_low_off = MEC_LOW_OFF() self.strategy_name = strategy self.strategy = mec_low_off self.strategy.replica_manager = self.replica_manager self.strategy.pm_manager = self.pm_manager self.strategy.dc_manager = self.dc_manager if "mec_vm" in strategy: # Migration mec_vm = MEC_VM() self.strategy_name = strategy self.strategy = mec_vm self.strategy.replica_manager = self.replica_manager self.strategy.pm_manager = self.pm_manager self.strategy.dc_manager = self.dc_manager
def __init__(self, refPath, dataPath, dbFilename): GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(self.AUTO_START_GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) self.__i2c = I2C(2) self.__analog = Analog(sel.__i2c.getLock(), 0x49) self.default = Default() self.database = Database(dataPath, dbFilename) self.waterlevel = Waterlevel(debug, self.database) self.light = Light(self.database) self.curtain = Curtain(self.database) self.pressure = Pressure(self.database, self.default, self.__analog) self.temperature = Temperature("28-0417716a37ff", self.database) self.redox = Redox(debug, self.database, self.default, self.__analog) self.ph = PH(debug, self.database, self.default, self.__analog, self.temperature) self.robot = Robot(debug, self.database) self.pump = Pump(debug, self.database, self.default, self.robot, self.redox, self.ph, self.temperature) self.panel = Panel(debug, self.database, self.default, self.pump, self.redox, self.ph, self.__i2c) self.statistic = Statistic(debug, self.pump, self.robot, self.redox, self.ph, self.temperature, self.pressure, self.waterlevel) self.refPath = refPath self.__autoSaveTick = 0 self.__today = date.today().day - 1 debug.TRACE(debug.DEBUG, "Initialisation done (Verbosity level: %s)\n", debug)
def __init__(self, cmd_name): if cmd_name in self.forbiddance: print "The %s is forbidden command in mgit! Please use git." % cmd_name self.cmd = None return if cmd_name in self.cmds.keys(): self.cmd = self.cmds[cmd_name]() else: self.cmd = Default()
def process(self): lines = [line.strip() for line in self.contents.splitlines(True)] format = self.format if re.match("^\{[0-9]+\}\{[0-9]*\}", lines[1]): format = "microdvd" elif re.match("^[0-9]{1,2}:[0-9]{2}:[0-9]{2}[:=,]", lines[1]): format = "txt" elif "[SUBTITLE]" in lines[1]: format = "subviewer" else: Log("The subtitle file does not have a known format, skipping... : " + self.filename) return {} self.format = format return Default.process(self)
from pump import Pump from debug import Debug debug = Debug(Debug.DEBUG) GPIO.cleanup() GPIO.setmode(GPIO.BCM) class Database: def __init__(self): self.mode = dict() self.mode["redox"] = Mode.READ_STATE # AUTO_STATE READ_STATE def save(self, a, b, c): print "SAVE %s::%s = %s" % (a, b, c) try: redox = Redox(debug, Database(), Default(), Analog(0x49)) GPIO.setup(Pump.LIQUID_MOVE_GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) state = GPIO.input(Pump.LIQUID_MOVE_GPIO_PIN) relayPump = Relay(Pump.PUMP_GPIO_PIN) relayPump.switchOn() time.sleep(2.0) if state == GPIO.input(Pump.LIQUID_MOVE_GPIO_PIN): relayPump.switchOff() raise ValueError, "Water move not detected" for i in range(12): redox.update() print redox.read() time.sleep(5) except KeyboardInterrupt:
#code.cache_code() #code.print_code(pro = True, epi = True) #PrintInstructionStream(code, Default(show_prologue = True, show_epilogue = True, line_numbers = True, show_hex = True)) #PrintInstructionStream(code, Default()) #PrintInstructionStream(code, SPU_Asm(comment_chan = True)) import corepy.arch.x86_64.platform as env import corepy.arch.x86_64.isa as x86 import corepy.arch.x86_64.types.registers as regs import corepy.arch.x86_64.lib.memory as mem code = env.InstructionStream() code.add(x86.mov(regs.rax, 0xDEADBEEF)) code.add(x86.add(regs.rax, 0xDEADBEEF)) code.add(x86.call(-6)) code.add( x86.div( mem.MemRef(regs.r8, 1048576, regs.r13, 4, data_size=16, addr_size=32))) code.add(x86.sub(regs.rax, 0xBEEF)) code.add(x86.mov(regs.rax, mem.MemRef(regs.rbp, 8))) code.cache_code() PrintInstructionStream(code, Default(show_hex=True)) PrintInstructionStream(code, x86_64_Nasm(function_name="foobar"))
import RPi.GPIO as GPIO from default import Default from analog import Analog from relay import Relay from pump import Pump GPIO.cleanup() GPIO.setmode(GPIO.BCM) class Database: def __init__(self): self.mode = dict() self.mode["pressure"] = Mode.READ_STATE def save(self, a, b, c): print "SAVE %s::%s = %s" % (a, b, c) try: # Running: should > 0.5Bar (even if the filter is clean) pressure = Pressure(Database(), Default(), Analog(0x49)) pressure.update() print "Stopped: %fbar" % pressure.read() GPIO.setup(Pump.LIQUID_MOVE_GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) state = GPIO.input(Pump.LIQUID_MOVE_GPIO_PIN) relayPump = Relay(Pump.PUMP_GPIO_PIN) relayPump.switchOn() time.sleep(2.0) if state == GPIO.input(Pump.LIQUID_MOVE_GPIO_PIN): relayPump.switchOff() raise ValueError, "Water move not detected" for i in range(12): pressure.update() print "Running: %fbar" % pressure.read() time.sleep(5) relayPump.switchOff()
def process(self): self.format = 'ssa' return Default.process(self)
def run(self, opts): with open(opts.config, 'r') as configfile: self.config = yaml.load(configfile) self.db = dataset.connect('sqlite:///{}'.format(self.config['db'])) self.backends['dominos'] = Dominos(self.config['dominos']) self.backends['default'] = Default(None) # Create the EventHandler and pass it your bot's token. updater = Updater(self.config['token']) # Get the dispatcher to register handlers dp = updater.dispatcher # General commands # dp.add_handler(MentionsHandler(self.config['bot_name'], self.mention, edited_updates=True)) dp.add_handler( MessageHandler(MentionFilter(self.config['bot_name']), self.mention, edited_updates=True)) dp.add_handler(CommandHandler("help", self.send_help)) dp.add_handler(CommandHandler("start", self.start)) # Order commands dp.add_handler(CommandHandler("delete", self.delete)) # Collection commands dp.add_handler(CommandHandler("close", self.close_order)) dp.add_handler(CommandHandler("reopen", self.reopen_order)) dp.add_handler(CommandHandler("order", self.place_order)) # Configuration commands dp.add_handler(CommandHandler("settings", self.print_settings)) dp.add_handler(CommandHandler("mode", self.set_mode)) # Backend specific configuration dp.add_handler( CommandHandler( "store", lambda update, context: self.set_backend_specific_setting( 'store', context.bot, update))) dp.add_handler( CommandHandler( "servicemethod", lambda update, context: self.set_backend_specific_setting( 'service_method', context.bot, update))) dp.add_handler( CommandHandler( "method", lambda update, context: self.set_backend_specific_setting( 'service_method', context.bot, update))) dp.add_handler( CommandHandler( "address", lambda update, context: self.set_backend_specific_setting( 'address', context.bot, update))) dp.add_handler( CommandHandler( "name", lambda update, context: self.set_backend_specific_setting( 'name', context.bot, update))) dp.add_handler( CommandHandler( "phone", lambda update, context: self.set_backend_specific_setting( 'phone', context.bot, update))) dp.add_handler( CommandHandler( "email", lambda update, context: self.set_backend_specific_setting( 'email', context.bot, update))) dp.add_handler( CommandHandler( "time", lambda update, context: self.set_backend_specific_setting( 'time', context.bot, update))) dp.add_handler(CallbackQueryHandler(self.button)) # log all errors dp.add_error_handler(self.error) # Start the Bot updater.start_polling() # Run the bot until you press Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
def __init__(self, config): Default.__init__(self, config) self.mode_selected_message = "You're using Domino's Pizza Mode. I will try to interpret your orders " \ "as Domino's Pizza Menu Items, and when you submit it, I will order at " \ "your configured Domino's Pizza Store." self.short_description = "Order at Domino's Pizza stores in Switzerland"