12
12
import hashlib
13
13
from datetime import datetime
14
14
15
+ from .constants import (
16
+ SETTINGS_DIR , CONFIG_FILE , INDEX_FILE , CACHE_FILE
17
+ )
18
+
15
19
class ProjectSettings :
16
20
"""Class for managing project settings and index data"""
17
21
18
- SETTINGS_DIR = "code_indexer"
19
- CONFIG_FILE = "config.json"
20
- INDEX_FILE = "file_index.pickle"
21
- CACHE_FILE = "content_cache.pickle"
22
-
23
22
def __init__ (self , base_path , skip_load = False ):
24
23
"""Initialize project settings
25
24
@@ -50,18 +49,13 @@ def __init__(self, base_path, skip_load=False):
50
49
print (f"Using current directory as fallback: { system_temp } " )
51
50
52
51
# Create code_indexer directory
53
- temp_base_dir = os .path .join (system_temp , self . SETTINGS_DIR )
52
+ temp_base_dir = os .path .join (system_temp , SETTINGS_DIR )
54
53
print (f"Code indexer directory path: { temp_base_dir } " )
55
54
56
55
if not os .path .exists (temp_base_dir ):
57
56
print (f"Creating code indexer directory: { temp_base_dir } " )
58
57
os .makedirs (temp_base_dir , exist_ok = True )
59
-
60
- # Create a README.md file explaining the purpose of this directory
61
- readme_path = os .path .join (temp_base_dir , "README.md" )
62
- with open (readme_path , 'w' , encoding = 'utf-8' ) as f :
63
- f .write ("# Code Indexer Cache Directory\n \n This directory contains cached data for the Code Index MCP tool.\n Each subdirectory corresponds to a different project.\n " )
64
- print (f"README file created: { readme_path } " )
58
+ print (f"Code indexer directory created: { temp_base_dir } " )
65
59
else :
66
60
print (f"Code indexer directory already exists: { temp_base_dir } " )
67
61
except Exception as e :
@@ -104,24 +98,7 @@ def ensure_settings_dir(self):
104
98
print (f"Creating project settings directory: { self .settings_path } " )
105
99
# Create directory structure
106
100
os .makedirs (self .settings_path , exist_ok = True )
107
-
108
- # Create a README.md file explaining the purpose of this directory
109
- readme_path = os .path .join (self .settings_path , "README.md" )
110
- readme_content = (
111
- f"# Code Indexer Cache Directory for { self .base_path } \n \n "
112
- f"This directory contains cached data for the Code Index MCP tool:\n \n "
113
- f"- `config.json`: Project configuration\n "
114
- f"- `file_index.pickle`: Index of project files\n "
115
- f"- `content_cache.pickle`: Cached file contents\n \n "
116
- f"These files are automatically generated and stored in the system temporary directory.\n "
117
- )
118
-
119
- try :
120
- with open (readme_path , 'w' , encoding = 'utf-8' ) as f :
121
- f .write (readme_content )
122
- print (f"README file created: { readme_path } " )
123
- except Exception as e :
124
- print (f"Warning: Could not create README file: { e } " )
101
+ print (f"Project settings directory created: { self .settings_path } " )
125
102
else :
126
103
print (f"Project settings directory already exists: { self .settings_path } " )
127
104
@@ -148,38 +125,38 @@ def ensure_settings_dir(self):
148
125
def get_config_path (self ):
149
126
"""Get the path to the configuration file"""
150
127
try :
151
- path = os .path .join (self .settings_path , self . CONFIG_FILE )
128
+ path = os .path .join (self .settings_path , CONFIG_FILE )
152
129
# Ensure directory exists
153
130
os .makedirs (os .path .dirname (path ), exist_ok = True )
154
131
return path
155
132
except Exception as e :
156
133
print (f"Error getting config path: { e } " )
157
134
# If error occurs, use file in current directory as fallback
158
- return os .path .join (os .getcwd (), self . CONFIG_FILE )
135
+ return os .path .join (os .getcwd (), CONFIG_FILE )
159
136
160
137
def get_index_path (self ):
161
138
"""Get the path to the index file"""
162
139
try :
163
- path = os .path .join (self .settings_path , self . INDEX_FILE )
140
+ path = os .path .join (self .settings_path , INDEX_FILE )
164
141
# Ensure directory exists
165
142
os .makedirs (os .path .dirname (path ), exist_ok = True )
166
143
return path
167
144
except Exception as e :
168
145
print (f"Error getting index path: { e } " )
169
146
# If error occurs, use file in current directory as fallback
170
- return os .path .join (os .getcwd (), self . INDEX_FILE )
147
+ return os .path .join (os .getcwd (), INDEX_FILE )
171
148
172
149
def get_cache_path (self ):
173
150
"""Get the path to the cache file"""
174
151
try :
175
- path = os .path .join (self .settings_path , self . CACHE_FILE )
152
+ path = os .path .join (self .settings_path , CACHE_FILE )
176
153
# Ensure directory exists
177
154
os .makedirs (os .path .dirname (path ), exist_ok = True )
178
155
return path
179
156
except Exception as e :
180
157
print (f"Error getting cache path: { e } " )
181
158
# If error occurs, use file in current directory as fallback
182
- return os .path .join (os .getcwd (), self . CACHE_FILE )
159
+ return os .path .join (os .getcwd (), CACHE_FILE )
183
160
184
161
def _get_timestamp (self ):
185
162
"""Get current timestamp"""
@@ -257,7 +234,7 @@ def save_index(self, file_index):
257
234
if not os .access (dir_path , os .W_OK ):
258
235
print (f"Warning: Directory is not writable: { dir_path } " )
259
236
# Use current directory as fallback
260
- index_path = os .path .join (os .getcwd (), self . INDEX_FILE )
237
+ index_path = os .path .join (os .getcwd (), INDEX_FILE )
261
238
print (f"Using fallback path: { index_path } " )
262
239
263
240
with open (index_path , 'wb' ) as f :
@@ -268,7 +245,7 @@ def save_index(self, file_index):
268
245
print (f"Error saving index: { e } " )
269
246
# Try saving to current directory
270
247
try :
271
- fallback_path = os .path .join (os .getcwd (), self . INDEX_FILE )
248
+ fallback_path = os .path .join (os .getcwd (), INDEX_FILE )
272
249
print (f"Trying fallback path: { fallback_path } " )
273
250
with open (fallback_path , 'wb' ) as f :
274
251
pickle .dump (file_index , f )
@@ -304,7 +281,7 @@ def load_index(self):
304
281
return {}
305
282
else :
306
283
# Try loading from current directory
307
- fallback_path = os .path .join (os .getcwd (), self . INDEX_FILE )
284
+ fallback_path = os .path .join (os .getcwd (), INDEX_FILE )
308
285
if os .path .exists (fallback_path ):
309
286
print (f"Trying fallback path: { fallback_path } " )
310
287
try :
@@ -340,7 +317,7 @@ def save_cache(self, content_cache):
340
317
if not os .access (dir_path , os .W_OK ):
341
318
print (f"Warning: Directory is not writable: { dir_path } " )
342
319
# Use current directory as fallback
343
- cache_path = os .path .join (os .getcwd (), self . CACHE_FILE )
320
+ cache_path = os .path .join (os .getcwd (), CACHE_FILE )
344
321
print (f"Using fallback path: { cache_path } " )
345
322
346
323
with open (cache_path , 'wb' ) as f :
@@ -351,7 +328,7 @@ def save_cache(self, content_cache):
351
328
print (f"Error saving cache: { e } " )
352
329
# Try saving to current directory
353
330
try :
354
- fallback_path = os .path .join (os .getcwd (), self . CACHE_FILE )
331
+ fallback_path = os .path .join (os .getcwd (), CACHE_FILE )
355
332
print (f"Trying fallback path: { fallback_path } " )
356
333
with open (fallback_path , 'wb' ) as f :
357
334
pickle .dump (content_cache , f )
@@ -387,7 +364,7 @@ def load_cache(self):
387
364
return {}
388
365
else :
389
366
# Try loading from current directory
390
- fallback_path = os .path .join (os .getcwd (), self . CACHE_FILE )
367
+ fallback_path = os .path .join (os .getcwd (), CACHE_FILE )
391
368
if os .path .exists (fallback_path ):
392
369
print (f"Trying fallback path: { fallback_path } " )
393
370
try :
@@ -462,7 +439,7 @@ def get_stats(self):
462
439
stats ['all_files' ] = all_files
463
440
464
441
# Get details for specific files
465
- for filename in [self . CONFIG_FILE , self . INDEX_FILE , self . CACHE_FILE ]:
442
+ for filename in [CONFIG_FILE , INDEX_FILE , CACHE_FILE ]:
466
443
file_path = os .path .join (self .settings_path , filename )
467
444
if os .path .exists (file_path ):
468
445
try :
0 commit comments