Esempio n. 1
0
	def run(self):
		r = Parser().read("repo_path")
		if not os.path.exists("%s/.repo" % r):
			if Globals.checkClobber.get_active() == False:
				RepoHelper().run_no_repo_found()
				Globals.TERM.set_background_saturation(1.0)
				Globals.TERM.fork_command('clear')
			return
		ab = Parser().read("rom_abrv")
		if ab == "CM":
			from projects.CyanogenMod import CyanogenMod as CM
			Update().main("Compiling CyanogenMod")
			CM().Compile()
		elif ab == "CNA":
			from projects.CodenameAndroid import CodenameAndroid as CNA
			Update().main("Compiling CodenameAndroid")
			CNA().Compile()
		elif ab == "AOSP":
			from projects.AOSP import AOSP
			Update().main("Compiling AOSP")
			AOSP().Compile()
		elif ab == "AOKP":
			from projects.AOKP import AOKP
			Update().main("Compiling AOKP")
			AOKP().Compile()
		else:
			n = Parser().read("rom_dist")
			Dialogs().CDial(gtk.MESSAGE_INFO, "Rom %s not supported" % n, "Sorry but at this time,\n\n%s\n\nis not supported, please contact us for more info" % n)
			Update().main(None)
			return
Esempio n. 2
0
 def del_repo_paths(widget):
     global REPO_NAME
     REPO_NAME = str(REPO_NAME.strip())
     if REPO_NAME is not "None":
         q = Dialogs().QDial(
             "Remove repos: %s?" % REPO_NAME,
             "Are you sure you want to remove:\n %s\n\nOnce this is done it can't be undone."
             % REPO_NAME)
         if q is not True:
             return
     if REPO_NAME == "All":
         for x in REPOS:
             if os.path.isdir(x):
                 if Parser().read("repo_path") == x:
                     Parser().write("repo_path",
                                    Globals.myDEF_REPO_PATH)
                 shutil.rmtree(x)
                 dialog.destroy()
                 Update().main(None)
     elif REPO_NAME == "None":
         pass
     else:
         if os.path.isdir(REPO_NAME):
             if Parser().read("repo_path") == REPO_NAME:
                 Parser().write("repo_path", Globals.myDEF_REPO_PATH)
             shutil.rmtree(REPO_NAME)
             dialog.destroy()
             Update().main(None)
Esempio n. 3
0
 def addArgs(parser: argparse.ArgumentParser) -> None:
     Update.addArgs(parser)
     grp = parser.add_argument_group(description="Dialog related options")
     grp.add_argument("--gliderDB",
                      type=str,
                      metavar="filename",
                      required=True,
                      help="Name of glider database")
    def create_individual(self):
        # get an id for indv
        id = self.generate_id()
        #data = [self.get_new_frac(), self.get_new_LAI()]
        fracs = [np.random.uniform() for f in range(self.n_tiles)]
        veg_lake = random.randint(1, self.n_veg)
        individual = [str(id)] + fracs[:] + [veg_lake]
        #random.shuffle(individual[1:])
        individual = self.normalize_fracs(individual)
        update = Update()
        # update global, lake parameters
        update.update_params(individual)

        return individual
Esempio n. 5
0
    def checked_term_toggle(self, widget):
        if Globals.checkTermToggle.get_active() == True:
            Parser().write(self.KEY_TERM_TOGGLE, True)
        else:
            Parser().write(self.KEY_TERM_TOGGLE, False)

        Update().widgets()
Esempio n. 6
0
    def mutate(self, child_1):
        chromosome = Individual()
        individual = child_1.individual
        start_index = 1
        end_index = len(individual) - 2
        mutate_index = random.randrange(start_index, end_index)
        individual[mutate_index] = np.random.uniform()
        individual = chromosome.normalize_fracs(individual)

        # update id and params
        individual[0] = str(chromosome.generate_id())
        update = Update()
        update.update_params(individual)
        #        chromosome.update_params(individual)
        child = Individual()
        child.individual = individual
        child.fitness = chromosome.calc_fitness(individual)
        return child
Esempio n. 7
0
    def toggle_term_btn(self):
        if Globals.checkTermToggle.get_active() == True:
            Parser().write(KEY_TERM_TOGGLE, False)
            Globals.checkTermToggle.set_active(False)
        else:
            Parser().write(KEY_TERM_TOGGLE, True)
            Globals.checkTermToggle.set_active(True)

        Update().widgets()
