Ejemplo n.º 1
0
 def _save_to_disk(self, updated_clients):
     tmp_table_name = self.table_name + '.tmp'
     with open(tmp_table_name) as f:
         writer = csv.DictWriter(f, fieldnames=ClientModel.schema())
         writer.writerows(updated_clients)
     os.remove(self.table_name)
     os.rename(tmp_table_name, self.table_name)
Ejemplo n.º 2
0
 def _save_to_disk(self, clients):
   tmp_table_name = self.table_name + '.tmp'
   with open(tmp_table_name, mode='w') as f:
     writer = csv.DictWriter(f, ClientModel.schema())
     writer.writerows(clients)
   os.remove(self.table_name)
   os.rename(tmp_table_name, self.table_name)
Ejemplo n.º 3
0
 def list_clients(self):
     try:
         with open(self.table_name, mode='r') as f:
             reader = csv.DictReader(f, fieldnames=ClientModel.schema())
             return list(reader)
     except:
         click.echo('There are no clients.')
         return 0
Ejemplo n.º 4
0
    def _save_to_disk(self, clients):
        tmp_file_name = self.file_name + ".tmp"
        with open(tmp_file_name, mode="a") as f:
            writer = csv.DictWriter(f, fieldnames=ClientModel.schema())
            writer.writerows(clients)

        os.remove(self.file_name)
        os.rename(tmp_file_name, self.file_name)
Ejemplo n.º 5
0
    def _save_to_disk(self, clients):
        # creamos tabla temporal
        tmp_table = self.table_name + '.tmp'
        with open(tmp_table, mode='w') as f:
            writer = csv.DictWriter(f, fieldnames=ClientModel.schema())
            writer.writerows(clients)

        # borramos tabla original
        os.remove(self.table_name)
        # renombramos nueva tabla
        os.rename(tmp_table, self.table_name)
Ejemplo n.º 6
0
 def list_clients(self):
     with open(self.table_name, mode='r') as f:
         reader = csv.DictReader(f, fieldnames=ClientModel.schema())
         return list(reader)
Ejemplo n.º 7
0
 def create_client(self, client):
     with open(self.table_name, mode='a') as f:
         writer = csv.DictWriter(f, fieldnames=ClientModel.schema())
         writer.writerow(client.to_dict())