Exemplo n.º 1
0
def moveYaxis(board, way):
    """
    Function used to move in list on y axis a.k.a. vertical axis.
    """

    if (way == "up"):
        new_board = turn(sanitizey(board, "up"))
        for i in range(len(new_board)):
            for j in range(len(new_board)):
                if (new_board[i][j] in powers_of_two
                        and new_board[i][j] == new_board[i][j + 1]):
                    new_board[i][j] *= 2
                    delete(i, j + 1, new_board)

        return sanitizey(turn(new_board), "up")

    if (way == "down"):
        new_board = turn(sanitizey(board, "down"))
        for i in range(len(new_board)):
            for j in range(len(new_board) - 1):
                if (new_board[i][j] in powers_of_two
                        and new_board[i][j + 1] == new_board[i][j]):
                    new_board[i][j + 1] *= 2
                    delete(i, j, new_board)

        return sanitizey(turn(new_board), "down")

    else:
        raise Exception("Type in correct way !")
Exemplo n.º 2
0
def moveXaxis(board, way):
    """
    Function used to move in list on x axis a.k.a. horzontal axis.
    """

    if (way == "right"):
        new_board = sanitizex(board, 'right')
        for i in range(len(new_board)):
            for j in range(len(new_board) - 1):
                if (new_board[i][j] in powers_of_two
                        and new_board[i][j + 1] == new_board[i][j]):
                    new_board[i][j + 1] *= 2
                    delete(i, j, new_board)

        return new_board

    elif (way == "left"):
        new_board = sanitizex(board, 'left')
        for i in range(len(new_board)):
            for j in range(len(new_board) - 1):
                if (new_board[i][j] in powers_of_two
                        and new_board[i][j - 1] == new_board[i][j]):
                    new_board[i][j - 1] *= 2
                    delete(i, j, new_board)

        return new_board

    else:
        raise Exception("Type in correct way !")
Exemplo n.º 3
0
 def _saveTrackings(self):
     if self.trackingsSaved: return
     try:
         self.trackingsLock.acquire()
         trackingFile = h.makePath(self.basePath, ".tracking")
         tmpTrackingFile = h.makePath(self.basePath, ".tracking.tmp")
         h.logDebug("Saving trackings saved to file", len(self.trackings),
                    trackingFile)
         headers, datas = [
             "path", "authorized", "password", "ip", "date", "protected",
             "location"
         ], []
         for t in self.trackings:
             datas.append([
                 t.path, t.authorized, t.password, t.ip, t.date,
                 t.protected, t.location
             ])
         h.writeToCSV(datas, tmpTrackingFile, headers=headers, append=True)
         h.delete(trackingFile)
         os.rename(tmpTrackingFile, trackingFile)
         if self.user is not None:
             h.changeFileOwner(trackingFile, self.user)
         self.trackingsSaved = True
         h.logDebug("Trackings saved to file", len(self.trackings),
                    trackingFile)
     except:
         le, lt = h.getLastExceptionAndTrace()
         h.logWarning("Can't save trackings", le)
     finally:
         self.trackingsLock.release()
 def remove(self, path):
     path = h.cleanPath(path)
     if self.doesItemExists(path) and self.ap.isEditAllowed(
             self.getParent(path)):
         h.delete(self.getFullPath(path))
         return True
     else:
         return False
    def run(self):
        while not self._interrupt and not self._exitEvent.isSet():
            try:
                items = h.listDirectoryItems(self.tmpFolder)
                for item in items:
                    if h.getFileModified(item) + self.tmpDuration < h.now():
                        h.delete(item)
                        h.logInfo("Item too old deleted %s" % item)
            except:
                print(h.getLastExceptionAndTrace())
            finally:
                self._exitEvent.wait(500)

        h.logDebug("CleanTmp thread finished")