Esempio n. 8
0
    def checked_bash_toggle(self, widget):
        if Globals.checkBashToggle.get_active() == True:
            if Globals.checkTermToggle.get_active() == False:
                Globals.checkTermToggle.set_active(True)
                Parser().write(self.KEY_TERM_TOGGLE, True)
                Update().widgets()

            self.run_local_shell()
        else:
            self.ResetTerm()
Esempio n. 9
0
    def crossover(self, individual1, individual2):
        # crossover fractions
        parent_1 = individual1.individual
        parent_2 = individual2.individual
        chromosome = Individual()
        start_index = 1
        end_index = len(parent_1) - 2
        crossover_index = random.randrange(start_index, end_index + 1)
        child_1a = parent_1[crossover_index:]
        child_1b = parent_2[:crossover_index]
        child_1 = child_1b + child_1a

        child_2a = parent_2[crossover_index:]
        child_2b = parent_1[:crossover_index]
        child_2 = child_2b + child_2a

        # crossover lake's veg type
        if np.random.uniform() > 0.5:
            tmp = child_1[len(child_1) - 1]
            child_1[len(child_1) - 1] = child_2[len(child_2) - 1]
            child_2[len(child_2) - 1] = tmp

        # normalize fractions
        child_1 = chromosome.normalize_fracs(child_1)
        child_2 = chromosome.normalize_fracs(child_2)

        # update id and params
        child_1[0] = chromosome.generate_id()
        child_2[0] = chromosome.generate_id()
        update = Update()
        update.update_params(child_1)
        update.update_params(child_2)
        #        chromosome.update_params(child_1)
        #        chromosome.update_params(child_2)
        child1 = Individual()
        child2 = Individual()

        child1.individual = child_1
        child2.individual = child_2

        child1.fitness = chromosome.calc_fitness(child_1)
        child2.fitness = chromosome.calc_fitness(child_2)
        return child1, child2
Esempio n. 10
0
    def update_generator(self):
        self.updates = []
        
        while True:
            
            #Wait for a random amount of time before generating the next update
            #Scale the rate s.t. each controller roughly gets to see lambda rate by means of splitting
            
            yield self.env.timeout(random.expovariate(len(self.controllers) * self.current_param[0]))
            
            #Select a uniformly random controller from all the ones that have been generated            
            controller = random.choice(self.controllers)

            #Create an update and hop it on
            update = Update(self.env, controller, controller.hla_list, self.current_param[2])            
            
            self.updates.append(update)
                        
            self.env.process(update.process_update())
Esempio n. 11
0
 def checked_adb_toggle(self, widget):
     if Globals.checkAdbToggle.get_active() == True:
         if Globals.checkTermToggle.get_active() == False:
             Globals.checkTermToggle.set_active(True)
             Parser().write(self.KEY_TERM_TOGGLE, True)
             Update().widgets()
             self.start_adb()
         else:
             self.start_adb()
     else:
         self.ResetTerm()
Esempio n. 12
0
    def cust_background_dialog(self):
        IMG = FileChooser().getFile()
        if IMG is not None:
            import imghdr as im
            test = im.what(IMG)
            if test:
                Parser().write("background", IMG)
                Update().background()
            else:
                Dialogs().CDial(
                    gtk.MESSAGE_ERROR, "File not an image!",
                    "Please use images for backgrounds!\n\nFile:\n%s" % IMG)

        return
Esempio n. 13
0
 def repo(self):
     q = Dialogs().QDial(
         "Install repo script",
         "Are you sure you want to install the repo script?\n\nThis will ask for root!"
     )
     if q == True:
         Update().main("Installing repo...")
         Globals.TERM.set_background_saturation(0.3)
         Globals.TERM.fork_command("bash")
         Globals.TERM.feed_child("clear\n")
         Globals.TERM.feed_child(
             "curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > repo\n"
         )
         Globals.TERM.feed_child("chmod a+x repo\n")
         Globals.TERM.feed_child("gksudo mv repo /usr/local/bin/repo\n")
     return
