PCART  v1.4
Automated Repair of Python API Parameter Compatibility Issues
getPath.py
Go to the documentation of this file.
1 
10 
11 
12 
13 import os
14 import copy
15 
16 
17 
18 
23 class Path:
24 
31  def __init__(self,mode):
32  self._mode_mode=mode
33  self._filePath_filePath=[]
34  self._dirPath_dirPath=[]
35  self._requirements_requirements=[] #同一个项目中可能有多个requirements,来自第三方库,如aepx
36 
37 
42  @property
43  def path(self):
44  if self._mode_mode=='D':
45  return copy.deepcopy(self._dirPath_dirPath)
46  else:
47  return copy.deepcopy(self._filePath_filePath)
48 
49 
51  def clc(self):
52  self._dirPath_dirPath.clear()
53  self._filePath_filePath.clear()
54 
55 
60  def getPath(self,rootDir):
61  for root, dirs, files in os.walk(rootDir, followlinks=True):
62  files=[f for f in files if f[0]!='.'] # 过滤掉以.开头的隐藏文件
63  dirs=[d for d in dirs if d[0]!='.' and d!= '__pycache__' and d!='include'] # 过滤掉当前路径./和上一级路径../
64  if self._mode_mode=='F':
65  for f in files:
66  self._filePath_filePath.append(os.path.join(root,f))
67  break
68 
69  elif self._mode_mode=='D':
70  for dir in dirs:
71  self._dirPath_dirPath.append(os.path.join(root,dir))
72  break
73 
74  elif self._mode_mode=='DF':
75  for f in files:
76  if f.endswith('.py') or f.endswith('.pyi'): #在抽取库的时候需要.pyi,但在抽取项目代码时不需要.pyi文件
77  self._filePath_filePath.append(os.path.join(root, f))
78  if 'requirements.txt' in f:
79  self._requirements_requirements.append(os.path.join(root,f))
80 
81 
82  #判断项目中是否有requirements.txt
83  if len(self._requirements_requirements)>0:
84  return self._requirements_requirements[0] #返回一个要求的版本号
85  else:
86  return None
The Path class definition 路径定义类
Definition: getPath.py:23
def path(self)
Return collected paths (deep copy to avoid mutation) 返回收集到的路径(深拷贝以避免被修改)
Definition: getPath.py:43
def clc(self)
Clear previously collected path data for reuse 清空之前收集的路径数据以便复用
Definition: getPath.py:51
def __init__(self, mode)
Initialize the Path object with a traversal mode 使用遍历模式初始化Path对象
Definition: getPath.py:31
def getPath(self, rootDir)
Traverse the root directory and collect file and directory paths 遍历根目录,收集文件和目录路径
Definition: getPath.py:60