11import os
2+ import shutil
23import errors
34
45
@@ -136,23 +137,16 @@ def write_in_file(database, file, *content):
136137 return f"Database \" { database } \" or File \" { file } \" not found!"
137138
138139
139- def check_table_content (database , table , * border ):
140+ def check_table_content (database , table , * args ):
140141 '''
141142 Console command
142-
143- without border: GET ALL TableName
144- with border: GET 3 TableName # border equals 3, gets the first three lines
143+ GET ALL TableName
145144 '''
146145
147146 if os .path .exists (f"databases/{ database } /tables/{ table } .txt" ):
148147 file = open (f"databases/{ database } /tables/{ table } .txt" , "r" )
149148
150- if border :
151- if type (border [0 ]) is int :
152- if border [0 ] < len ([line for line in file ]):
153- return [line for line in file [3 :border [0 ]+ 4 ]]
154- 155- return [line for line in file [3 :]]
149+ return [line for line in file ][2 :]
156150
157151 print ("Table not found!" )
158152 return []
@@ -161,18 +155,11 @@ def check_table_content(database, table, *border):
161155def check_file_content (database , file_name , * border ):
162156 '''
163157 Console command
164-
165- without border: GET FILE FileName
166- with border: GET FILE FileName 3 # border equals 3, gets the first three lines
158+ GET FILE FileName
167159 '''
168160
169161 if os .path .exists (f"databases/{ database } /files/{ file_name } .txt" ):
170- file = open (f"databases/{ database } /tables/{ file_name } .txt" , "r" )
171- 172- if border :
173- if type (border [0 ]) is int :
174- if border [0 ] < len ([line for line in file ]):
175- return [line for line in file [:border [0 ] + 1 ]]
162+ file = open (f"databases/{ database } /files/{ file_name } .txt" , "r" )
176163
177164 return [line for line in file ]
178165
@@ -195,7 +182,7 @@ def drop_database(*databases):
195182
196183 for db in databases :
197184 if os .path .exists (f"databases/{ db } /" ):
198- os . remove (f"databases/{ db } /" )
185+ shutil . rmtree (f"databases/{ db } /" )
199186
200187 return "Database/s dropped!"
201188
@@ -247,6 +234,21 @@ def code_saver(user_input, code_file, new_line):
247234
248235
249236def run_program ():
237+ while True :
238+ db = input ("create or use database: " )
239+ 240+ if db == 'create' :
241+ create_db = input ("database name: " )
242+ create_database (create_db )
243+ d = use_database (create_db )
244+ break
245+ 246+ elif db == "use" :
247+ d = use_database (input ("database name: " ))[- 1 ]
248+ break
249+ 250+ database = d
251+ 250252 while True :
251253 file = input ("Create or choose file where to save the code from your console experience:\n " )
252254
@@ -327,7 +329,7 @@ def run_program():
327329 code_saver (item , file , '\n \n \n ' )
328330 print (add_content_to_table (database , table , * lst_values ))
329331
330- elif operation [:- 1 ] == ["create" "file" ]:
332+ elif operation [:- 1 ] == ["create" , "file" ]:
331333 print (create_file (database , operation [- 1 ]))
332334
333335 elif operation [:- 1 ] == ["write" , "in" ]:
@@ -344,22 +346,16 @@ def run_program():
344346 content .append (text )
345347
346348 if operation [- 1 ][- 1 ] == ':' :
347- print (write_in_file (database , operation [- 1 ][:- 1 ], content ))
349+ print (write_in_file (database , operation [- 1 ][:- 1 ], * content ))
348350
349351 else :
350- print (write_in_file (database , operation [- 1 ], content ))
352+ print (write_in_file (database , operation [- 1 ], * content ))
351353
352- code_saver (content , file , '\n \n \n ' )
354+ code_saver (content [ - 1 ] , file , '\n \n \n ' )
353355
354356 elif operation [0 ] == "get" and operation [1 ] == "all" :
355357
356- lines = check_table_content (database , operation [1 ])
357- print ()
358- [print (line ) for line in lines ]
359- 360- elif operation [0 ] == "get" and operation [1 ].isdigit ():
361- 362- lines = check_table_content (database , operation [- 1 ], int (operation [1 ]))
358+ lines = check_table_content (database , operation [- 1 ])
363359 print ()
364360 [print (line ) for line in lines ]
365361
@@ -369,12 +365,6 @@ def run_program():
369365 print ()
370366 [print (line ) for line in lines ]
371367
372- elif operation [:- 2 ] == ["get" , "file" ]:
373- 374- lines = check_file_content (database , operation [- 2 ], int (operation [- 1 ]))
375- print ()
376- [print (line ) for line in lines ]
377- 378368 elif operation [:- 1 ] == ["drop" , "db" ] or operation [:- 1 ] == ["drop" , "database" ] or operation [:2 ] == \
379369 ["drop" , "dbs" ] or operation [:2 ] == ["drop" , "databases" ]:
380370
@@ -388,6 +378,3 @@ def run_program():
388378 print (delete_file (database , * operation [2 :]))
389379
390380 code_saver ('\n // everything bellow is made on new run.' , file , '\n ' )
391- 392- 393- run_program ()
0 commit comments