Esempio n. 14
0
    def change_background(self):
        def chbutton(widget, data=None):
            global WHICH
            WHICH = data

        BLIST = ["Custom", "Default"]
        global WHICH
        WHICH = None

        dialog = gtk.Dialog("Change background", None,
                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                             gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        dialog.set_size_request(225, 233)
        dialog.set_resizable(False)

        hbox = gtk.HBox(False, 10)
        hbox.show()

        TYPE = gtk.RadioButton(None, None)

        for radio in BLIST:
            frame = gtk.Frame()
            frame.set_label(radio)
            frame.show()
            button = gtk.RadioButton(group=TYPE, label="%s" % (radio))
            button.connect("toggled", chbutton, radio)
            frame.add(button)
            hbox.add(frame)
            button.show()

        dialog.vbox.pack_start(hbox, True, True, 0)

        r = dialog.run()
        dialog.destroy()

        if r == gtk.RESPONSE_ACCEPT:
            if WHICH is "Default":
                Parser().write("background", None)
                Update().background()
            elif WHICH is "Custom":
                self.cust_background_dialog()
            else:
                return None
        else:
            return None
Esempio n. 15
0
 def start_adb(self):
     if Utils().is_adb_running() == True:
         (x, y) = self.choose_adb()
         if x is not None:
             Update().main("Running adb for %ss" % y)
             Globals.TERM.set_background_saturation(0.3)
             Globals.TERM.fork_command('bash')
             if x is "A":
                 Globals.TERM.feed_child("adb logcat\n")
             else:
                 Globals.TERM.feed_child("adb logcat |grep \"%s/\"\n" % x)
         else:
             self.ResetTerm()
     else:
         Dialogs().CDial(
             self.DIALOG_ERROR, "Adb isn't running",
             "Need adb running to start, start it.\n\nPlease try again.")
         self.ResetTerm()
         return
Esempio n. 16
0
    def handleInput(self, command):
        """ handleInput will be used to execute commands to change the key value
        store.

        This handles insertions, deletions, select statements,
        update statements, search/find statements, and rename statements.
        Insert commands will return the new rows, Delete statements returns a
        list of keys of deleted items, Update statements return updated rows,
        rename statements return rename objects of tuples, and
        SELECT, SEARCH, and FIND STATEMENTS will print the outputs
        while also returning nothing.

        Keyword Argument:
        command -- the raw command passed in by the user

        Return values:
        changesMade -- an object of type Insert, Delete, Update, Rename,
                       or None depending on which command the input was to
                       execute. The object will be used to update dynamicDB and
                       any variables used to keep track of changes for
                       save/undo purposes.
        """

        # check the inputs
        parser = re.compile(r'[a-z-0-9*!@#$%^&~_.+={}():\'",]+', re.IGNORECASE)
        matches = parser.findall(command)
        changesMade = None
        if matches[0].lower() == 'insert':
            changesMade = Insert(matches, self.typesSet)
        elif matches[0].lower() == 'rename':
            changesMade = renamed(matches[1:])
        elif matches[0].lower() == 'delete':
            changesMade = Delete(matches, self.typesSet)
        elif matches[0].lower() == 'update':
            changesMade = Update(matches, self.typesSet)
        elif matches[0].lower() == 'select':
            Selects.handleSelects(matches, self.dynamicDB)
        elif matches[0].lower() == 'search':
            Search.handleSearches(matches, self.dynamicDB)
        elif matches[0].lower() == 'find':
            Search.handleSearches(matches, self.dynamicDB, True)
        return changesMade
Esempio n. 17
0
 def rom_combo_change(self, w):
     value = str(w.get_active_text())
     num = int(w.get_active())
     if num == 0:
         value2 = "Android Open Source Project"
     elif num == 1:
         value2 = "CyanogenMod"
     elif num == 2:
         value2 = "Android Open Kang Project"
     elif num == 3:
         value2 = "Codename Android"
     else:
         value = "AOSC"
         value2 = "Android Open Source Compiler"
     Parser().write("rom_dist", value2)
     Parser().write("rom_abrv", value)
     Parser().write("branch", "Default")
     Parser().write("device", "Default")
     Parser().write("manuf", "Default")
     Update().main(None)
Esempio n. 18
0
class Dialog(MyBaseThread):
    def __init__(self, args: argparse.ArgumentParser, logger: logging.Logger):
        MyBaseThread.__init__(self, "Dialog", args, logger)
        self.__queue = queue.Queue()
        self.__update = Update(args, logger)

    @staticmethod
    def addArgs(parser: argparse.ArgumentParser) -> None:
        Update.addArgs(parser)
        grp = parser.add_argument_group(description="Dialog related options")
        grp.add_argument("--gliderDB",
                         type=str,
                         metavar="filename",
                         required=True,
                         help="Name of glider database")

    def __repr__(self) -> str:
        msg = []
        for key in sorted(self):
            msg.append("{}={}".format(key, self[key]))
        return "\n".join(msg)

    def put(self, line: str) -> None:
        self.__queue.put(
            (datetime.datetime.now(tz=datetime.timezone.utc), line))

    def runAndCatch(self) -> None:  # Called on start
        args = self.args
        logger = self.logger
        q = self.__queue
        update = self.__update

        logger.info("Starting")

        update.start()  # Start the update thread

        db = None
        timeout = 300  # Close database if no communications for this long
        sql = "INSERT OR REPLACE INTO glider VALUES(?,?,?);"

        while True:
            try:
                (t, line) = q.get(timeout=None if db is None else timeout)
                line = line.strip()
                logger.debug("t=%s line=%s", t, line)
                for pattern in patterns:
                    info = pattern.check(line, logger)
                    if info is None: continue
                    if db is None:
                        db = self.__makeDB(args.gliderDB)
                        cur = db.cursor()
                    for key in info:
                        cur.execute(sql, (t, key, info[key]))
                    db.commit()
                    if "FLAG" in info: update.put(t, args.gliderDB)
                    break
                q.task_done()
            except queue.Empty:
                if db is not None:
                    logger.info("Closing database")
                    db.close()
                    db = None
            except:
                logger.exception("Error processing %s", line)
                q.task_done()

    def __makeDB(self, dbName: str) -> None:
        sql = "CREATE TABLE IF NOT EXISTS glider ( -- Glider dialog information\n"
        sql += "    t TIMESTAMP WITH TIME ZONE, -- When line was received\n"
        sql += "    name TEXT, -- name of the field\n"
        sql += "    val FLOAT, -- value of the field\n"
        sql += "    PRIMARY KEY (t,name) -- Retain each t/name pair\n"
        sql += ");"
        db = sqlite3.connect(dbName)
        cur = db.cursor()
        cur.execute(sql)
        return db

    def waitToFinish(self) -> None:
        self.__queue.join()
        self.__update.waitToFinish()
Esempio n. 19
0
    if options.action not in 'update|status|shelved':
        if (options.branch == None) and (len(options.args) == 0):
            print('You must be in a valid Mercurial working folder!')
            sys.exit(0)

    if not options.action:
        print('Nothing to do!  Please specify an action.')
        sys.exit(0)

    result = 0
    pyhg_action = None

    if options.action == 'update':
        from Update import Update
        Update(options)
    elif options.action == 'status':
        from Info import Status
        pyhg_action = Status()
    elif options.action == 'log':
        from Info import Log
        Log(options)
    elif options.action == 'incoming':
        from Incoming import Incoming
        Incoming(options)
    elif options.action == 'commit':
        from Commit import Commit
        Commit(options)
    elif options.action == 'stage':
        from Stage import Stage
        Stage(options)
Esempio n. 20
0
 def device_button(self, event):
     self.Devices()
     Update().main(None)
Esempio n. 21
0
 def sync_combo_change(self, w):
     value = int(w.get_active_text())
     Parser().write("sync_jobs", value)
     Update().main(None)
Esempio n. 22
0
 def __init__(self):
     self.update = Update()
     self.gmodel = Gmodel()
Esempio n. 23
0
 def run_local_shell(self):
     self.ResetTerm()
     Update().main("Running bash shell")
     Globals.TERM.set_background_saturation(0.3)
     Globals.TERM.fork_command('bash')
Esempio n. 24
0
 def choose_repo_path(self):
     RESPONSE = FileChooser().getFolder()
     if RESPONSE is not None:
         Parser().write("repo_path", RESPONSE)
         Update().main(None)
Esempio n. 25
0
 def ResetTerm(self):
     Globals.checkAdbToggle.set_active(False)
     Globals.TERM.set_background_saturation(1.0)
     Globals.TERM.fork_command('clear')
     Update().main(None)
Esempio n. 26
0
class WebController(object):
    def __init__(self, ipadd, session=None):
        self.ip = ipadd
        self.class_name = "WebController"
        self.ls = LogShow(self.class_name)
        if not hasattr(self, "session"):
            if session is None:
                self.login()
            else:
                self.session = session

    def __str__(self):
        return self.class_name

    def login(self):
        self.login = LogIn(self.ip)
        self.session = self.login.login()
        return self.session

    def Debug(self):
        if not hasattr(self, "debug"):
            self.debug = Debug(self.ip, self.session)
        return self.debug

    def openDebug(self):
        self.Debug()
        return self.debug.openDebug()

    def closeDebug(self):
        self.Debug()
        return self.debug.closeDebug()

    def getSN(self):
        if not hasattr(self, "getsn"):
            self.getsn = GetSN(self.ip, self.session)
        return self.getsn

    def getDeviceSN(self):
        self.getSN()
        return self.getsn.getDeviceSN()

    def getBaseSN(self):
        self.getSN()
        return self.getsn.getBaseSN()

    def getIPMode(self):
        self.getSN()
        return self.getsn.getIPMode()

    def getVersion(self):
        self.getSN()
        return self.getsn.getVersion()

    def getFWVersion(self):
        self.getSN()
        return self.getsn.getFWVersion()

    def GetDiagnosis(self):
        if not hasattr(self, "getdiagnosis"):
            self.getdiagnosis = GetDiagnosis(self.ip, self.session)
        return self.getdiagnosis

    def OpenDiagnosis(self):
        self.GetDiagnosis()
        self.getdiagnosis.OpenDiagnosis()

    def getMsg(self):
        self.GetDiagnosis()
        self.getdiagnosis.getMsg()

    def RunGetAll(self):
        self.GetDiagnosis()
        self.getdiagnosis.RunGetAll()

    def CloseDiagnosis(self):
        self.GetDiagnosis()
        self.getdiagnosis.CloseDiagnosis()

    def Update(self, fmpath):
        if not hasattr(self, "update"):
            self.update = Update(self.ip, fmpath, self.session)
        return self.update

    def runUpdate(self):
        self.Update()
        self.update.runUpdate()

    def runUpdate_new(self):
        self.Update()
        self.update.runUpdate_new()

    def run(self, command, args=[]):
        if command is not None and command != '':
            if command == 'openDebug':
                self.openDebug()
            if command == 'closeDebug':
                self.closeDebug()
            if command == 'getDeviceSN':
                self.getDeviceSN()
            if command == 'getBaseSN':
                self.getBaseSN()
            if command == 'getVersion':
                self.getVersion()
            if command == 'getFWVersion':
                self.getFWVersion()
            if command == 'openDiagnosis':
                self.openDiagnosis()
            if command == 'getMsg':
                self.getMsg()
            if command == 'RunGetALL':
                self.RunGetAll()
            if command == 'CloseDiagnosis':
                self.CloseDiagnosis()
            if command == 'Update':
                self.Update(args)
            if command == 'runUpdate':
                self.runUpdate()
Esempio n. 27
0
 def __init__(self, args: argparse.ArgumentParser, logger: logging.Logger):
     MyBaseThread.__init__(self, "Dialog", args, logger)
     self.__queue = queue.Queue()
     self.__update = Update(args, logger)
Esempio n. 28
0
    def choose_branch(self, obj):
        branchList = []
        rom = Parser().read("rom_abrv")
        if rom == "CM":
            from projects.CyanogenMod import CyanogenMod as CM
            for x in CM.BranchList:
                branchList.append(x)
        elif rom == "AOKP":
            from projects.AOKP import AOKP as AOKP
            for x in AOKP.BranchList:
                branchList.append(x)
        elif rom == "AOSP":
            from projects.AOSP import AOSP as AOSP
            for x in AOSP.BranchList:
                branchList.append(x)
        elif rom == "CNA":
            from projects.CodenameAndroid import CodenameAndroid as CNA
            for x in CNA.BranchList:
                branchList.append(x)
        else:
            return

        def callback_branch(widget, data=None):
            #print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])
            Parser().write("branch", data)

        dialog = gtk.Dialog("Choose branch", None,
                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                             gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        dialog.set_size_request(260, 200)
        dialog.set_resizable(False)

        scroll = gtk.ScrolledWindow()
        scroll.set_border_width(10)
        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
        dialog.vbox.pack_start(scroll, True, True, 0)
        scroll.show()

        table = gtk.Table(2, 1, False)
        table.set_row_spacings(0)

        scroll.add_with_viewport(table)
        table.show()

        device = gtk.RadioButton(None, None)

        button_count = 0
        for radio in branchList:

            button_count += 1
            button = gtk.RadioButton(group=device, label="%s" % (radio))
            button.connect("toggled", callback_branch, radio)
            table.attach(button,
                         0,
                         1,
                         button_count - 1,
                         button_count,
                         xoptions=gtk.FILL,
                         yoptions=gtk.FILL)
            button.show()

        dialog.run()
        dialog.destroy()
        Update().main(None)
Esempio n. 29
0
 def Update(self, fmpath):
     if not hasattr(self, "update"):
         self.update = Update(self.ip, fmpath, self.session)
     return self.update