예제 #1
0
def getActionppArgs(modelDir,targetDir,options):
    if options.actionpp_args:
        return options.actionpp_args
    mddFile = getMddFileWithPath(modelDir)
    reader = Reader(mddFile)
    targets = getTargetDevices(modelDir,options)
    actionpp_args = ""
    tdFiles = getTdFilesWithPath(targetDir,options)
    for d,l,p in targets:
        devices = reader.getValue('devices',[p]).split('\n')
        for tdFile in tdFiles:
            for device in devices:
                if tdFile.endswith(urllib.quote(device) + ".td"):
                    try:
                        handle = open(tdFile,'r')
                        contents = handle.readline()
                    finally:
                        if handle:
                            handle.close()
                            handle = None

                    log_cmp = datareader.getDataInfo(contents)[0]
                    if l == log_cmp:        
                        locales = reader.getValue('locales',[p]).split('\n')
                        actionpp_args += "file:%s:%s.csv," % (tdFile,os.path.join(targetDir,p))
                        d_quot = urllib.quote(d)
                        if d_quot in options.devices and options.devices[d_quot] not in locales and options.devices[d_quot].strip() != '':
                            raise RunModelPackageFailed(
                                "Unknown locale '%s' for device '%s'" % (options.devices[d_quot],d))
                        elif d_quot in options.devices and options.devices[d_quot].strip() != '':
                            actionpp_args += "lang:%s:%s," % (tdFile,options.devices[d_quot])
                        else:
                            actionpp_args += "lang:%s:%s," % (tdFile,locales[0])

    return actionpp_args
예제 #2
0
	def __get_logicalname(self, params):
		if len(params) < 1:
			raise Reader.Error("Logical name query requires as an additional parameter the name of a data table.")
		elif len(params) > 1:
			raise Reader.Error("Logical name query does not accept more than one additional parameter.")

		for dt in self.__mdd[mddParser.DATATABLES].itervalues():
			if dt[mddParser.E_F_NAME] == params[0]:
				datatable = dt
				break
		else:
			raise Reader.Error("Unknown data table '%s'." % params[0])

		path = self.__directory + self.__id2filename(params[0]) + '.' + Reader.__suffixes[datatable[mddParser.E_F_MODEL]]
		try:
			f = file(path)
		except IOError:
			raise Reader.Error("Cannot open file '%s'." % path)
		try:
			line = f.readline()
		finally:
			f.close()

#		return line.split(':',1)[0].split('(',1)[0].strip()
		return datareader.getDataInfo(line)[0]
예제 #3
0
    def __get_logicalname(self, params):
        if len(params) < 1:
            raise Reader.Error(
                "Logical name query requires as an additional parameter the name of a data table."
            )
        elif len(params) > 1:
            raise Reader.Error(
                "Logical name query does not accept more than one additional parameter."
            )

        for dt in self.__mdd[mddParser.DATATABLES].itervalues():
            if dt[mddParser.E_F_NAME] == params[0]:
                datatable = dt
                break
        else:
            raise Reader.Error("Unknown data table '%s'." % params[0])

        path = self.__directory + self.__id2filename(
            params[0]) + '.' + Reader.__suffixes[datatable[
                mddParser.E_F_MODEL]]
        try:
            f = file(path)
        except IOError:
            raise Reader.Error("Cannot open file '%s'." % path)
        try:
            line = f.readline()
        finally:
            f.close()

#		return line.split(':',1)[0].split('(',1)[0].strip()
        return datareader.getDataInfo(line)[0]
예제 #4
0
    def __get_datacomment(self, params):
        if len(params) < 1:
            raise Reader.Error(
                "Data comment query requires as an additional parameter the name of a data table."
            )
        elif len(params) > 1:
            raise Reader.Error(
                "Data comment query does not accept more than one additional parameter."
            )

        for dt in self.__mdd[mddParser.DATATABLES].itervalues():
            if dt[mddParser.E_F_NAME] == params[0]:
                datatable = dt
                break
        else:
            raise Reader.Error("Unknown data table '%s'." % params[0])

        path = self.__directory + self.__id2filename(
            params[0]) + '.' + Reader.__suffixes[datatable[
                mddParser.E_F_MODEL]]
        try:
            f = file(path)
        except IOError:
            raise Reader.Error("Cannot open file '%s'." % path)
        try:
            line = f.readline()
        finally:
            f.close()


#		i = 0
#		while i < len(line):
#			for separator in ('"""', '"', "'"):
#				if line[i:i+len(separator)] == separator:
#					j = i + len(separator)
#					while j < len(line):
#						if line[j] == '\\':
#							j = j+1
#						elif line[j:j+len(separator)] == separator:
#							i = j + len(separator) - 1
#							break
#						j = j+1
#					else:
#						raise Reader.Error("Cannot parse file '%s'." % path)
#					break
#
#			else:
#				if line[i] == '#':
#					return line[i+1:].strip()
#
#			i = i+1
#
#		return ""

        return datareader.getDataInfo(line)[1]
예제 #5
0
	def __get_datacomment(self, params):
		if len(params) < 1:
			raise Reader.Error("Data comment query requires as an additional parameter the name of a data table.")
		elif len(params) > 1:
			raise Reader.Error("Data comment query does not accept more than one additional parameter.")

		for dt in self.__mdd[mddParser.DATATABLES].itervalues():
			if dt[mddParser.E_F_NAME] == params[0]:
				datatable = dt
				break
		else:
			raise Reader.Error("Unknown data table '%s'." % params[0])

		path = self.__directory + self.__id2filename(params[0]) + '.' + Reader.__suffixes[datatable[mddParser.E_F_MODEL]]
		try:
			f = file(path)
		except IOError:
			raise Reader.Error("Cannot open file '%s'." % path)
		try:
			line = f.readline()
		finally:
			f.close()

