示例#1
0
 def deleteUrl(self, urlId):
     urlModel = self.getUrlById(urlId)
     logDebug("[api][delete]url:{},{}".format(urlId, urlModel.url))
     # 删除文件
     deleteUrl(urlModel.url)
     fakerSession.delete(urlModel)
     fakerSession.commit()
示例#2
0
 def __init__(self, projectName):
     self.project = fakerSession.query(ProjectModel).filter(
         ProjectModel.name == projectName).first()
     if self.project:
         print(" \033[32mload config: {}\033[0m".format(projectName))
         print(" \033[32m首页地址可访问:http://127.0.0.1:5000\033[0m")
     else:
         logDebug("加载project:{}出错".format(projectName))
示例#3
0
 def deleteOtherParam(self, url, method, paramName, existUrls):
     basePath = jsonPathBy(url)
     directory = os.path.dirname(basePath)
     for file in os.listdir(directory):
         pathUrl = directory + file
         if file.startswith(basePath) and (not pathUrl in existUrls):
             logDebug("[api][delete]param: {} {} {}".format(
                 url, paramName, pathUrl))
             os.remove(pathUrl)
示例#4
0
 def addGroup(self, groupInfo):
     name = groupInfo.get("name")
     logDebug("[api][add] group: [{}]".format(name))
     group = GroupModel(name=name,
                        desc=name,
                        icon=groupInfo.get("icon"),
                        baseUrl=groupInfo.get("baseUrl"))
     self.project.groups.append(group)
     fakerSession.commit()
     return group
示例#5
0
def _loadFile(filepath):
    try:
        if not os.path.exists(filepath):
            logDebug("[file]-file not exist: {}".format(filepath))
            with open(userConfig.json("fileNotFound"), 'r',
                      encoding="utf-8") as f:
                return f.read()
        with open(filepath, 'r', encoding="utf-8") as f:
            return f.read()
    except:
        return ""
示例#6
0
def renameJson(name, newName, method):
    logDebug("[file]rename file: {} {}".format(name, newName))

    jsName = jsonPathBy(name)
    jsNewName = jsonPathBy(newName)
    if not os.path.exists(jsName):
        logDebug("[file] rename not exist: {}".format(name))
        return
    new_dir = os.path.dirname(jsNewName)
    if not os.path.exists(new_dir):
        os.makedirs(new_dir)

    os.rename(jsName, jsNewName)
示例#7
0
文件: main.py 项目: 515783034/Faker
def featchJson(request):
    logDebug("[fetch]url:{} {}".format(request.path, request.method))

    urlModel = Uapi.getUrlByPath(request.path)
    if not urlModel:
        return resNotFound()
    if urlModel.method != request.method:
        return resError("请检查 GET 和 POST 请求是否正确")
    result = getJsonPath(request, urlModel)
    if result[0]:
        newUrl = result[1]
    else:
        return result[1]

    try:
        logDebug("[fetch]url:{} path:{}".format(request.path, newUrl))
        return loadJson(newUrl)
    except json.decoder.JSONDecodeError as err:
        return resError('json解析失败:\n{}'.format(err))
示例#8
0
def deleteUrl(url):
    fileUrl = jsonPathBy(url)
    if os.path.exists(fileUrl):
        logDebug("[file]delete url: {}".format(fileUrl))
        os.remove(fileUrl)