def __init__(self, sourceFilePath, includePaths, sourceDirPath, objectDirPath, makeConf):
        Rule.__init__(self)

        relPath = sourceFilePath.getRelevantPath(sourceDirPath)
        dirName = relPath.getDirName()
        baseName = relPath.getBaseName()

        objectSubDirPath = objectDirPath.join(dirName)
        objectFilePath = objectSubDirPath.join(PathUtil.getPrefix(baseName))
        if sourceFilePath.getExt() not in makeConf['asm_src_exts']:
            objectFilePath.appendExt('o')
        if sourceFilePath.getExt() in makeConf['asm_src_exts'] and makeConf['asm_with_object_ext']:
            objectFilePath.appendExt('o')
        self.setTarget(objectFilePath.shellString())

        self.sourceFilePath = sourceFilePath
        self.includePaths = includePaths
        self.objectSubDirPath = objectSubDirPath

        if self.sourceFilePath.getExt() in makeConf['c_src_exts']:
            self.includePaths.extend(PathUtil.toPathList(makeConf['c_include_paths']))
        elif self.sourceFilePath.getExt() in makeConf['cxx_src_exts']:
            if makeConf['cxx_using_c_include_paths']:
                self.includePaths.extend(PathUtil.toPathList(makeConf['c_include_paths']))
            self.includePaths.extend(PathUtil.toPathList(makeConf['cxx_include_paths']))
        elif self.sourceFilePath.getExt() in makeConf['asm_src_exts']:
            self.includePaths.extend(PathUtil.toPathList(makeConf['asm_include_paths']))

        self.targetLine = self.generateTargetLine(makeConf)

        makeDirectoryAction = MakeDirectoryAction(objectSubDirPath)
        compileAction = GCCCompileAction(objectFilePath, sourceFilePath, includePaths, makeConf)
        self.addBuildAction(makeDirectoryAction)
        self.addBuildAction(compileAction)
Пример #2
0
 def download_video(self, url, filename):
     final_filename = PathUtil.join_path(CONFIG['DOWNLOAD_PATH'], filename)
     if PathUtil.check_path(final_filename):
         print(f'{final_filename} exists, stop downloading')
         return final_filename
     print(f'{filename} download start')
     request = BilibiliApi.build_video_download_request(url)
     response = RequestUtil.do_request(request, load_json=False)
     self.before_response(response)
     self.save_video(response.raw_response, final_filename)
     return final_filename
def MakeBuildVersion():
    versionFile = None
    if not PathUtil.exist('target/BUILD_VERSION'):
        versionFile = FileUtil.openFile('target/BUILD_VERSION')
    else:
        versionFile = open('target/BUILD_VERSION', 'w')
    versionFile.close() 
 def scanModules(self):
     modules = __import__('modules')
     modulesPath = modules.__path__[0]
     modulesSubFiles = os.listdir(modulesPath)
     for modulesSubFile in modulesSubFiles:
         if os.path.isdir(PathUtil.join(modulesPath, modulesSubFile)) and not modulesSubFile.startswith('__'):
             self.moduleList.append(modulesSubFile)
Пример #5
0
 def _read_project_json(project_name):
     path = PathUtil.get_project_json(project_name)
     if os.path.exists(path):
         with open(path, 'r', encoding='utf8') as fp:
             return json.load(fp)
     else:
         return {'name': project_name, 'description': '--'}
Пример #6
0
 def get_project_by_name(project_name):
     # 工程基本信息
     project = ProjectService._read_project_json(project_name)
     file_tree_json = FileWorker().get_tree_json(
         PathUtil.get_project_dir(project_name))
     project_file_tree = {'project': project, 'files': file_tree_json}
     return json.dumps(project_file_tree)
Пример #7
0
def MakeBuildVersion():
    versionFile = None
    if not PathUtil.exist('target/BUILD_VERSION'):
        versionFile = FileUtil.openFile('target/BUILD_VERSION')
    else:
        versionFile = open('target/BUILD_VERSION', 'w')
    versionFile.close()
def KakefileChanged():
    if PathUtil.exist('target/BUILD_VERSION'):
        kakefileModifiedTime = os.path.getmtime('Kakefile')
        lastBuildTime = os.path.getmtime('target/BUILD_VERSION')
        if kakefileModifiedTime > lastBuildTime:
            return True

    return False
