def UpdateCproject(env, project, excluding): excluding = sorted(excluding) cproject = etree.parse('.cproject') root = cproject.getroot() cconfigurations = root.findall('storageModule/cconfiguration') for cconfiguration in cconfigurations: tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool') HandleToolOption(tools, env, project) sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') entry = sourceEntries.find('entry') if entry != None: sourceEntries.remove(entry) value = '' for item in excluding: if value == '': value = item else: value += '|' + item SubElement(sourceEntries, 'entry', {'excluding': value, 'flags': 'VALUE_WORKSPACE_PATH|RESOLVED', 'kind':'sourcePath', 'name':""}) # write back to .cproject out = open('.cproject', 'w') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n') out.write('<?fileVersion 4.0.0?>') xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def IARProject(target, script): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('build/scripts/template.ewp') root = tree.getroot() out = file(target, 'wb') existedFileNameString=[] # find repeat source file for group in script: for filePath in group['src']: filename = os.path.splitext(basename(filePath)) if existedFileNameString.count(filename): repeat_path.append(filePath) else: existedFileNameString.append(filename) print 'repeat files:', repeat_path # add group for group in script: IARAddGroup(root, group['name'], group['src'], group['include'], project_path) xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() IARWorkspace(target)
def UpdateCproject(env, project, excluding, reset, prj_name): excluding = sorted(excluding) cproject = etree.parse('.cproject') root = cproject.getroot() cconfigurations = root.findall('storageModule/cconfiguration') for cconfiguration in cconfigurations: tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool') HandleToolOption(tools, env, project, reset) sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') entry = sourceEntries.find('entry') HandleExcludingOption(entry, sourceEntries, excluding) # update refreshScope if prj_name: prj_name = '/' + prj_name configurations = root.findall('storageModule/configuration') for configuration in configurations: resource = configuration.find('resource') configuration.remove(resource) SubElement(configuration, 'resource', {'resourceType': "PROJECT", 'workspacePath': prj_name}) # write back to .cproject out = open('.cproject', 'w') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n') out.write('<?fileVersion 4.0.0?>') xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def UpdateProjectStructure(env, prj_name): bsp_root = env['BSP_ROOT'] rtt_root = env['RTT_ROOT'] project = etree.parse('.project') root = project.getroot() if rtt_root.startswith(bsp_root): linkedResources = root.find('linkedResources') if linkedResources == None: linkedResources = SubElement(root, 'linkedResources') links = linkedResources.findall('link') # delete all RT-Thread folder links for link in links: if link.find('name').text.startswith('rt-thread'): linkedResources.remove(link) if prj_name: name = root.find('name') if name == None: name = SubElement(root, 'name') name.text = prj_name out = open('.project', 'w') out.write('<?xml version="1.0" encoding="UTF-8"?>\n') xml_indent(root) out.write(etree.tostring(root, encoding = 'utf-8')) out.close() return
def IARProject(target, script): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template.ewp') root = tree.getroot() out = file(target, 'wb') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' # add group for group in script: IARAddGroup(root, group['name'], group['src'], project_path) # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: CPPPATH += group['CPPPATH'] # get each group's definitions if group.has_key('CPPDEFINES') and group['CPPDEFINES']: CPPDEFINES += group['CPPDEFINES'] # get each group's link flags if group.has_key('LINKFLAGS') and group['LINKFLAGS']: LINKFLAGS += group['LINKFLAGS'] # make relative path paths = set() for path in CPPPATH: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') # setting options options = tree.findall('configuration/settings/data/option') for option in options: # print option.text name = option.find('name') if name.text == 'CCIncludePath2' or name.text == 'newCCIncludePaths': for path in paths: state = SubElement(option, 'state') if os.path.isabs(path) or path.startswith('$'): state.text = path else: state.text = '$PROJ_DIR$\\' + path if name.text == 'CCDefines': for define in CPPDEFINES: state = SubElement(option, 'state') state.text = define xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() IARWorkspace(target)
def IARProject(target, script): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template.ewp') root = tree.getroot() out = file(target, 'wb') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' # add group for group in script: IARAddGroup(root, group['name'], group['src'], project_path) # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: CPPPATH += group['CPPPATH'] # get each group's definitions if group.has_key('CPPDEFINES') and group['CPPDEFINES']: CPPDEFINES += group['CPPDEFINES'] # get each group's link flags if group.has_key('LINKFLAGS') and group['LINKFLAGS']: LINKFLAGS += group['LINKFLAGS'] # make relative path paths = set() for path in CPPPATH: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') # setting options options = tree.findall('configuration/settings/data/option') for option in options: # print option.text name = option.find('name') if name.text == 'CCIncludePath2' or name.text == 'newCCIncludePaths': for path in paths: state = SubElement(option, 'state') if os.path.isabs(path): state.text = path else: state.text = '$PROJ_DIR$\\' + path if name.text == 'CCDefines': for define in CPPDEFINES: state = SubElement(option, 'state') state.text = define xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() IARWorkspace(target)
def singleNode(self, indexnumber, tagname, mediatype, itemtype): tagname = tagname.encode('utf-8') cleantagname = self.normalize_nodes(tagname) nodepath = xbmc.translatePath("special://profile/library/video/").decode('utf-8') nodeXML = "%semby_%s.xml" % (nodepath, cleantagname) path = "library://video/emby_%s.xml" % cleantagname windowpath = "ActivateWindow(Videos,%s,return)" % path # Create the video node directory if not xbmcvfs.exists(nodepath): # We need to copy over the default items shutil.copytree( src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'), dst=xbmc.translatePath("special://profile/library/video").decode('utf-8')) xbmcvfs.exists(path) labels = { 'Favorite movies': 30180, 'Favorite tvshows': 30181, 'Favorite episodes': 30182, 'channels': 30173 } label = lang(labels[tagname]) embynode = "Emby.nodes.%s" % indexnumber window('%s.title' % embynode, value=label) window('%s.path' % embynode, value=windowpath) window('%s.content' % embynode, value=path) window('%s.type' % embynode, value=itemtype) if xbmcvfs.exists(nodeXML): # Don't recreate xml if already exists return if itemtype == "channels": root = self.commonRoot(order=1, label=label, tagname=tagname, roottype=2) etree.SubElement(root, 'path').text = "plugin://plugin.video.emby/?id=0&mode=channels" elif itemtype == "favourites" and mediatype == "episodes": root = self.commonRoot(order=1, label=label, tagname=tagname, roottype=2) etree.SubElement(root, 'path').text = "plugin://plugin.video.emby/?id=%s&mode=browsecontent&type=%s&folderid=favepisodes" %(tagname, mediatype) else: root = self.commonRoot(order=1, label=label, tagname=tagname) etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle" etree.SubElement(root, 'content').text = mediatype try: xml_indent(root) except: pass etree.ElementTree(root).write(nodeXML)
def HandleRTTRoot(env): bsp_root = env['BSP_ROOT'] rtt_root = env['RTT_ROOT'] if not rtt_root.startswith(bsp_root): to_SubElement = True # print('handle virtual root') # always use '/' path separator rtt_root = rtt_root.replace('\\', '/') project = etree.parse('.project') root = project.getroot() linkedResources = root.find('linkedResources') if linkedResources == None: # add linkedResources linkedResources = SubElement(root, 'linkedResources') # print('add linkedResources') else: links = linkedResources.findall('link') # search exist 'rt-thread' virtual folder for link in links: if link.find('name').text == 'rt-thread': # handle location to_SubElement = False location = link.find('location') location.text = rtt_root if to_SubElement: # print('to subelement for virtual folder') link = SubElement(linkedResources, 'link') name = SubElement(link, 'name') name.text = 'rt-thread' type = SubElement(link, 'type') type.text = '2' location = SubElement(link, 'location') location.text = rtt_root out = open('.project', 'w') out.write('<?xml version="1.0" encoding="UTF-8"?>\n') xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() return
def CLGenWorkspace(project_name, project_path): if os.path.isfile('codelite_template.workspace'): tree = etree.parse('codelite_template.workspace') else: tree = etree.parse( os.path.join(os.path.dirname(__file__), 'codelite_template.workspace')) root = tree.getroot() root.attrib['Name'] = project_name node = root.find('Project') node.attrib['Name'] = project_name node.attrib['Path'] = project_name + '.project' node = root.find('BuildMatrix').find('WorkspaceConfiguration').find( 'Project') node.attrib['Name'] = project_name out = open(project_name + '.workspace', 'w') out.write('<?xml version="1.0" encoding="UTF-8"?>\n') xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def SESProject(env): target = 'project.emProject' tree = etree.parse('template.emProject') # print(etree.dump(tree.getroot())) # etree.dump(tree.getroot()) project = ProjectInfo(env) # print(project) # return project_path = os.path.abspath(env['BSP_ROOT']) script = env['project'] root = tree.getroot() out = file(target, 'w') out.write('<!DOCTYPE CrossStudio_Project_File>\n') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' project_node = tree.find('project') for group in script: # print(group) group_tree = SDKAddGroup(project_node, group['name'], group['src'], project_path) # get each group's cc flags if 'CCFLAGS' in group and group['CCFLAGS']: if CCFLAGS: CCFLAGS += ' ' + group['CCFLAGS'] else: CCFLAGS += group['CCFLAGS'] # get each group's link flags if 'LINKFLAGS' in group and group['LINKFLAGS']: if LINKFLAGS: LINKFLAGS += ' ' + group['LINKFLAGS'] else: LINKFLAGS += group['LINKFLAGS'] # write include path, definitions and link flags path = ';'.join([ _make_path_relative(project_path, os.path.normpath(i)) for i in project['CPPPATH'] ]) path = path.replace('\\', '/') defines = ';'.join(set(project['CPPDEFINES'])) node = tree.findall('project/configuration') for item in node: if item.get('c_preprocessor_definitions'): item.set('c_preprocessor_definitions', defines) if item.get('c_user_include_directories'): item.set('c_user_include_directories', path) xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() return
def MDK45Project(tree, target, script): project_path = os.path.dirname(os.path.abspath(target)) root = tree.getroot() out = open(target, 'w') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' ProjectFiles = [] # add group groups = tree.find('Targets/Target/Groups') if groups is None: groups = SubElement(tree.find('Targets/Target'), 'Groups') groups.clear() # clean old groups for group in script: group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) # for local CPPPATH/CPPDEFINES if (group_tree != None) and ('LOCAL_CPPPATH' in group or 'LOCAL_CCFLAGS' in group or 'LOCAL_CPPDEFINES' in group): GroupOption = SubElement(group_tree, 'GroupOption') GroupArmAds = SubElement(GroupOption, 'GroupArmAds') Cads = SubElement(GroupArmAds, 'Cads') VariousControls = SubElement(Cads, 'VariousControls') MiscControls = SubElement(VariousControls, 'MiscControls') if 'LOCAL_CCFLAGS' in group: MiscControls.text = group['LOCAL_CCFLAGS'] else: MiscControls.text = ' ' Define = SubElement(VariousControls, 'Define') if 'LOCAL_CPPDEFINES' in group: Define.text = ', '.join(set(group['LOCAL_CPPDEFINES'])) else: Define.text = ' ' Undefine = SubElement(VariousControls, 'Undefine') Undefine.text = ' ' IncludePath = SubElement(VariousControls, 'IncludePath') if 'LOCAL_CPPPATH' in group: IncludePath.text = ';'.join([ _make_path_relative(project_path, os.path.normpath(i)) for i in group['LOCAL_CPPPATH'] ]) else: IncludePath.text = ' ' # get each include path if 'CPPPATH' in group and group['CPPPATH']: if CPPPATH: CPPPATH += group['CPPPATH'] else: CPPPATH += group['CPPPATH'] # get each group's definitions if 'CPPDEFINES' in group and group['CPPDEFINES']: if CPPDEFINES: CPPDEFINES += group['CPPDEFINES'] else: CPPDEFINES = group['CPPDEFINES'] # get each group's link flags if 'LINKFLAGS' in group and group['LINKFLAGS']: if LINKFLAGS: LINKFLAGS += ' ' + group['LINKFLAGS'] else: LINKFLAGS += group['LINKFLAGS'] if 'LIBS' in group and group['LIBS']: for item in group['LIBS']: lib_path = '' for path_item in group['LIBPATH']: full_path = os.path.join(path_item, item + '.lib') if os.path.isfile(full_path): # has this library lib_path = full_path break if lib_path != '': if group_tree != None: MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path) else: group_tree = MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) # write include path, definitions and link flags IncludePath = tree.find( 'Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath' ) IncludePath.text = ';'.join([ _make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH ]) Define = tree.find( 'Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') Define.text = ', '.join(set(CPPDEFINES)) Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') Misc.text = LINKFLAGS xml_indent(root) out.write(etree.tostring(root, encoding='utf-8').decode()) out.close()
def CBProject(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) if os.path.isfile('template.cbp'): tree = etree.parse('template.cbp') else: tree = etree.parse(os.path.join(os.path.dirname(__file__), 'template.cbp')) root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n') ProjectFiles = [] # SECTION 1. add "*.c|*.h" files group for elem in tree.iter(tag='Project'): # print elem.tag, elem.attrib break # add c files for group in script: group_xml = CB_AddCFiles(ProjectFiles, elem, group['name'], group['src'], project_path) # add h files CB_AddHeadFiles(program, elem, project_path) # SECTION 2. # write head include path if building.Env.has_key('CPPPATH'): cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() # write include path, definitions for elem in tree.iter(tag='Compiler'): break for path in paths: Add = SubElement(elem, 'Add') Add.set('directory', path) for macro in building.Env.get('CPPDEFINES', []): Add = SubElement(elem, 'Add') Add.set('option', "-D"+macro) # write link flags ''' # write lib dependence if building.Env.has_key('LIBS'): for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCLinkerTool': break libs_with_extention = [i+'.lib' for i in building.Env['LIBS']] libs = ' '.join(libs_with_extention) elem.set('AdditionalDependencies', libs) # write lib include path if building.Env.has_key('LIBPATH'): lib_path = building.Env['LIBPATH'] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() lib_paths = ';'.join(paths) elem.set('AdditionalLibraryDirectories', lib_paths) ''' xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def VS2012Project(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template_vs2012.vcxproj') root = tree.getroot() elem = root out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') ProjectFiles = [] # add "*.c or *.h" files VS2012_CreateFilter(script, project_path) # add "*.c" files for group in script: VS_add_ItemGroup(elem, 'C', group['src'], project_path) # add "*.h" files VS_add_HeadFiles(program, elem, project_path) # write head include path if building.Env.has_key('CPPPATH'): cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() cpp_path = ';'.join(paths) + ';%(AdditionalIncludeDirectories)' # write include path for elem in tree.iter(tag='AdditionalIncludeDirectories'): elem.text = cpp_path break # write cppdefinitons flags if building.Env.has_key('CPPDEFINES'): for elem in tree.iter(tag='PreprocessorDefinitions'): definitions = ';'.join( building.Env['CPPDEFINES']) + ';%(PreprocessorDefinitions)' elem.text = definitions break # write link flags # write lib dependence (Link) if building.Env.has_key('LIBS'): for elem in tree.iter(tag='AdditionalDependencies'): libs_with_extention = [i + '.lib' for i in building.Env['LIBS']] libs = ';'.join(libs_with_extention) + ';%(AdditionalDependencies)' elem.text = libs break # write lib include path if building.Env.has_key('LIBPATH'): lib_path = building.Env['LIBPATH'] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) paths = [i for i in paths] paths.sort() lib_paths = ';'.join(paths) + ';%(AdditionalLibraryDirectories)' for elem in tree.iter(tag='AdditionalLibraryDirectories'): elem.text = lib_paths break xml_indent(root) vcxproj_string = etree.tostring(root, encoding='utf-8') root_node = r'<Project DefaultTargets="Build" ToolsVersion="4.0">' out.write( r'<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' ) out.write(vcxproj_string[len(root_node):]) out.close() xml_indent(filter_project) filter_string = etree.tostring(filter_project, encoding='utf-8') out = file('project.vcxproj.filters', 'wb') out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') root_node = r'<Project ToolsVersion="4.0">' out.write( r'<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' ) out.write(filter_string[len(root_node):]) out.close()
def MDK4Project(target, script): project_path = os.path.dirname(os.path.abspath(target)) project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt') if os.path.isfile(project_uvopt): os.unlink(project_uvopt) tree = etree.parse('template.uvproj') root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' ProjectFiles = [] # add group groups = tree.find('Targets/Target/Groups') if groups is None: groups = SubElement(tree.find('Targets/Target'), 'Groups') for group in script: group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: if CPPPATH: CPPPATH += group['CPPPATH'] else: CPPPATH += group['CPPPATH'] # get each group's definitions if group.has_key('CPPDEFINES') and group['CPPDEFINES']: if CPPDEFINES: CPPDEFINES += group['CPPDEFINES'] else: CPPDEFINES += group['CPPDEFINES'] # get each group's link flags if group.has_key('LINKFLAGS') and group['LINKFLAGS']: if LINKFLAGS: LINKFLAGS += ' ' + group['LINKFLAGS'] else: LINKFLAGS += group['LINKFLAGS'] if group.has_key('LIBS') and group['LIBS']: for item in group['LIBS']: lib_path = '' for path_item in group['LIBPATH']: full_path = os.path.join(path_item, item + '.lib') if os.path.isfile(full_path): # has this library lib_path = full_path if lib_path != '': MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) # remove repeat path paths = set() for path in CPPPATH: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() CPPPATH = string.join(paths, ';') definitions = [i for i in set(CPPDEFINES)] CPPDEFINES = string.join(definitions, ', ') # write include path, definitions and link flags IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') IncludePath.text = CPPPATH Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') Define.text = CPPDEFINES Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') Misc.text = LINKFLAGS xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def singleNode(self, indexnumber, tagname, mediatype, itemtype): tagname = tagname.encode('utf-8') cleantagname = self.normalize_nodes(tagname) nodepath = xbmc.translatePath( "special://profile/library/video/").decode('utf-8') nodeXML = "%semby_%s.xml" % (nodepath, cleantagname) path = "library://video/emby_%s.xml" % cleantagname windowpath = "ActivateWindow(Videos,%s,return)" % path # Create the video node directory if not xbmcvfs.exists(nodepath): # We need to copy over the default items shutil.copytree( src=xbmc.translatePath( "special://xbmc/system/library/video").decode('utf-8'), dst=xbmc.translatePath( "special://profile/library/video").decode('utf-8')) xbmcvfs.exists(path) labels = { 'Favorite movies': 30180, 'Favorite tvshows': 30181, 'Favorite episodes': 30182, 'channels': 30173 } label = lang(labels[tagname]) embynode = "Emby.nodes.%s" % indexnumber window('%s.title' % embynode, value=label) window('%s.path' % embynode, value=windowpath) window('%s.content' % embynode, value=path) window('%s.type' % embynode, value=itemtype) if xbmcvfs.exists(nodeXML): # Don't recreate xml if already exists return if itemtype == "channels": root = self.commonRoot(order=1, label=label, tagname=tagname, roottype=2) etree.SubElement( root, 'path').text = "plugin://emby.for.kodi/?id=0&mode=channels" elif itemtype == "favourites" and mediatype == "episodes": root = self.commonRoot(order=1, label=label, tagname=tagname, roottype=2) etree.SubElement( root, 'path' ).text = "plugin://emby.for.kodi/?id=%s&mode=browsecontent&type=%s&folderid=favepisodes" % ( tagname, mediatype) else: root = self.commonRoot(order=1, label=label, tagname=tagname) etree.SubElement(root, 'order', { 'direction': "ascending" }).text = "sorttitle" etree.SubElement(root, 'content').text = mediatype try: xml_indent(root) except: pass etree.ElementTree(root).write(nodeXML)
def viewNode(self, indexnumber, tagname, mediatype, viewtype, viewid, delete=False): if viewtype == "mixed": dirname = "%s - %s" % (viewid, mediatype) else: dirname = viewid nodepath = xbmc.translatePath( "special://profile/library/video/emby/%s/" % dirname).decode('utf-8') if delete: dirs, files = xbmcvfs.listdir(nodepath) for file in files: xbmcvfs.delete(nodepath + file) log.info("Sucessfully removed videonode: %s." % tagname) return # Verify the video directory path = xbmc.translatePath("special://profile/library/video/").decode( 'utf-8') if not xbmcvfs.exists(path): try: shutil.copytree( src=xbmc.translatePath( "special://xbmc/system/library/video").decode('utf-8'), dst=xbmc.translatePath( "special://profile/library/video").decode('utf-8')) except Exception as error: log.error(error) xbmcvfs.mkdir(path) embypath = xbmc.translatePath( "special://profile/library/video/emby/").decode('utf-8') if not xbmcvfs.exists(embypath): xbmcvfs.mkdir(embypath) root = self.commonRoot(order=0, label="Emby", roottype=0) try: xml_indent(root) except: pass etree.ElementTree(root).write(os.path.join(embypath, "index.xml")) # Create the node directory if not xbmcvfs.exists(nodepath) and not mediatype == "photos": # We need to copy over the default items xbmcvfs.mkdir(nodepath) # Create index entry nodeXML = "%sindex.xml" % nodepath # Set windows property path = "library://video/emby/%s/" % dirname for i in range(1, indexnumber): # Verify to make sure we don't create duplicates if window('Emby.nodes.%s.index' % i) == path: return if mediatype == "photos": path = "plugin://emby.for.kodi/?id=%s&mode=getsubfolders" % indexnumber window('Emby.nodes.%s.index' % indexnumber, value=path) # Root if not mediatype == "photos": if viewtype == "mixed": specialtag = "%s - %s" % (tagname, mediatype) root = self.commonRoot(order=0, label=specialtag, tagname=tagname, roottype=0) else: root = self.commonRoot(order=0, label=tagname, tagname=tagname, roottype=0) try: xml_indent(root) except: pass etree.ElementTree(root).write(nodeXML) nodetypes = { '1': "all", '2': "recent", '3': "recentepisodes", '4': "inprogress", '5': "inprogressepisodes", '6': "unwatched", '7': "nextepisodes", '8': "sets", '9': "genres", '10': "random", '11': "recommended", } mediatypes = { # label according to nodetype per mediatype 'movies': { '1': tagname, '2': 30174, '4': 30177, '6': 30189, '8': 20434, '9': 135, '10': 30229, '11': 30230 }, 'tvshows': { '1': tagname, '2': 30170, '3': 30175, '4': 30171, '5': 30178, '7': 30179, '9': 135, '10': 30229, '11': 30230 }, 'homevideos': { '1': tagname, '2': 30251, '11': 30253 }, 'photos': { '1': tagname, '2': 30252, '8': 30255, '11': 30254 }, 'musicvideos': { '1': tagname, '2': 30256, '4': 30257, '6': 30258 } } nodes = mediatypes[mediatype] for node in nodes: nodetype = nodetypes[node] nodeXML = "%s%s.xml" % (nodepath, nodetype) # Get label stringid = nodes[node] if node != "1": label = lang(stringid) if not label: label = xbmc.getLocalizedString(stringid) else: label = stringid # Set window properties if (mediatype == "homevideos" or mediatype == "photos") and nodetype == "all": # Custom query path = ( "plugin://emby.for.kodi/?id=%s&mode=browsecontent&type=%s" % (tagname, mediatype)) elif (mediatype == "homevideos" or mediatype == "photos"): # Custom query path = ( "plugin://emby.for.kodi/?id=%s&mode=browsecontent&type=%s&folderid=%s" % (tagname, mediatype, nodetype)) elif nodetype == "nextepisodes": # Custom query path = "plugin://emby.for.kodi/?id=%s&mode=nextup&limit=25" % tagname elif KODI == 14 and nodetype == "recentepisodes": # Custom query path = "plugin://emby.for.kodi/?id=%s&mode=recentepisodes&limit=25" % tagname elif KODI == 14 and nodetype == "inprogressepisodes": # Custom query path = "plugin://emby.for.kodi/?id=%s&mode=inprogressepisodes&limit=25" % tagname else: path = "library://video/emby/%s/%s.xml" % (viewid, nodetype) if mediatype == "photos": windowpath = "ActivateWindow(Pictures,%s,return)" % path else: windowpath = "ActivateWindow(Videos,%s,return)" % path if nodetype == "all": if viewtype == "mixed": templabel = "%s - %s" % (tagname, mediatype) else: templabel = label embynode = "Emby.nodes.%s" % indexnumber window('%s.title' % embynode, value=templabel) window('%s.path' % embynode, value=windowpath) window('%s.content' % embynode, value=path) window('%s.type' % embynode, value=mediatype) else: embynode = "Emby.nodes.%s.%s" % (indexnumber, nodetype) window('%s.title' % embynode, value=label) window('%s.path' % embynode, value=windowpath) window('%s.content' % embynode, value=path) if mediatype == "photos": # For photos, we do not create a node in videos but we do want the window props # to be created. # To do: add our photos nodes to kodi picture sources somehow continue if xbmcvfs.exists(nodeXML): # Don't recreate xml if already exists continue # Create the root if (nodetype == "nextepisodes" or mediatype == "homevideos" or (KODI == 14 and nodetype in ('recentepisodes', 'inprogressepisodes'))): # Folder type with plugin path root = self.commonRoot(order=node, label=label, tagname=tagname, roottype=2) etree.SubElement(root, 'path').text = path etree.SubElement(root, 'content').text = "episodes" else: root = self.commonRoot(order=node, label=label, tagname=tagname) if nodetype in ('recentepisodes', 'inprogressepisodes'): etree.SubElement(root, 'content').text = "episodes" else: etree.SubElement(root, 'content').text = mediatype limit = "25" # Elements per nodetype if nodetype == "all": etree.SubElement(root, 'order', { 'direction': "ascending" }).text = "sorttitle" elif nodetype == "recent": etree.SubElement(root, 'order', { 'direction': "descending" }).text = "dateadded" etree.SubElement(root, 'limit').text = limit rule = etree.SubElement(root, 'rule', { 'field': "playcount", 'operator': "is" }) etree.SubElement(rule, 'value').text = "0" elif nodetype == "inprogress": etree.SubElement(root, 'rule', { 'field': "inprogress", 'operator': "true" }) etree.SubElement(root, 'limit').text = limit elif nodetype == "genres": etree.SubElement(root, 'order', { 'direction': "ascending" }).text = "sorttitle" etree.SubElement(root, 'group').text = "genres" elif nodetype == "unwatched": etree.SubElement(root, 'order', { 'direction': "ascending" }).text = "sorttitle" rule = etree.SubElement(root, "rule", { 'field': "playcount", 'operator': "is" }) etree.SubElement(rule, 'value').text = "0" elif nodetype == "sets": etree.SubElement(root, 'order', { 'direction': "ascending" }).text = "sorttitle" etree.SubElement(root, 'group').text = "sets" elif nodetype == "random": etree.SubElement(root, 'order', { 'direction': "ascending" }).text = "random" etree.SubElement(root, 'limit').text = limit elif nodetype == "recommended": etree.SubElement(root, 'order', { 'direction': "descending" }).text = "rating" etree.SubElement(root, 'limit').text = limit rule = etree.SubElement(root, 'rule', { 'field': "playcount", 'operator': "is" }) etree.SubElement(rule, 'value').text = "0" rule2 = etree.SubElement(root, 'rule', attrib={ 'field': "rating", 'operator': "greaterthan" }) etree.SubElement(rule2, 'value').text = "7" elif nodetype == "recentepisodes": # Kodi Isengard, Jarvis etree.SubElement(root, 'order', { 'direction': "descending" }).text = "dateadded" etree.SubElement(root, 'limit').text = limit rule = etree.SubElement(root, 'rule', { 'field': "playcount", 'operator': "is" }) etree.SubElement(rule, 'value').text = "0" elif nodetype == "inprogressepisodes": # Kodi Isengard, Jarvis etree.SubElement(root, 'limit').text = "25" rule = etree.SubElement(root, 'rule', attrib={ 'field': "inprogress", 'operator': "true" }) try: xml_indent(root) except: pass etree.ElementTree(root).write(nodeXML)
def IARProject(target, script): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template.ewp') root = tree.getroot() out = file(target, 'wb') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' Libs = [] lib_prefix = ['lib', ''] lib_suffix = ['.a', '.o', ''] def searchLib(group): for path_item in group['LIBPATH']: for prefix_item in lib_prefix: for suffix_item in lib_suffix: lib_full_path = os.path.join( path_item, prefix_item + item + suffix_item) if os.path.isfile(lib_full_path): return lib_full_path else: return '' # add group for group in script: IARAddGroup(root, group['name'], group['src'], project_path) # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: CPPPATH += group['CPPPATH'] # get each group's definitions if group.has_key('CPPDEFINES') and group['CPPDEFINES']: CPPDEFINES += group['CPPDEFINES'] # get each group's link flags if group.has_key('LINKFLAGS') and group['LINKFLAGS']: LINKFLAGS += group['LINKFLAGS'] if group.has_key('LIBS') and group['LIBS']: for item in group['LIBS']: lib_path = searchLib(group) if lib_path != '': lib_path = _make_path_relative(project_path, lib_path) Libs += [lib_path] # print('found lib isfile: ' + lib_path) else: print('not found LIB: ' + item) # make relative path paths = set() for path in CPPPATH: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') # setting options options = tree.findall('configuration/settings/data/option') for option in options: # print option.text name = option.find('name') if name.text == 'CCIncludePath2' or name.text == 'newCCIncludePaths': for path in paths: state = SubElement(option, 'state') if os.path.isabs(path) or path.startswith('$'): state.text = path else: state.text = '$PROJ_DIR$\\' + path if name.text == 'CCDefines': for define in CPPDEFINES: state = SubElement(option, 'state') state.text = define if name.text == 'IlinkAdditionalLibs': for path in Libs: state = SubElement(option, 'state') if os.path.isabs(path) or path.startswith('$'): path = path.decode(fs_encoding) else: path = ('$PROJ_DIR$\\' + path).decode(fs_encoding) state.text = path xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() IARWorkspace(target)
def TargetEclipse(env): global source_pattern print('Update eclipse setting...') if not os.path.exists('.cproject'): print('no eclipse CDT project found!') return HandleRTTRoot(env) project = ProjectInfo(env) all_paths = [OSPath(path) for path in CollectPaths(project['DIRS'])] # print(all_paths) bsp_root = os.path.abspath(env['BSP_ROOT']) exclude_paths = ExcludePaths(bsp_root, all_paths) paths = exclude_paths exclude_paths = [] for path in paths: # add bsp and libcpu folder and not collect source files (too more files) if path.endswith('rt-thread\\bsp') or path.endswith( 'rt-thread\\libcpu'): exclude_paths += [path] continue set = CollectAllFilesinPath(path, source_pattern) if len(set): exclude_paths += [path] exclude_paths = [ _make_path_relative(bsp_root, path).replace('\\', '/') for path in exclude_paths ] env['ExPaths'] = exclude_paths all_files = CollectFiles(all_paths, source_pattern) src_files = project['FILES'] exclude_files = ExcludeFiles(all_files, src_files) exclude_files = [ _make_path_relative(bsp_root, file).replace('\\', '/') for file in exclude_files ] env['ExFiles'] = exclude_files cproject = etree.parse('.cproject') root = cproject.getroot() cconfigurations = root.findall('storageModule/cconfiguration') for cconfiguration in cconfigurations: tools = cconfiguration.findall( 'storageModule/configuration/folderInfo/toolChain/tool') HandleToolOption(tools, env) sourceEntries = cconfiguration.find( 'storageModule/configuration/sourceEntries') entry = sourceEntries.find('entry') if entry != None: sourceEntries.remove(entry) excluding = exclude_paths + exclude_files excluding = sorted(excluding) value = '' for item in excluding: if value == '': value = item else: value += '|' + item excluding = value SubElement( sourceEntries, 'entry', { 'excluding': excluding, 'flags': 'VALUE_WORKSPACE_PATH|RESOLVED', 'kind': 'sourcePath', 'name': "" }) # write back to .cproject out = open('.cproject', 'w') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n') out.write('<?fileVersion 4.0.0?>') xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() print('done!') return
def VSProject(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template_vs2005.vcproj') root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') ProjectFiles = [] # add "*.c" files group for elem in tree.iter(tag='Filter'): if elem.attrib['Name'] == 'Source Files': #print elem.tag, elem.attrib break for group in script: group_xml = VS_AddGroup(ProjectFiles, elem, group['name'], group['src'], project_path) # add "*.h" files group for elem in tree.iter(tag='Filter'): if elem.attrib['Name'] == 'Header Files': break VS_AddHeadFilesGroup(program, elem, project_path) # write head include path if building.Env.has_key('CPPPATH'): cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() cpp_path = ';'.join(paths) # write include path, definitions for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCCLCompilerTool': #print elem.tag, elem.attrib break elem.set('AdditionalIncludeDirectories', cpp_path) # write cppdefinitons flags if building.Env.has_key('CPPDEFINES'): definitions = ';'.join(building.Env['CPPDEFINES']) elem.set('PreprocessorDefinitions', definitions) # write link flags # write lib dependence if building.Env.has_key('LIBS'): for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCLinkerTool': break libs_with_extention = [i + '.lib' for i in building.Env['LIBS']] libs = ' '.join(libs_with_extention) elem.set('AdditionalDependencies', libs) # write lib include path if building.Env.has_key('LIBPATH'): lib_path = building.Env['LIBPATH'] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() lib_paths = ';'.join(paths) elem.set('AdditionalLibraryDirectories', lib_paths) xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def _CDKProject(tree, target, script): project_path = os.path.dirname(os.path.abspath(target)) root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8"?>\n') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' ProjectFiles = [] for child in root: if child.tag == 'VirtualDirectory': root.remove(child) for group in script: group_tree = SDKAddGroup(ProjectFiles, root, group['name'], group['src'], project_path) # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: if CPPPATH: CPPPATH += group['CPPPATH'] else: CPPPATH += group['CPPPATH'] # get each group's definitions if group.has_key('CPPDEFINES') and group['CPPDEFINES']: if CPPDEFINES: CPPDEFINES += group['CPPDEFINES'] else: CPPDEFINES += group['CPPDEFINES'] # get each group's cc flags if group.has_key('CCFLAGS') and group['CCFLAGS']: if CCFLAGS: CCFLAGS += ' ' + group['CCFLAGS'] else: CCFLAGS += group['CCFLAGS'] # get each group's link flags if group.has_key('LINKFLAGS') and group['LINKFLAGS']: if LINKFLAGS: LINKFLAGS += ' ' + group['LINKFLAGS'] else: LINKFLAGS += group['LINKFLAGS'] # todo: cdk add lib # write include path, definitions and link flags text = ';'.join([ _make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH ]) IncludePath = tree.find('BuildConfigs/BuildConfig/Compiler/IncludePath') IncludePath.text = text IncludePath = tree.find('BuildConfigs/BuildConfig/Asm/IncludePath') IncludePath.text = text Define = tree.find('BuildConfigs/BuildConfig/Compiler/Define') Define.text = ', '.join(set(CPPDEFINES)) CC_Misc = tree.find('BuildConfigs/BuildConfig/Compiler/OtherFlags') CC_Misc.text = CCFLAGS LK_Misc = tree.find('BuildConfigs/BuildConfig/Linker/OtherFlags') LK_Misc.text = LINKFLAGS xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def CBProject(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) if os.path.isfile('template.cbp'): tree = etree.parse('template.cbp') else: tree = etree.parse( os.path.join(os.path.dirname(__file__), 'template.cbp')) root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n') ProjectFiles = [] # SECTION 1. add "*.c|*.h" files group for elem in tree.iter(tag='Project'): # print elem.tag, elem.attrib break # add c files for group in script: group_xml = CB_AddCFiles(ProjectFiles, elem, group['name'], group['src'], project_path) # add h files CB_AddHeadFiles(program, elem, project_path) # SECTION 2. # write head include path if building.Env.has_key('CPPPATH'): cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() # write include path, definitions for elem in tree.iter(tag='Compiler'): break for path in paths: Add = SubElement(elem, 'Add') Add.set('directory', path) for macro in building.Env.get('CPPDEFINES', []): Add = SubElement(elem, 'Add') Add.set('option', "-D" + macro) # write link flags ''' # write lib dependence if building.Env.has_key('LIBS'): for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCLinkerTool': break libs_with_extention = [i+'.lib' for i in building.Env['LIBS']] libs = ' '.join(libs_with_extention) elem.set('AdditionalDependencies', libs) # write lib include path if building.Env.has_key('LIBPATH'): lib_path = building.Env['LIBPATH'] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() lib_paths = ';'.join(paths) elem.set('AdditionalLibraryDirectories', lib_paths) ''' xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def VS2012Project(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template_vs2012.vcxproj') root = tree.getroot() elem = root out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') ProjectFiles = [] # add "*.c or *.h" files VS2012_CreateFilter(script, project_path) # add "*.c" files for group in script: VS_add_ItemGroup(elem, 'C', group['src'], project_path) # add "*.h" files VS_add_HeadFiles(program, elem, project_path) # write head include path if building.Env.has_key('CPPPATH'): cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() cpp_path = ';'.join(paths) + ';%(AdditionalIncludeDirectories)' # write include path for elem in tree.iter(tag='AdditionalIncludeDirectories'): elem.text = cpp_path break # write cppdefinitons flags if building.Env.has_key('CPPDEFINES'): for elem in tree.iter(tag='PreprocessorDefinitions'): definitions = ';'.join(building.Env['CPPDEFINES']) + ';%(PreprocessorDefinitions)' elem.text = definitions break # write link flags # write lib dependence (Link) if building.Env.has_key('LIBS'): for elem in tree.iter(tag='AdditionalDependencies'): libs_with_extention = [i+'.lib' for i in building.Env['LIBS']] libs = ';'.join(libs_with_extention) + ';%(AdditionalDependencies)' elem.text = libs break # write lib include path if building.Env.has_key('LIBPATH'): lib_path = building.Env['LIBPATH'] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) paths = [i for i in paths] paths.sort() lib_paths = ';'.join(paths) + ';%(AdditionalLibraryDirectories)' for elem in tree.iter(tag='AdditionalLibraryDirectories'): elem.text = lib_paths break xml_indent(root) vcxproj_string = etree.tostring(root, encoding='utf-8') root_node=r'<Project DefaultTargets="Build" ToolsVersion="4.0">' out.write(r'<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">') out.write(vcxproj_string[len(root_node):]) out.close() xml_indent(filter_project) filter_string = etree.tostring(filter_project, encoding='utf-8') out = file('project.vcxproj.filters', 'wb') out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') root_node=r'<Project ToolsVersion="4.0">' out.write(r'<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">') out.write(filter_string[len(root_node):]) out.close()
def MDK5Project(target, script): project_path = os.path.dirname(os.path.abspath(target)) project_uvopt = os.path.abspath(target).replace('uvprojx', 'uvoptx') if os.path.isfile(project_uvopt): os.unlink(project_uvopt) tree = etree.parse('template.uvprojx') root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' ProjectFiles = [] # add group groups = tree.find('Targets/Target/Groups') if groups is None: groups = SubElement(tree.find('Targets/Target'), 'Groups') for group in script: group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: if CPPPATH: CPPPATH += group['CPPPATH'] else: CPPPATH += group['CPPPATH'] # get each group's definitions if group.has_key('CPPDEFINES') and group['CPPDEFINES']: if CPPDEFINES: CPPDEFINES += group['CPPDEFINES'] else: CPPDEFINES += group['CPPDEFINES'] # get each group's link flags if group.has_key('LINKFLAGS') and group['LINKFLAGS']: if LINKFLAGS: LINKFLAGS += ' ' + group['LINKFLAGS'] else: LINKFLAGS += group['LINKFLAGS'] if group.has_key('LIBS') and group['LIBS']: for item in group['LIBS']: lib_path = '' for path_item in group['LIBPATH']: full_path = os.path.join(path_item, item + '.lib') if os.path.isfile(full_path): # has this library lib_path = full_path if lib_path != '': MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) # remove repeat path paths = set() for path in CPPPATH: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() CPPPATH = string.join(paths, ';') definitions = [i for i in set(CPPDEFINES)] CPPDEFINES = string.join(definitions, ', ') # write include path, definitions and link flags IncludePath = tree.find( 'Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath' ) IncludePath.text = CPPPATH Define = tree.find( 'Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') Define.text = CPPDEFINES Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') Misc.text = LINKFLAGS xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close() # copy uvopt file if os.path.exists('template.uvoptx'): import shutil shutil.copy2('template.uvoptx', 'project.uvoptx')
def VSProject(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse("template_vs2005.vcproj") root = tree.getroot() out = file(target, "wb") out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') ProjectFiles = [] # add "*.c" files group for elem in tree.iter(tag="Filter"): if elem.attrib["Name"] == "Source Files": # print elem.tag, elem.attrib break for group in script: group_xml = VS_AddGroup(ProjectFiles, elem, group["name"], group["src"], project_path) # add "*.h" files group for elem in tree.iter(tag="Filter"): if elem.attrib["Name"] == "Header Files": break VS_AddHeadFilesGroup(program, elem, project_path) # write head include path if building.Env.has_key("CPPPATH"): cpp_path = building.Env["CPPPATH"] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) # .replace('\\', '/') paths = [i for i in paths] paths.sort() cpp_path = ";".join(paths) # write include path, definitions for elem in tree.iter(tag="Tool"): if elem.attrib["Name"] == "VCCLCompilerTool": # print elem.tag, elem.attrib break elem.set("AdditionalIncludeDirectories", cpp_path) # write cppdefinitons flags if building.Env.has_key("CPPDEFINES"): CPPDEFINES = building.Env["CPPDEFINES"] definitions = [] if type(CPPDEFINES[0]) == type(()): for item in CPPDEFINES: definitions += [i for i in item] definitions = ";".join(definitions) else: definitions = ";".join(building.Env["CPPDEFINES"]) elem.set("PreprocessorDefinitions", definitions) # write link flags # write lib dependence if building.Env.has_key("LIBS"): for elem in tree.iter(tag="Tool"): if elem.attrib["Name"] == "VCLinkerTool": break libs_with_extention = [i + ".lib" for i in building.Env["LIBS"]] libs = " ".join(libs_with_extention) elem.set("AdditionalDependencies", libs) # write lib include path if building.Env.has_key("LIBPATH"): lib_path = building.Env["LIBPATH"] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) # .replace('\\', '/') paths = [i for i in paths] paths.sort() lib_paths = ";".join(paths) elem.set("AdditionalLibraryDirectories", lib_paths) xml_indent(root) out.write(etree.tostring(root, encoding="utf-8")) out.close()
def TargetCodelite(script, program): project_name = os.path.abspath('.').replace('\\', '/').split('/')[-1] #project_name.replace('-', '_') project_path = os.path.abspath('.') CLGenWorkspace(project_name, project_path) if os.path.isfile('codelite_template.project'): tree = etree.parse('codelite_template.project') else: tree = etree.parse( os.path.join(os.path.dirname(__file__), 'codelite_template.project')) root = tree.getroot() root.attrib['Name'] = project_name out = open(project_name + '.project', 'w') out.write('<?xml version="1.0" encoding="UTF-8"?>\n') # add files for group in script: CLAddCFiles(root, group['src'], project_path) # add header file CLAddHeaderFiles(root, program, project_path) # SECTION 2. # write head include path if 'CPPPATH' in building.Env: cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() # write include path, definitions for elem in tree.iter(tag='Compiler'): break for path in paths: CLAddIncludePath(root, path) #print building.Env.get('LIBPATH', []) #print building.Env.get('LIBS', []) CLSetCFlags(root, building.Env.get('CFLAGS', [])) CLSetCxxFlags(root, building.Env.get('CFLAGS', [])) asflags = building.Env.get('ASFLAGS', []) asflags = asflags.replace('-ffunction-sections', '') asflags = asflags.replace('-fdata-sections', '') asflags = asflags.replace('-x', '') asflags = asflags.replace('-Wa,', '') asflags = asflags.replace('assembler-with-cpp', '') CLSetAsFlags(root, asflags) CLSetLdFlags(root, building.Env.get('LINKFLAGS', [])) for macro in building.Env.get('CPPDEFINES', []): for d in macro: CLAddPreprocessor(root, d) xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def MDK5Project(target, script): project_path = os.path.dirname(os.path.abspath(target)) project_uvopt = os.path.abspath(target).replace("uvprojx", "uvoptx") if os.path.isfile(project_uvopt): os.unlink(project_uvopt) tree = etree.parse("template.uvprojx") root = tree.getroot() out = file(target, "wb") out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = "" CCFLAGS = "" ProjectFiles = [] # add group groups = tree.find("Targets/Target/Groups") if groups is None: groups = SubElement(tree.find("Targets/Target"), "Groups") for group in script: group_xml = MDK4AddGroup(ProjectFiles, groups, group["name"], group["src"], project_path) # get each include path if group.has_key("CPPPATH") and group["CPPPATH"]: if CPPPATH: CPPPATH += group["CPPPATH"] else: CPPPATH += group["CPPPATH"] # get each group's definitions if group.has_key("CPPDEFINES") and group["CPPDEFINES"]: if CPPDEFINES: CPPDEFINES += group["CPPDEFINES"] else: CPPDEFINES += group["CPPDEFINES"] # get each group's link flags if group.has_key("LINKFLAGS") and group["LINKFLAGS"]: if LINKFLAGS: LINKFLAGS += " " + group["LINKFLAGS"] else: LINKFLAGS += group["LINKFLAGS"] if group.has_key("LIBS") and group["LIBS"]: for item in group["LIBS"]: lib_path = "" for path_item in group["LIBPATH"]: full_path = os.path.join(path_item, item + ".lib") if os.path.isfile(full_path): # has this library lib_path = full_path if lib_path != "": MDK4AddGroupForFN(ProjectFiles, groups, group["name"], lib_path, project_path) # remove repeat path paths = set() for path in CPPPATH: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) # .replace('\\', '/') paths = [i for i in paths] paths.sort() CPPPATH = string.join(paths, ";") definitions = [i for i in set(CPPDEFINES)] CPPDEFINES = string.join(definitions, ", ") # write include path, definitions and link flags IncludePath = tree.find("Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath") IncludePath.text = CPPPATH Define = tree.find("Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define") Define.text = CPPDEFINES Misc = tree.find("Targets/Target/TargetOption/TargetArmAds/LDads/Misc") Misc.text = LINKFLAGS xml_indent(root) out.write(etree.tostring(root, encoding="utf-8")) out.close() # copy uvopt file if os.path.exists("template.uvoptx"): import shutil shutil.copy2("template.uvoptx", "project.uvoptx")
def MDK45Project(tree, target, script): project_path = os.path.dirname(os.path.abspath(target)) root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n') CPPPATH = [] CPPDEFINES = [] LINKFLAGS = '' CCFLAGS = '' ProjectFiles = [] # add group groups = tree.find('Targets/Target/Groups') if groups is None: groups = SubElement(tree.find('Targets/Target'), 'Groups') groups.clear() # clean old groups for group in script: group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) # for local CPPPATH/CPPDEFINES if (group_tree != None) and (group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CCFLAGS')): GroupOption = SubElement(group_tree, 'GroupOption') GroupArmAds = SubElement(GroupOption, 'GroupArmAds') Cads = SubElement(GroupArmAds, 'Cads') VariousControls = SubElement(Cads, 'VariousControls') MiscControls = SubElement(VariousControls, 'MiscControls') if group.has_key('LOCAL_CCFLAGS'): MiscControls.text = group['LOCAL_CCFLAGS'] else: MiscControls.text = ' ' Define = SubElement(VariousControls, 'Define') if group.has_key('LOCAL_CPPDEFINES'): Define.text = ', '.join(set(group['LOCAL_CPPDEFINES'])) else: Define.text = ' ' Undefine = SubElement(VariousControls, 'Undefine') Undefine.text = ' ' IncludePath = SubElement(VariousControls, 'IncludePath') if group.has_key('LOCAL_CPPPATH'): IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in group['LOCAL_CPPPATH']]) else: IncludePath.text = ' ' # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: if CPPPATH: CPPPATH += group['CPPPATH'] else: CPPPATH += group['CPPPATH'] # get each group's definitions if group.has_key('CPPDEFINES') and group['CPPDEFINES']: if CPPDEFINES: CPPDEFINES += group['CPPDEFINES'] else: CPPDEFINES += group['CPPDEFINES'] # get each group's link flags if group.has_key('LINKFLAGS') and group['LINKFLAGS']: if LINKFLAGS: LINKFLAGS += ' ' + group['LINKFLAGS'] else: LINKFLAGS += group['LINKFLAGS'] if group.has_key('LIBS') and group['LIBS']: for item in group['LIBS']: lib_path = '' for path_item in group['LIBPATH']: full_path = os.path.join(path_item, item + '.lib') if os.path.isfile(full_path): # has this library lib_path = full_path if lib_path != '': if (group_tree != None): MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path) else: MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) # write include path, definitions and link flags IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH]) Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') Define.text = ', '.join(set(CPPDEFINES)) Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') Misc.text = LINKFLAGS xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()
def viewNode(self, indexnumber, tagname, mediatype, viewtype, viewid, delete=False): if viewtype == "mixed": dirname = "%s - %s" % (viewid, mediatype) else: dirname = viewid nodepath = xbmc.translatePath( "special://profile/library/video/emby/%s/" % dirname).decode('utf-8') if delete: dirs, files = xbmcvfs.listdir(nodepath) for file in files: xbmcvfs.delete(nodepath + file) log.info("Sucessfully removed videonode: %s." % tagname) return # Verify the video directory path = xbmc.translatePath("special://profile/library/video/").decode('utf-8') if not xbmcvfs.exists(path): try: shutil.copytree( src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'), dst=xbmc.translatePath("special://profile/library/video").decode('utf-8')) except Exception as error: log.error(error) xbmcvfs.mkdir(path) embypath = xbmc.translatePath("special://profile/library/video/emby/").decode('utf-8') if not xbmcvfs.exists(embypath): xbmcvfs.mkdir(embypath) root = self.commonRoot(order=0, label="Emby", roottype=0) try: xml_indent(root) except: pass etree.ElementTree(root).write(os.path.join(embypath, "index.xml")) # Create the node directory if not xbmcvfs.exists(nodepath) and not mediatype == "photos": # We need to copy over the default items xbmcvfs.mkdir(nodepath) # Create index entry nodeXML = "%sindex.xml" % nodepath # Set windows property path = "library://video/emby/%s/" % dirname for i in range(1, indexnumber): # Verify to make sure we don't create duplicates if window('Emby.nodes.%s.index' % i) == path: return if mediatype == "photos": path = "plugin://plugin.video.emby/?id=%s&mode=getsubfolders" % indexnumber window('Emby.nodes.%s.index' % indexnumber, value=path) # Root if not mediatype == "photos": if viewtype == "mixed": specialtag = "%s - %s" % (tagname, mediatype) root = self.commonRoot(order=0, label=specialtag, tagname=tagname, roottype=0) else: root = self.commonRoot(order=0, label=tagname, tagname=tagname, roottype=0) try: xml_indent(root) except: pass etree.ElementTree(root).write(nodeXML) nodetypes = { '1': "all", '2': "recent", '3': "recentepisodes", '4': "inprogress", '5': "inprogressepisodes", '6': "unwatched", '7': "nextepisodes", '8': "sets", '9': "genres", '10': "random", '11': "recommended", } mediatypes = { # label according to nodetype per mediatype 'movies': { '1': tagname, '2': 30174, '4': 30177, '6': 30189, '8': 20434, '9': 135, '10': 30229, '11': 30230 }, 'tvshows': { '1': tagname, '2': 30170, '3': 30175, '4': 30171, '5': 30178, '7': 30179, '9': 135, '10': 30229, '11': 30230 }, 'homevideos': { '1': tagname, '2': 30251, '11': 30253 }, 'photos': { '1': tagname, '2': 30252, '8': 30255, '11': 30254 }, 'musicvideos': { '1': tagname, '2': 30256, '4': 30257, '6': 30258 } } nodes = mediatypes[mediatype] for node in nodes: nodetype = nodetypes[node] nodeXML = "%s%s.xml" % (nodepath, nodetype) # Get label stringid = nodes[node] if node != "1": label = lang(stringid) if not label: label = xbmc.getLocalizedString(stringid) else: label = stringid # Set window properties if (mediatype == "homevideos" or mediatype == "photos") and nodetype == "all": # Custom query path = ("plugin://plugin.video.emby/?id=%s&mode=browsecontent&type=%s" % (tagname, mediatype)) elif (mediatype == "homevideos" or mediatype == "photos"): # Custom query path = ("plugin://plugin.video.emby/?id=%s&mode=browsecontent&type=%s&folderid=%s" % (tagname, mediatype, nodetype)) elif nodetype == "nextepisodes": # Custom query path = "plugin://plugin.video.emby/?id=%s&mode=nextup&limit=25" % tagname elif KODI == 14 and nodetype == "recentepisodes": # Custom query path = "plugin://plugin.video.emby/?id=%s&mode=recentepisodes&limit=25" % tagname elif KODI == 14 and nodetype == "inprogressepisodes": # Custom query path = "plugin://plugin.video.emby/?id=%s&mode=inprogressepisodes&limit=25"% tagname else: path = "library://video/emby/%s/%s.xml" % (viewid, nodetype) if mediatype == "photos": windowpath = "ActivateWindow(Pictures,%s,return)" % path else: windowpath = "ActivateWindow(Videos,%s,return)" % path if nodetype == "all": if viewtype == "mixed": templabel = "%s - %s" % (tagname, mediatype) else: templabel = label embynode = "Emby.nodes.%s" % indexnumber window('%s.title' % embynode, value=templabel) window('%s.path' % embynode, value=windowpath) window('%s.content' % embynode, value=path) window('%s.type' % embynode, value=mediatype) else: embynode = "Emby.nodes.%s.%s" % (indexnumber, nodetype) window('%s.title' % embynode, value=label) window('%s.path' % embynode, value=windowpath) window('%s.content' % embynode, value=path) if mediatype == "photos": # For photos, we do not create a node in videos but we do want the window props # to be created. # To do: add our photos nodes to kodi picture sources somehow continue if xbmcvfs.exists(nodeXML): # Don't recreate xml if already exists continue # Create the root if (nodetype == "nextepisodes" or mediatype == "homevideos" or (KODI == 14 and nodetype in ('recentepisodes', 'inprogressepisodes'))): # Folder type with plugin path root = self.commonRoot(order=node, label=label, tagname=tagname, roottype=2) etree.SubElement(root, 'path').text = path etree.SubElement(root, 'content').text = "episodes" else: root = self.commonRoot(order=node, label=label, tagname=tagname) if nodetype in ('recentepisodes', 'inprogressepisodes'): etree.SubElement(root, 'content').text = "episodes" else: etree.SubElement(root, 'content').text = mediatype limit = "25" # Elements per nodetype if nodetype == "all": etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle" elif nodetype == "recent": etree.SubElement(root, 'order', {'direction': "descending"}).text = "dateadded" etree.SubElement(root, 'limit').text = limit rule = etree.SubElement(root, 'rule', {'field': "playcount", 'operator': "is"}) etree.SubElement(rule, 'value').text = "0" elif nodetype == "inprogress": etree.SubElement(root, 'rule', {'field': "inprogress", 'operator': "true"}) etree.SubElement(root, 'limit').text = limit elif nodetype == "genres": etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle" etree.SubElement(root, 'group').text = "genres" elif nodetype == "unwatched": etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle" rule = etree.SubElement(root, "rule", {'field': "playcount", 'operator': "is"}) etree.SubElement(rule, 'value').text = "0" elif nodetype == "sets": etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle" etree.SubElement(root, 'group').text = "sets" elif nodetype == "random": etree.SubElement(root, 'order', {'direction': "ascending"}).text = "random" etree.SubElement(root, 'limit').text = limit elif nodetype == "recommended": etree.SubElement(root, 'order', {'direction': "descending"}).text = "rating" etree.SubElement(root, 'limit').text = limit rule = etree.SubElement(root, 'rule', {'field': "playcount", 'operator': "is"}) etree.SubElement(rule, 'value').text = "0" rule2 = etree.SubElement(root, 'rule', attrib={'field': "rating", 'operator': "greaterthan"}) etree.SubElement(rule2, 'value').text = "7" elif nodetype == "recentepisodes": # Kodi Isengard, Jarvis etree.SubElement(root, 'order', {'direction': "descending"}).text = "dateadded" etree.SubElement(root, 'limit').text = limit rule = etree.SubElement(root, 'rule', {'field': "playcount", 'operator': "is"}) etree.SubElement(rule, 'value').text = "0" elif nodetype == "inprogressepisodes": # Kodi Isengard, Jarvis etree.SubElement(root, 'limit').text = "25" rule = etree.SubElement(root, 'rule', attrib={'field': "inprogress", 'operator':"true"}) try: xml_indent(root) except: pass etree.ElementTree(root).write(nodeXML)
def VSProject(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template_vs2005.vcproj') root = tree.getroot() out = open(target, 'w') out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') ProjectFiles = [] # add "*.c" files group for elem in tree.iter(tag='Filter'): if elem.attrib['Name'] == 'Source Files': #print elem.tag, elem.attrib break for group in script: libs = [] if 'LIBS' in group and group['LIBS']: for item in group['LIBS']: lib_path = '' for path_item in group['LIBPATH']: full_path = os.path.join(path_item, item + '.lib') if os.path.isfile(full_path): # has this library lib_path = full_path if lib_path != '': libs.append(lib_path) group_xml = VS_AddGroup(ProjectFiles, elem, group['name'], group['src'], libs, project_path) # add "*.h" files group for elem in tree.iter(tag='Filter'): if elem.attrib['Name'] == 'Header Files': break VS_AddHeadFilesGroup(program, elem, project_path) # write head include path if 'CPPPATH' in building.Env: cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() cpp_path = ';'.join(paths) # write include path, definitions for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCCLCompilerTool': #print elem.tag, elem.attrib break elem.set('AdditionalIncludeDirectories', cpp_path) # write cppdefinitons flags if 'CPPDEFINES' in building.Env: CPPDEFINES = building.Env['CPPDEFINES'] definitions = [] if type(CPPDEFINES[0]) == type(()): for item in CPPDEFINES: definitions += [i for i in item] definitions = ';'.join(definitions) else: definitions = ';'.join(building.Env['CPPDEFINES']) elem.set('PreprocessorDefinitions', definitions) # write link flags # write lib dependence if 'LIBS' in building.Env: for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCLinkerTool': break libs_with_extention = [i + '.lib' for i in building.Env['LIBS']] libs = ' '.join(libs_with_extention) elem.set('AdditionalDependencies', libs) # write lib include path if 'LIBPATH' in building.Env: lib_path = building.Env['LIBPATH'] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() lib_paths = ';'.join(paths) elem.set('AdditionalLibraryDirectories', lib_paths) xml_indent(root) text = etree.tostring(root, encoding='utf-8') try: text = text.decode(encoding="utf-8") except: text = text out.write(text) out.close()
def VSProject(target, script, program): project_path = os.path.dirname(os.path.abspath(target)) tree = etree.parse('template_vs2005.vcproj') root = tree.getroot() out = file(target, 'wb') out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n') ProjectFiles = [] # add "*.c" files group for elem in tree.iter(tag='Filter'): if elem.attrib['Name'] == 'Source Files': #print elem.tag, elem.attrib break for group in script: group_xml = VS_AddGroup(ProjectFiles, elem, group['name'], group['src'], project_path) # add "*.h" files group for elem in tree.iter(tag='Filter'): if elem.attrib['Name'] == 'Header Files': break VS_AddHeadFilesGroup(program, elem, project_path) # write head include path if building.Env.has_key('CPPPATH'): cpp_path = building.Env['CPPPATH'] paths = set() for path in cpp_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() cpp_path = ';'.join(paths) # write include path, definitions for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCCLCompilerTool': #print elem.tag, elem.attrib break elem.set('AdditionalIncludeDirectories', cpp_path) # write cppdefinitons flags if building.Env.has_key('CPPDEFINES'): definitions = ';'.join(building.Env['CPPDEFINES']) elem.set('PreprocessorDefinitions', definitions) # write link flags # write lib dependence if building.Env.has_key('LIBS'): for elem in tree.iter(tag='Tool'): if elem.attrib['Name'] == 'VCLinkerTool': break libs_with_extention = [i+'.lib' for i in building.Env['LIBS']] libs = ' '.join(libs_with_extention) elem.set('AdditionalDependencies', libs) # write lib include path if building.Env.has_key('LIBPATH'): lib_path = building.Env['LIBPATH'] paths = set() for path in lib_path: inc = _make_path_relative(project_path, os.path.normpath(path)) paths.add(inc) #.replace('\\', '/') paths = [i for i in paths] paths.sort() lib_paths = ';'.join(paths) elem.set('AdditionalLibraryDirectories', lib_paths) xml_indent(root) out.write(etree.tostring(root, encoding='utf-8')) out.close()