1
1
import os
2
2
import shutil
3
- import subprocess
4
3
import concurrent .futures
5
4
6
5
from git import Repo
20
19
'.py' : PythonAnalyzer ()}
21
20
22
21
class SourceAnalyzer ():
22
+
23
+ def supported_types (self ) -> List [str ]:
24
+ """
25
+ """
26
+ return list (analyzers .keys ())
27
+
23
28
def first_pass (self , ignore : List [str ], executor : concurrent .futures .Executor ) -> None :
24
29
"""
25
30
Perform the first pass analysis on source files in the given directory tree.
@@ -53,6 +58,7 @@ def first_pass(self, ignore: List[str], executor: concurrent.futures.Executor) -
53
58
continue
54
59
55
60
logger .info (f'Processing file: { file_path } ' )
61
+ print (f'Processing file: { file_path } ' )
56
62
57
63
def process_file (path : Path ) -> None :
58
64
with open (path , 'rb' ) as f :
@@ -111,6 +117,17 @@ def process_file(path: Path) -> None:
111
117
# Wait for all tasks to complete
112
118
concurrent .futures .wait (tasks )
113
119
120
+ def analyze_file (self , path : Path , graph : Graph ) -> None :
121
+ ext = path .suffix
122
+ print (f"analyze_file: path: { path } " )
123
+ print (f"analyze_file: ext: { ext } " )
124
+ if ext not in analyzers :
125
+ return
126
+
127
+ with open (path , 'rb' ) as f :
128
+ analyzers [ext ].first_pass (path , f , graph )
129
+ analyzers [ext ].second_pass (path , f , graph )
130
+
114
131
def analyze_sources (self , ignore : List [str ]) -> None :
115
132
with concurrent .futures .ThreadPoolExecutor (max_workers = 1 ) as executor :
116
133
# First pass analysis of the source code
@@ -119,62 +136,9 @@ def analyze_sources(self, ignore: List[str]) -> None:
119
136
# Second pass analysis of the source code
120
137
self .second_pass (ignore , executor )
121
138
122
- def analyze_github_repository (
123
- self ,
124
- url : str ,
125
- repo_path : Path ,
126
- repo_name : str ,
127
- ignore : Optional [List [str ]] = []
128
- ) -> None :
139
+ def analyze (self , path : str , g : Graph , ignore : Optional [List [str ]] = []) -> None :
129
140
"""
130
- Analyze a Git repository given its URL.
131
-
132
- Args:
133
- url: The URL of the Git repository to analyze
134
- ignore_patterns: List of patterns to ignore during analysis
135
-
136
- Raises:
137
- subprocess.SubprocessError: If git clone fails
138
- OSError: If there are filesystem operation errors
139
- """
140
-
141
- # Extract repository name more reliably
142
- # Delete local repository if exists
143
- if repo_path .exists ():
144
- shutil .rmtree (repo_path )
145
-
146
- # Create directory
147
- repo_path .mkdir (parents = True , exist_ok = True )
148
-
149
- # Clone repository
150
- # Prepare the git clone command
151
- command = ["git" , "clone" , url , repo_path ]
152
-
153
- # Run the git clone command and wait for it to finish
154
- result = subprocess .run (command , check = True , capture_output = True , text = True )
155
-
156
- # Store original working directory
157
- original_dir = Path .cwd ()
158
-
159
- # change working directory to local repository
160
- os .chdir (repo_path )
161
-
162
- try :
163
- # Initialize the graph and analyzer
164
- self .graph = Graph (repo_name )
165
-
166
- # Analyze repository
167
- self .analyze_sources (ignore )
168
-
169
- logging .info (f"Successfully processed repository: { repo_name } " )
170
-
171
- finally :
172
- # Ensure we always return to the original directory
173
- os .chdir (original_dir )
174
-
175
- def analyze_local_folder (self , path : str , ignore : Optional [List [str ]] = []) -> Graph :
176
- """
177
- Analyze a local folder.
141
+ Analyze path.
178
142
179
143
Args:
180
144
path (str): Path to a local folder containing source files to process
@@ -184,18 +148,13 @@ def analyze_local_folder(self, path: str, ignore: Optional[List[str]] = []) -> G
184
148
# change working directory to path
185
149
os .chdir (path )
186
150
187
- proj_name = os .path .split (os .path .normpath (path ))[- 1 ]
188
- logger .debug (f'proj_name: { proj_name } ' )
189
-
190
151
# Initialize the graph and analyzer
191
- self .graph = Graph ( proj_name )
152
+ self .graph = g
192
153
193
154
# Analyze source files
194
155
self .analyze_sources (ignore )
195
156
196
- logger .info ("Done processing folder" )
197
-
198
- return self .graph
157
+ logger .info ("Done analyzing path" )
199
158
200
159
def analyze_local_repository (self , path : str , ignore : Optional [List [str ]] = []) -> Graph :
201
160
"""
0 commit comments