Ejemplo n.º 1
0
    def getWorkspaceSettings(self, filename):
        '''
        Le o arquivo de configuração e retorna a configuração para o arq em questão:
        @param Nome do arquivo\n
        @return Objeto de configuração do .json
        '''
        if not File.arquivoExiste("config.json"):
            return None

        with open("config.json", "r") as arq:
            obj = json.load(arq)
            if filename in obj:
                return obj[filename]
        return None
Ejemplo n.º 2
0
    def open(self, who, where, canCreate : bool = False):
        for arqv in self.files:
            absWhere = File.getAbsPath(who,where)
            print("$ FileDelivery OPEN [%s] @ %s" % (where,absWhere))
            if absWhere == arqv.local:
                return arqv
        absNewWhere = File.getAbsPath(who,where)
        
        if File.arquivoExiste(absNewWhere):
            novo = Arquivo(absNewWhere)
            self.files.append(novo)
            return novo

        elif canCreate:
            novo = Arquivo(absNewWhere, True)
            self.files.append(novo)
            return novo

        else:
            return None
Ejemplo n.º 3
0
    def writeWorkspaceSettings(self, filename, linha, coluna):
        '''
        Escreve no arquivo .json as configurações do arquivo em questão\n
        @param Nome do arquivo, linha e coluna do cursor\n
        '''
        '''
        ARQUIVO ANTES: {}
        ARQUIVO DEPOIS:{
            "nome_do_arq":{
                "linha":"posição_da_linha"
                "coluna":"posição_da_coluna"
            }
        }
        '''
        # if not(os.path.exists('config.json')):
        #     with open('config.json', 'w') as arq:
        #         arq.write('{}')

        if File.arquivoExiste("config.json"):
            with open('config.json', 'r') as arq:
                dados = json.load(arq)  # Leio o arq .json
        else:
            dados = {}

        dados_json = json.dumps(dados)  # Transfromo em uma string

        if dados_json == '{}':  # Testo pra ver se está vazio ou não
            # Se estiver, escrevo por cima a configuração do arq
            teste = {filename: {"linha": linha, "coluna": coluna}}
            with open('config.json', 'w') as arq:
                json.dump(teste, arq, indent=4)
        else:
            # Se não, coloco o arquivo como um obj
            with open("config.json", "r") as arq:
                obj = json.load(arq)
            # Acrescento a nova configuração no obj
            obj[filename] = {'linha': linha, 'coluna': coluna}
            # Reescrevo no arquivo o obj atualizado
            with open("config.json", "w") as arq:
                json.dump(obj, arq, indent=4)