Пример #9
0
def KakefileChanged():
    if PathUtil.exist('target/BUILD_VERSION'):
        kakefileModifiedTime = os.path.getmtime('Kakefile')
        lastBuildTime = os.path.getmtime('target/BUILD_VERSION')
        if kakefileModifiedTime > lastBuildTime:
            return True

    return False
Пример #10
0
 def initCaller(self):
     self.enterPhase('Init')
     if not PathUtil.exist('Kakefile'):
         self.initKakefile()
     else:
         logger.debug('Skip initialize Kakefile')
     self.init()
     self.exitPhase('Init')
 def initCaller(self):
     self.enterPhase('Init')
     if not PathUtil.exist('Kakefile'):
         self.initKakefile()
     else:
         logger.debug('Skip initialize Kakefile')
     self.init()
     self.exitPhase('Init')
Пример #12
0
 def get_projects():
     projects = []
     base_dir = PathUtil.get_base_dir()
     for project_dir in os.listdir(base_dir):
         # 读取 ./.codepy/project.json
         project_json = ProjectService._read_project_json(project_dir)
         projects.append(project_json)
     return json.dumps(projects)
Пример #13
0
 def delete_project(project_name):
     full_path = PathUtil.get_project_dir(project_name)
     if os.path.exists(full_path):
         shutil.rmtree(full_path)
         project = {'name': project_name, 'description': ''}
         return Response(json.dumps(project), status=200)
     else:
         resp = Response("project not exist!", status=404)
         abort(resp)
Пример #14
0
 def scanModules(self):
     modules = __import__('modules')
     modulesPath = modules.__path__[0]
     modulesSubFiles = os.listdir(modulesPath)
     for modulesSubFile in modulesSubFiles:
         if os.path.isdir(PathUtil.join(
                 modulesPath,
                 modulesSubFile)) and not modulesSubFile.startswith('__'):
             self.moduleList.append(modulesSubFile)
Пример #15
0
 def build_filename(self, p_title, i, ext, j=None):
     if self.p_len == 1:
         filename = f'{self.owner}-{self.title}({p_title}).{ext}'
     else:
         filename = f'{self.owner}-{self.title}(P{i}.{p_title}).{ext}'
     if j is not None:
         filename = f'[{j}]-{filename}'
     filename = f'{filename}.download'
     return PathUtil.join_path(CONFIG['DOWNLOAD_PATH'],
                               legitimize(filename))
Пример #16
0
 def merge_video(self, video, *args):
     tmp_list = video.split('/')
     tmp_list[-1] = 'merge-' + tmp_list[-1]
     output = '/'.join(tmp_list)
     if PathUtil.check_path(output):
         print(f'{output}已存在')
         return output
     print('正在尝试合并视频,请参考控制台输出')
     FFmpegUtil(CONFIG['FFMPEG_PATH']).merge(video, *args, output=output)
     return output
Пример #17
0
    def __init__(self, sourceFilePath, includePaths, sourceDirPath,
                 objectDirPath, makeConf):
        Rule.__init__(self)

        relPath = sourceFilePath.getRelevantPath(sourceDirPath)
        dirName = relPath.getDirName()
        baseName = relPath.getBaseName()

        objectSubDirPath = objectDirPath.join(dirName)
        objectFilePath = objectSubDirPath.join(PathUtil.getPrefix(baseName))
        if sourceFilePath.getExt() not in makeConf['asm_src_exts']:
            objectFilePath.appendExt('o')
        if sourceFilePath.getExt(
        ) in makeConf['asm_src_exts'] and makeConf['asm_with_object_ext']:
            objectFilePath.appendExt('o')
        self.setTarget(objectFilePath.shellString())

        self.sourceFilePath = sourceFilePath
        self.includePaths = includePaths
        self.objectSubDirPath = objectSubDirPath

        if self.sourceFilePath.getExt() in makeConf['c_src_exts']:
            self.includePaths.extend(
                PathUtil.toPathList(makeConf['c_include_paths']))
        elif self.sourceFilePath.getExt() in makeConf['cxx_src_exts']:
            if makeConf['cxx_using_c_include_paths']:
                self.includePaths.extend(
                    PathUtil.toPathList(makeConf['c_include_paths']))
            self.includePaths.extend(
                PathUtil.toPathList(makeConf['cxx_include_paths']))
        elif self.sourceFilePath.getExt() in makeConf['asm_src_exts']:
            self.includePaths.extend(
                PathUtil.toPathList(makeConf['asm_include_paths']))

        self.targetLine = self.generateTargetLine(makeConf)

        makeDirectoryAction = MakeDirectoryAction(objectSubDirPath)
        compileAction = GCCCompileAction(objectFilePath, sourceFilePath,
                                         includePaths, makeConf)
        self.addBuildAction(makeDirectoryAction)
        self.addBuildAction(compileAction)