#		i = 0
#		while i < len(line):
#			for separator in ('"""', '"', "'"):
#				if line[i:i+len(separator)] == separator:
#					j = i + len(separator)
#					while j < len(line):
#						if line[j] == '\\':
#							j = j+1
#						elif line[j:j+len(separator)] == separator:
#							i = j + len(separator) - 1
#							break
#						j = j+1
#					else:
#						raise Reader.Error("Cannot parse file '%s'." % path)
#					break
#
#			else:
#				if line[i] == '#':
#					return line[i+1:].strip()
#
#			i = i+1
#
#		return ""

		return datareader.getDataInfo(line)[1]
예제 #6
0
def targetDevicesAllowedByOptions(modelDir,allTargets,options):
    logicalnames = []
    selectedProducts = []

    if options.devices:
        allowedDevices = options.devices.keys()
    else:
        allowedDevices = None
    if options.products:
        allowedProducts = options.products.split() 
    else:
        allowedProducts = None

    chosen = []
    for d,p in allTargets:
        if allowedDevices and urllib.quote(d) not in allowedDevices:
            continue
        if allowedProducts and urllib.quote(p) not in allowedProducts:
            continue
        if isExcluded(d,options.exclude):
            continue

        # Options deviceperproduct and devices are mutually exclusive so we
        # don't need to check for that
        if options.deviceperproduct and p in selectedProducts:
            continue
            
        
        handle = None
        try:
            handle = open(os.path.join(modelDir,urllib.quote(d)) + ".td")
            contents = handle.readline()
        finally:
            if handle:
                handle.close()

        l = datareader.getDataInfo(contents)[0]
        if l in logicalnames:
            continue
        
        chosen.append( (d,l,p) )
        logicalnames.append(l)
        selectedProducts.append(p)
    return chosen
예제 #7
0
def targetDevicesAllowedByOptions(modelDir, allTargets, options):
    logicalnames = []
    selectedProducts = []

    if options.devices:
        allowedDevices = options.devices.keys()
    else:
        allowedDevices = None
    if options.products:
        allowedProducts = options.products.split()
    else:
        allowedProducts = None

    chosen = []
    for d, p in allTargets:
        if allowedDevices and urllib.quote(d) not in allowedDevices:
            continue
        if allowedProducts and urllib.quote(p) not in allowedProducts:
            continue
        if isExcluded(d, options.exclude):
            continue

        # Options deviceperproduct and devices are mutually exclusive so we
        # don't need to check for that
        if options.deviceperproduct and p in selectedProducts:
            continue

        handle = None
        try:
            handle = open(os.path.join(modelDir, urllib.quote(d)) + ".td")
            contents = handle.readline()
        finally:
            if handle:
                handle.close()

        l = datareader.getDataInfo(contents)[0]
        if l in logicalnames:
            continue

        chosen.append((d, l, p))
        logicalnames.append(l)
        selectedProducts.append(p)
    return chosen
예제 #8
0
def getActionppArgs(modelDir, targetDir, options):
    if options.actionpp_args:
        return options.actionpp_args
    mddFile = getMddFileWithPath(modelDir)
    reader = Reader(mddFile)
    targets = getTargetDevices(modelDir, options)
    actionpp_args = ""
    tdFiles = getTdFilesWithPath(targetDir, options)
    for d, l, p in targets:
        devices = reader.getValue("devices", [p]).split("\n")
        for tdFile in tdFiles:
            for device in devices:
                if tdFile.endswith(urllib.quote(device) + ".td"):
                    try:
                        handle = open(tdFile, "r")
                        contents = handle.readline()
                    finally:
                        if handle:
                            handle.close()
                            handle = None

                    log_cmp = datareader.getDataInfo(contents)[0]
                    if l == log_cmp:
                        locales = reader.getValue("locales", [p]).split("\n")
                        actionpp_args += "file:%s:%s.csv," % (tdFile, os.path.join(targetDir, p))
                        d_quot = urllib.quote(d)
                        if (
                            d_quot in options.devices
                            and options.devices[d_quot] not in locales
                            and options.devices[d_quot].strip() != ""
                        ):
                            raise RunModelPackageFailed(
                                "Unknown locale '%s' for device '%s'" % (options.devices[d_quot], d)
                            )
                        elif d_quot in options.devices and options.devices[d_quot].strip() != "":
                            actionpp_args += "lang:%s:%s," % (tdFile, options.devices[d_quot])
                        else:
                            actionpp_args += "lang:%s:%s," % (tdFile, locales[0])

    return actionpp_args
예제 #9
0
def excludeDevices(dirName, tdFiles, options):
    if options.devices:
        allowedDevices = options.devices.keys()
    else:
        allowedDevices = []

    chosen = {}
    handle = None
    for tdFile in tdFiles:
        try:
            handle = open(os.path.join(dirName, tdFile), "r")
            contents = handle.readline()
        finally:
            if handle:
                handle.close()
                handle = None

        l = datareader.getDataInfo(contents)[0]
        if l in chosen and tdFile[:-3] not in allowedDevices:
            continue

        chosen[l] = tdFile

    return chosen.values()
예제 #10
0
def excludeDevices(dirName,tdFiles,options):
    if options.devices:
        allowedDevices = options.devices.keys()
    else:
        allowedDevices = []

    chosen = {}
    handle = None
    for tdFile in tdFiles:
        try:
            handle = open(os.path.join(dirName,tdFile),'r')
            contents = handle.readline()
        finally:
            if handle:
                handle.close()
                handle = None

        l = datareader.getDataInfo(contents)[0]
        if l in chosen and tdFile[:-3] not in allowedDevices:
            continue
        
        chosen[l]=tdFile
            
    return chosen.values()