Пример #18
0
 def download_video(self, url, filename):
     if PathUtil.check_path(filename):
         PathUtil.remove(filename)
     retry_times = 2
     while retry_times > 0:
         try:
             request = BilibiliApi.build_video_download_request(url)
             response = RequestUtil.do_request(request,
                                               load_json=False,
                                               stream=True)
             self.before_response(response)
             self.save_video(response.raw_response, filename)
             break
         except:
             print(
                 f'{filename} download fail, retry times = {retry_times}, restart...'
             )
             retry_times -= 1
             if retry_times == 0:
                 raise Exception('retry times exceed, stop downloading...')
             continue
Пример #19
0
 def create_project(data):
     '''
     创建工程
     '''
     project = json.loads(data)
     name = project.get('name')
     full_path = PathUtil.get_project_dir(name)
     if os.path.exists(full_path):
         abort(Response("project already exist!", status=300))
     else:
         os.makedirs(os.path.join(full_path, '.codepy'))
         # 写入信息到 ./.codepy/project.json
         ProjectService._write_project_json(name, project)
         return json.dumps(project)
Пример #20
0
    def get_file(data):
        project_name = data.get("projectName")
        related_path = data.get("path")
        file_path = PathUtil.get_file_path(project_name, related_path)

        content = ''
        if os.path.exists(file_path):
            with open(file_path, 'r', encoding='utf8') as fp:
                content = fp.read()

        result = {
            'projectName': project_name,
            'path': related_path,
            "content": content
        }

        return json.dumps(result)
    def make(self, projectConfig):
        makeConf = {
            'target_type': projectConfig.getItem('make.configuration.target.type', self.defaultConf['target_type']),
            'cc': projectConfig.getItem('make.configuration.compiler.c.cc', self.defaultConf['cc']),
            'cxxc': projectConfig.getItem('make.configuration.compiler.cpp.cc', self.defaultConf['cxxc']),
            'cflags': projectConfig.getItem('make.configuration.compiler.c.flags', self.defaultConf['cflags']),
            'cxxflags': projectConfig.getItem('make.configuration.compiler.cpp.flags', self.defaultConf['cxxflags']),
            'fpic': projectConfig.getItem('make.configuration.compiler.fpic', self.defaultConf['fpic']),
            'autolink': projectConfig.getItem('make.configuration.linker.autolink', self.defaultConf['autolink']),
            'ar': projectConfig.getItem('make.configuration.archiver.ar', self.defaultConf['ar']),
            'ld': projectConfig.getItem('make.configuration.linker.ld', self.defaultConf['ld']),
            'ldflags': projectConfig.getItem('make.configuration.linker.flags', self.defaultConf['ldflags']),
            'ld_library_paths': projectConfig.getItem('make.configuration.linker.library_paths', self.defaultConf['ld_library_paths']),
            'libraries': projectConfig.getItem('make.configuration.linker.libraries', []),
            'c_src_exts': projectConfig.getItem('make.configuration.compiler.c.src_exts', self.defaultConf['c_src_exts']),
            'cxx_src_exts': projectConfig.getItem('make.configuration.compiler.cpp.src_exts', self.defaultConf['cxx_src_exts']),
            'c_include_paths': projectConfig.getItem('make.configuration.compiler.c.include_paths', self.defaultConf['c_include_paths']),
            'cxx_include_paths': projectConfig.getItem('make.configuration.compiler.cpp.include_paths', self.defaultConf['cxx_include_paths']),
            'cxx_using_c_include_paths': projectConfig.getItem('make.configuration.compiler.cpp.inherit_c_include_path', self.defaultConf['cxx_using_c_include_paths'])
        }

        makefile = GMakeDocument(TARGET_MAKEFILE_PATH)

        self.mainSourceFiles.clear()
        self.objectFiles.clear()
        cSourceFiles = []
        cppSourceFiles = []
        FileUtil.searchAllFiles(cSourceFiles, SRC_MAIN_PATH, makeConf['c_src_exts'])
        FileUtil.searchAllFiles(cppSourceFiles, SRC_MAIN_PATH, makeConf['cxx_src_exts'])
        self.mainSourceFiles.extend(cSourceFiles)
        self.mainSourceFiles.extend(cppSourceFiles)

        for fileName in self.mainSourceFiles:
            filePath = Path(fileName, True)
            relPath = filePath.getRelevantPath(SRC_MAIN_PATH)
            dirName = relPath.getDirName()
            baseName = relPath.getBaseName()

            subMakeDirPath = TARGET_SUBMAKE_MAIN_PATH.join(dirName)
            FileUtil.createDirectory(subMakeDirPath)

            subMakefilePath = subMakeDirPath.join(PathUtil.getPrefix(baseName))
            subMakefilePath.appendExt('mk')
            subMakefile = GMakeDocument(subMakefilePath)

            compileRule = GCCCompileRule(filePath, [INCLUDE_MAIN_PATH], SRC_MAIN_PATH, TARGET_OBJECT_MAIN_PATH, makeConf)
            subMakefile.addRule(compileRule)
            makefile.addSubDocument(subMakefile)

            objectFilePath = Path(compileRule.getTarget())
            self.objectFiles.append(objectFilePath)

        if makeConf['autolink']:
            if makeConf['target_type'] == 'executable':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)
                
                finalFileName = '%(name)s-%(version)s' % { 
                        'name': projectConfig.getItem('project.name', 'noname'),
                        'version': projectConfig.getItem('project.version', '1.0.0')}
                finalFilePath = TARGET_PATH.join(finalFileName)

                linkRule = GCCLinkRule(finalFilePath, self.objectFiles, makeConf)
                subMakefile.addRule(linkRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            elif makeConf['target_type'] == 'dynamic_library':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)
                
                finalFileName = 'lib%(name)s.so.%(version)s' % { 
                        'name': projectConfig.getItem('project.name', 'noname'),
                        'version': projectConfig.getItem('project.version', '1.0.0')}
                finalFilePath = TARGET_PATH.join(finalFileName)

                linkRule = GCCLinkRule(finalFilePath, self.objectFiles, makeConf)
                subMakefile.addRule(linkRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            elif makeConf['target_type'] == 'static_library':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)
                
                finalFileName = 'lib%(name)s.a.%(version)s' % { 
                        'name': projectConfig.getItem('project.name', 'noname'),
                        'version': projectConfig.getItem('project.version', '1.0.0')}
                finalFilePath = TARGET_PATH.join(finalFileName)

                arRule = ArRule(finalFilePath, self.objectFiles, makeConf)
                subMakefile.addRule(arRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            else:
                self.logger.warn('target_type is not recognized!')
                sys.exit(1)
        else:
            allRule = GMakeSimpleRule('all', self.objectFiles)
            makefile.addRule(allRule)

        makefile.writeToFile()

        return True
Пример #22
0
 def _write_project_json(project_name, project_json):
     path = PathUtil.get_project_json(project_name)
     with open(path, "w") as fp:
         fp.write(json.dumps(project_json, indent=4))
Пример #23
0
 def remove_download(self, output):
     filepath = output.replace('.download', '')
     PathUtil.rename(output, filepath)
     return filepath
Пример #24
0
 def merge_video(self, output, *files):
     if PathUtil.check_path(output):
         PathUtil.remove(output)
         return
     print('正在尝试合并视频,请参考控制台输出')
     FFmpegUtil(CONFIG['FFMPEG_PATH']).merge(*files, output=output)
Пример #25
0
    def make(self, projectConfig):
        makeConf = {
            'target_type':
            projectConfig.getItem('make.configuration.target.type',
                                  self.defaultConf['target_type']),
            'cc':
            projectConfig.getItem('make.configuration.compiler.c.cc',
                                  self.defaultConf['cc']),
            'cxxc':
            projectConfig.getItem('make.configuration.compiler.cpp.cc',
                                  self.defaultConf['cxxc']),
            'cflags':
            projectConfig.getItem('make.configuration.compiler.c.flags',
                                  self.defaultConf['cflags']),
            'cxxflags':
            projectConfig.getItem('make.configuration.compiler.cpp.flags',
                                  self.defaultConf['cxxflags']),
            'fpic':
            projectConfig.getItem('make.configuration.compiler.fpic',
                                  self.defaultConf['fpic']),
            'autolink':
            projectConfig.getItem('make.configuration.linker.autolink',
                                  self.defaultConf['autolink']),
            'ar':
            projectConfig.getItem('make.configuration.archiver.ar',
                                  self.defaultConf['ar']),
            'ld':
            projectConfig.getItem('make.configuration.linker.ld',
                                  self.defaultConf['ld']),
            'ldflags':
            projectConfig.getItem('make.configuration.linker.flags',
                                  self.defaultConf['ldflags']),
            'ld_library_paths':
            projectConfig.getItem('make.configuration.linker.library_paths',
                                  self.defaultConf['ld_library_paths']),
            'libraries':
            projectConfig.getItem('make.configuration.linker.libraries', []),
            'c_src_exts':
            projectConfig.getItem('make.configuration.compiler.c.src_exts',
                                  self.defaultConf['c_src_exts']),
            'cxx_src_exts':
            projectConfig.getItem('make.configuration.compiler.cpp.src_exts',
                                  self.defaultConf['cxx_src_exts']),
            'c_include_paths':
            projectConfig.getItem(
                'make.configuration.compiler.c.include_paths',
                self.defaultConf['c_include_paths']),
            'cxx_include_paths':
            projectConfig.getItem(
                'make.configuration.compiler.cpp.include_paths',
                self.defaultConf['cxx_include_paths']),
            'cxx_using_c_include_paths':
            projectConfig.getItem(
                'make.configuration.compiler.cpp.inherit_c_include_path',
                self.defaultConf['cxx_using_c_include_paths'])
        }

        makefile = GMakeDocument(TARGET_MAKEFILE_PATH)

        self.mainSourceFiles.clear()
        self.objectFiles.clear()
        cSourceFiles = []
        cppSourceFiles = []
        FileUtil.searchAllFiles(cSourceFiles, SRC_MAIN_PATH,
                                makeConf['c_src_exts'])
        FileUtil.searchAllFiles(cppSourceFiles, SRC_MAIN_PATH,
                                makeConf['cxx_src_exts'])
        self.mainSourceFiles.extend(cSourceFiles)
        self.mainSourceFiles.extend(cppSourceFiles)

        for fileName in self.mainSourceFiles:
            filePath = Path(fileName, True)
            relPath = filePath.getRelevantPath(SRC_MAIN_PATH)
            dirName = relPath.getDirName()
            baseName = relPath.getBaseName()

            subMakeDirPath = TARGET_SUBMAKE_MAIN_PATH.join(dirName)
            FileUtil.createDirectory(subMakeDirPath)

            subMakefilePath = subMakeDirPath.join(PathUtil.getPrefix(baseName))
            subMakefilePath.appendExt('mk')
            subMakefile = GMakeDocument(subMakefilePath)

            compileRule = GCCCompileRule(filePath, [INCLUDE_MAIN_PATH],
                                         SRC_MAIN_PATH,
                                         TARGET_OBJECT_MAIN_PATH, makeConf)
            subMakefile.addRule(compileRule)
            makefile.addSubDocument(subMakefile)

            objectFilePath = Path(compileRule.getTarget())
            self.objectFiles.append(objectFilePath)

        if makeConf['autolink']:
            if makeConf['target_type'] == 'executable':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)

                finalFileName = '%(name)s-%(version)s' % {
                    'name': projectConfig.getItem('project.name', 'noname'),
                    'version': projectConfig.getItem('project.version',
                                                     '1.0.0')
                }
                finalFilePath = TARGET_PATH.join(finalFileName)

                linkRule = GCCLinkRule(finalFilePath, self.objectFiles,
                                       makeConf)
                subMakefile.addRule(linkRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            elif makeConf['target_type'] == 'dynamic_library':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)

                finalFileName = 'lib%(name)s.so.%(version)s' % {
                    'name': projectConfig.getItem('project.name', 'noname'),
                    'version': projectConfig.getItem('project.version',
                                                     '1.0.0')
                }
                finalFilePath = TARGET_PATH.join(finalFileName)

                linkRule = GCCLinkRule(finalFilePath, self.objectFiles,
                                       makeConf)
                subMakefile.addRule(linkRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            elif makeConf['target_type'] == 'static_library':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)

                finalFileName = 'lib%(name)s.a.%(version)s' % {
                    'name': projectConfig.getItem('project.name', 'noname'),
                    'version': projectConfig.getItem('project.version',
                                                     '1.0.0')
                }
                finalFilePath = TARGET_PATH.join(finalFileName)

                arRule = ArRule(finalFilePath, self.objectFiles, makeConf)
                subMakefile.addRule(arRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            else:
                self.logger.warn('target_type is not recognized!')
                sys.exit(1)
        else:
            allRule = GMakeSimpleRule('all', self.objectFiles)
            makefile.addRule(allRule)

        makefile.writeToFile()

        return True