예제 #1
0
    def readtime(what, alt=readdate,
                 getdate=withlocale(locale.LC_TIME, "nb_NO")(readdate),
                 today=datetime.date.today, parse=time.strptime):
        now = today()
        try: return getdate(what, now)
        except ValueError:
            try: return alt(what, now)
            except ValueError: pass

        parse(what, '%H:%M') # daytime format
        # That may raise ValueError again - try other formats ?
        return now
def getFPGAcomponentsFromCN(componentNetwork):
    print(ANSI_CYAN + "\nMappings:" + ANSI_END)
    fpga_components = []
    dp = expatbuilder.parse(componentNetwork, False)
    mappings = dp.getElementsByTagName('component')

    for m in mappings:
        devices = m.getElementsByTagName('devices')

        if len(devices) == 1:
            if devices[0].getAttribute('FPGA').lower() == 'yes':
                print(ANSI_GREEN, end="")
                fpga_components.append(m.getAttribute('name'))
            else:
                print(ANSI_BLUE, end="")

            print("\t{:<15} ".format(m.getAttribute('name')), end="")
            print(ANSI_BLUE + "CPU -> {:<5} GPU -> {:<5} ".format(
                devices[0].getAttribute('CPU'),
                devices[0].getAttribute('GPU')),
                  end="")

            if devices[0].getAttribute('FPGA').lower() == 'yes':
                print(ANSI_GREEN, end="")
            else:
                print(ANSI_BLUE, end="")

            print("FPGA -> {:<5}".format(devices[0].getAttribute('FPGA')))

    print(ANSI_END)
    return fpga_components
def getfilesfromCN(componentNetwork, fpga_component, localmode, inputdir):
    cn = expatbuilder.parse(componentNetwork, False)
    directories = []

    for component in cn.getElementsByTagName('component'):
        if component.getAttribute('name') == fpga_component:
            for implementation in component.getElementsByTagName(
                    'implementation'):
                if implementation.getAttribute('id') == "1":
                    for source_file in implementation.getElementsByTagName(
                            'source'):
                        if source_file.getAttribute('path') not in directories:
                            directories.append(
                                source_file.getAttribute('path'))

    #TODO Not be the best way to get the main component directory.
    firstdir = tmpdir = os.path.join(generated_src_dir, directories[0])

    # Get Files
    for ddir in directories:
        if localmode == True:
            localdir = os.path.abspath(os.path.join(inputdir, ddir))
            tmpdir = os.path.join(generated_src_dir, ddir)
            os.makedirs(tmpdir, exist_ok=True)
            copytree(localdir, tmpdir)
        else:
            repository.set_source(settings.repository_user_dir)
            tmpdir = os.path.join(generated_src_dir, ddir)
            os.makedirs(tmpdir, exist_ok=True)
            repository.downloadFiles(ddir, tmpdir)
            repository.set_source(repository_ipcoregen_source)
    return firstdir
예제 #4
0
    def readdate(what, now=None, date=datetime.date, parse=time.strptime):
        try: when = parse(what, '%d %b %Y')
        except ValueError: pass
        else: return date(when.tm_year, when.tm_mon, when.tm_mday)

        try: when = parse(what, '%d %b')
        except ValueError:
            if what.endswith('.'): raise # can't fix
            when = parse(what + '.', '%d %b')

        if now is None: now = date.today()
        when = date(now.year, when.tm_mon, when.tm_mday)
        if when > now: # year rolled round since page generated ?
            then = date(now.year - 1, when.month, when.day)
            if (now - then) < (when - now):
                return then
        return when
예제 #5
0
def main():
    boardpart = DEFAULTBOARDPART
    if len(sys.argv) < 3:
        print(
            "Usage {} <project_to_create> <input_de.xml> <board_part>".format(
                sys.argv[0]))
        sys.exit(1)
    if len(sys.argv) >= 4:
        boardpart = sys.argv[3]

    if not os.path.exists(sys.argv[2]):
        print("File {} does not exist.".format(sys.argv[2]))
        sys.exit(1)

    fpgas = {}

    # Check for deployment mappings which have 'component' and 'fpga' subelements
    # The fpga element has attributes:
    #   name = name of the fpga to target
    #   ipname = name of the IP core to use to implement it
    doc = expatbuilder.parse(sys.argv[2], False)
    mappings = doc.getElementsByTagName('mapping')
    for m in mappings:
        fpga = m.getElementsByTagName('fpga')
        comp = m.getElementsByTagName('component')
        if len(fpga) > 0 and len(comp) > 0:
            if fpga[0].getAttribute('name') in fpgas:
                fpgas[fpga[0].getAttribute('name')].append((fpga[0], comp[0]))
            else:
                fpgas[fpga[0].getAttribute('name')] = [(fpga[0], comp[0])]

# Report what we found
    print(ANSI_MAGENTA + "FPGA designs to construct:" + ANSI_END)
    for fpganame in fpgas:
        print("\tFPGA: {}{}{}".format(ANSI_CYAN, fpganame, ANSI_END))
        for f, c in fpgas[fpganame]:
            print("\t\tComponent: {}{} -> {}{}".format(
                ANSI_GREEN, c.getAttribute('name'), f.getAttribute('ipname'),
                ANSI_END))

    # Now for each FPGA we build a Vivado design
    if len(fpgas) > 1:
        print(
            "Warning: Currently only automatic construction of the first design is supported."
        )
        fpgas = fpgas[:1]
    for fpganame in fpgas:
        print(ANSI_MAGENTA +
              "Constructing design for FPGA {}...".format(fpganame) + ANSI_END)

        cmd = "vivado -mode batch -source build_project.tcl -quiet -notrace -tclargs hwproj {} {} ".format(
            sys.argv[1], boardpart)
        for f, c in fpgas[fpganame]:
            cmd = cmd + f.getAttribute('ipname') + " "
        print(cmd)
        os.system(cmd)
def getfilesfromCN(componentNetwork, fpga_component, localmode, inputdir):
    cn = expatbuilder.parse(componentNetwork, False)
    dirs = []

    for component in cn.getElementsByTagName('component'):
        if component.getAttribute('name') == fpga_component:
            for implementation in component.getElementsByTagName(
                    'implementation'):
                if implementation.getAttribute('id') == "1":
                    for source_file in implementation.getElementsByTagName(
                            'source'):
                        if source_file.getAttribute('path') not in dirs:
                            dirs.append(source_file.getAttribute('path'))

    # Get Files
    for ddir in dirs:
        if localmode == True:
            localdir = os.path.abspath(os.path.join(inputdir, ddir))
            tmpdir = os.path.join(generated_src_dir, ddir)
            os.makedirs(tmpdir, exist_ok=True)
            copytree(localdir, tmpdir)
        else:
            repository.set_source(settings.repository_user_dir)
            tmpdir = os.path.join(generated_src_dir, ddir)
            os.makedirs(tmpdir, exist_ok=True)
            repository.downloadFiles(ddir, tmpdir)
            repository.set_source(repository_ipcoregen_source)

    files = []
    for ddir in dirs:
        for root, directories, filenames in os.walk(tmpdir):
            for filename in filenames:
                if os.path.isfile(os.path.join(tmpdir, filename)):
                    with open(os.path.join(tmpdir, filename), 'r') as file:
                        for line in file:
                            if '#pragma ipcoregen function' in line:
                                function_name = line.replace(
                                    '#pragma ipcoregen function ',
                                    '').split()[0]
                                relpath, filename = os.path.split(
                                    os.path.join(tmpdir, filename))
                                file_funtion = [
                                    os.path.join(tmpdir, filename),
                                    function_name
                                ]
                                files.append(file_funtion)
    return files
def getFPGAcomponentsFromDP(deploymentPlan):
    print(ANSI_MAGENTA + "\nMappings:")
    fpga_components = []
    dp = expatbuilder.parse(deploymentPlan, False)
    mappings = dp.getElementsByTagName('mapping')

    for m in mappings:
        comp = m.getElementsByTagName('component')
        proc = m.getElementsByTagName('processor')

        if len(comp) == 1 and len(proc) == 1:
            print("\t{} -> {}".format(comp[0].getAttribute('name'),
                                      proc[0].getAttribute('name')))

        if proc[0].getAttribute('name') == "FPGA":
            fpga_components.append(comp[0].getAttribute('name'))
    print()
    return fpga_components
예제 #8
0
파일: rxml.py 프로젝트: onecommons/rhizome
def rx2model(path, url=None, debug=0, namespaceAware=0, scope=''):
    '''
    Parse the RxML and returns a 4Suite model containing its statements.
    '''
    from xml.dom import expatbuilder

    if url:
        isrc = InputSource.DefaultFactory.fromUri(url)
        src = isrc.stream
    else:
        src = path
    doc = expatbuilder.parse(src, namespaces=namespaceAware)

    outputModel = RxPath.MemModel()

    nsMap = addRxdom2Model(doc,
                           outputModel,
                           thisResource='wikiwiki:',
                           scope=scope)
    return outputModel, nsMap
예제 #9
0
def readinbox():
    if DEBUG:
        logging.debug('Debugging is TRUE!')
    logging.debug('Starting to read mailbox interface for incoming message...')
    # read the mailbox only for unread email.
    for item in account.inbox.filter(is_read=False):
        logging.debug(80 * '#')
        logging.debug('Receiving from: %s' % item.sender.email_address)
        # now check who is the sender, unknown sender will be rejected.
        if recvfrom.match(item.sender.email_address):
            try:
                # read the mailbody
                mybody = item.body.encode('utf-8').strip()
            except UnicodeDecodeError as err:
                logging.debug(err)
                logging.debug('Unicode error...')
                # if mailbody is garbled and in unknown format, delete the email. consider rogue email.
                sendalert(
                    str(err) + 'Unknown or format error of the mailbody!')
                item.is_read = True
                item.save()
                pass
            fd, path = tempfile.mkstemp()
            if mybody:
                # now the body is validated, write into a file.
                with os.fdopen(fd, 'w') as tmp:
                    # xml.dom requires xml to be perfectly formatted. Hence need the root entry point.
                    tmp.write('<root>\n')
                    for line in mybody.split('\n'):
                        if not xmlheader.match(line) and not xmlmessg.match(
                                line) and not xmlreturn.match(line):
                            if DEBUG:
                                logging.debug(line)
                            tmp.write(line)
                    # close the root entry point of the XML body.
                    tmp.write('</root>\n')
                try:
                    # now parse the XML file.
                    xmldoc = expatbuilder.parse(path, False)
                except ExpatError as err:
                    logging.debug(str(err))
                    errmsg = 'Marking email as read with no further action due to XML parsing error...'
                    logging.debug(errmsg)
                    # if parsing error, send alert.
                    sendalert(str(err) + errmsg)
                    item.is_read = True
                    item.save()
                    pass

                try:
                    name_ag = 'None'
                    name_info = 'None'
                    name_host = 'None'
                    # now get all the element in the XML for processing info.
                    node_id = xmldoc.getElementsByTagName("ns1:IncidentID")
                    for i in node_id:
                        name_id = i.firstChild.nodeValue
                    node_ag = xmldoc.getElementsByTagName(
                        "ns1:AssignmentGroup")
                    for j in node_ag:
                        name_ag = j.firstChild.nodeValue
                    node_info = xmldoc.getElementsByTagName("ns1:Title")
                    for k in node_info:
                        name_info = k.firstChild.nodeValue
                    node_host = xmldoc.getElementsByTagName("ns1:CIListName")
                    for l in node_host:
                        name_host = l.firstChild.nodeValue
                    if DEBUG:
                        logging.debug(name_ag)
                        logging.debug(name_id)
                        logging.debug(node_info)
                        logging.debug(name_host)
                    logging.debug('Adding new job %s' % name_id)
                except AttributeError as err:
                    logging.debug('Error to read child value of the XML: %s' %
                                  str(err))
                    pass
                try:
                    logging.debug('Adding new job : %s ' % name_id)
                    # based on the XML element insert item into database.
                    dbapi.add_new_job(name_id, name_info, name_ag,
                                      name_host.lower().replace(" ", ""))
                except RuntimeError as err:
                    logging.debug('Unable to add new job : %s ' % name_id)
                    logging.debug(str(err))
                    sendalert(
                        str(err) + 'Unable to add new job, check engine.log!')
                    item.is_read = True
                    item.save()
            # marked the processed email as read.
            item.is_read = True
            item.save()
            os.remove(path)
        else:
            # dont to anything if unknown sender. Shared mailbox with DEV system.
            logging.debug('Unknown sender: %s, ignoring...' %
                          item.sender.email_address)
def addfilestoCN(componentNetwork, fpga_component, files, solution_name):
    cn = expatbuilder.parse(componentNetwork, False)
    implementation_number = 0

    for component in cn.getElementsByTagName('component'):
        if component.getAttribute('name') == fpga_component:
            for implementation in component.getElementsByTagName(
                    'implementation'):
                if int(implementation.getAttribute(
                        'id')) > implementation_number:
                    implementation_number = int(
                        implementation.getAttribute('id'))

            newimpl = cn.createElement("implementation")
            newimpl.setAttribute("target", "fpga")
            newimpl.setAttribute("id", str(implementation_number + 1))

            # Modified component files
            for root, directories, filenames in os.walk(files[0]):
                for filename in filenames:
                    filepath = os.path.join(files[0], filename)
                    filetype = "".join(pathlib.Path(filename).suffixes)[1:]
                    if os.path.isfile(filepath):
                        if filetype != "" and filetype != "h":
                            relpath, filename = os.path.split(filepath)
                            newsrc = cn.createElement("source")
                            newsrc.setAttribute("file", filename)
                            newsrc.setAttribute("lang", filetype)
                            newsrc.setAttribute(
                                "path",
                                os.path.join(
                                    repository_ipcoregen_source, solution_name,
                                    os.path.relpath(files[0],
                                                    generated_src_dir)))
                            newimpl.appendChild(newsrc)
                    else:
                        print("{} is not a valid file.".format(filepath))

            # Xilinx Autogenerated drivers
            for root, directories, filenames in os.walk(files[1]):
                for filename in filenames:
                    filepath = os.path.join(files[1], filename)
                    filetype = "".join(pathlib.Path(filename).suffixes)[1:]
                    if os.path.isfile(filepath):
                        if filetype != "" and filetype != "h":
                            relpath, filename = os.path.split(filepath)
                            newsrc = cn.createElement("source")
                            newsrc.setAttribute("file", filename)
                            newsrc.setAttribute("lang", filetype)
                            newsrc.setAttribute(
                                "path",
                                os.path.join(
                                    repository_ipcoregen_source, solution_name,
                                    os.path.relpath(files[0],
                                                    generated_src_dir),
                                    'drivers'))
                            newimpl.appendChild(newsrc)
                    else:
                        print("{} is not a valid file.".format(filepath))

            # IP Core Zip
            relpath, filename = os.path.split(files[2])
            newsrc = cn.createElement("source")
            newsrc.setAttribute("file", filename)
            newsrc.setAttribute("lang", "ipcore")
            newsrc.setAttribute(
                "path", os.path.join(repository_ipcoregen_source,
                                     solution_name))
            newimpl.appendChild(newsrc)

            # Write XML
            component.appendChild(newimpl)
            cnstring = cn.toprettyxml().replace("\r", "").replace("\n", "")
            cn = expatbuilder.parseString(cnstring, False)
            f = open(componentNetwork, "w+")
            cn.writexml(f, "", "\t", "\n")
            f.close()
def SafetyCalculator():
    risky_count = 0
    normal_count = 0
    app_zip_data = []

    Risky_list = [
        "android.permission.READ_CALENDAR",
        "android.permission.WRITE_CALENDAR", "android.permission.CAMERA",
        "android.permission.READ_CONTACTS",
        "android.permission.WRITE_CONTACTS", "android.permission.GET_ACCOUNTS",
        "android.permission.ACCESS_FINE_LOCATION",
        "android.permission.ACCESS_COARSE_LOCATION",
        "android.permission.RECORD_AUDIO",
        "android.permission.READ_PHONE_STATE",
        "android.permission.READ_PHONE_NUMBERS",
        "android.permission.CALL_PHONE",
        "android.permission.ANSWER_PHONE_CALLS",
        "android.permission.READ_CALL_LOG",
        "android.permission.WRITE_CALL_LOG",
        "android.permission.ADD_VOICEMAIL", "android.permission.USE_SIP",
        "android.permission.PROCESS_OUTGOING_CALLS",
        "android.permission.BODY_SENSORS", "android.permission.SEND_SMS",
        "android.permission.RECEIVE_SMS", "android.permission.READ_SMS",
        "android.permission.RECEIVE_WAP_PUSH",
        "android.permission.RECEIVE_MMS",
        "android.permission.READ_EXTERNAL_STORAGE",
        "android.permission.WRITE_EXTERNAL_STORAGE"
    ]
    Normal_list = [
        "android.permission.ACCESS_LOCATION_EXTRA_COMMANDS",
        "android.permission.ACCESS_NETWORK_STATE",
        "android.permission.ACCESS_NOTIFICATION_POLICY",
        "android.permission.ACCESS_WIFI_STATE", "android.permission.BLUETOOTH",
        "android.permission.BLUETOOTH_ADMIN",
        "android.permission.BROADCAST_STICKY",
        "android.permission.CHANGE_NETWORK_STATE",
        "android.permission.CHANGE_WIFI_MULTICAST_STATE",
        "android.permission.CHANGE_WIFI_STATE",
        "android.permission.DISABLE_KEYGUARD",
        "android.permission.EXPAND_STATUS_BAR",
        "android.permission.GET_PACKAGE_SIZE",
        "android.permission.INSTALL_SHORTCUT", "android.permission.INTERNET",
        "android.permission.KILL_BACKGROUND_PROCESSES",
        "android.permission.MODIFY_AUDIO_SETTINGS", "android.permission.NFC",
        "android.permission.READ_SYNC_SETTINGS",
        "android.permission.READ_SYNC_STATS",
        "android.permission.RECEIVE_BOOT_COMPLETED",
        "android.permission.REORDER_TASKS",
        "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS",
        "android.permission.REQUEST_INSTALL_PACKAGES",
        "android.permission.SET_ALARM", "android.permission.SET_TIME_ZONE",
        "android.permission.SET_WALLPAPER",
        "android.permission.SET_WALLPAPER_HINTS",
        "android.permission.TRANSMIT_IR",
        "android.permission.UNINSTALL_SHORTCUT",
        "android.permission.USE_FINGERPRINT", "android.permission.VIBRATE",
        "android.permission.WAKE_LOCK",
        "android.permission.WRITE_SYNC_SETTINGS"
    ]

    # new excel sheet to save the data with names
    workbook = xlsxwriter.Workbook('App Data Security.xlsx')
    worksheet = workbook.add_worksheet("Application Security Data")

    # labels
    worksheet.write('A1', 'App Name')
    worksheet.write('B1', 'Normal Percentage')
    worksheet.write('C1', 'Risky Percentage')
    worksheet.write('D1', 'Security Percentage')

    k = 2

    path_zip = ManifestExtractor.request()
    path = "D:\Project\Privacy Detection\Apps\Excel Sheets\Manifest Data.xlsx"
    workbook1 = xlrd.open_workbook(path_zip)
    for sheet in workbook1.sheets():
        for row in range(sheet.nrows):
            for column in range(sheet.ncols):
                app_zip_data.append(str(sheet.cell(row, column).value))

    for i in app_zip_data:
        doc = expatbuilder.parse(i, False)
        #doc = xml.dom.minidom.parse(i)
        permission = doc.getElementsByTagName("uses-permission")
        for skill in permission:
            permission_string = skill.getAttribute("android:name")
            for j in Risky_list:
                if j == permission_string:
                    risky_count += 1
            for j in Normal_list:
                if j == permission_string:
                    normal_count += 1

        #saftey generation code
        app_count = normal_count + risky_count
        normal_safety = (normal_count / app_count) * 100
        risky_safety = (risky_count / app_count) * 100

        safety = 0

        if (normal_safety > risky_safety):
            safety = normal_safety
        elif (risky_safety > normal_safety):
            safety = risky_safety
        else:
            safety = normal_safety

        # for app name
        worksheet.write(
            'A' + str(k),
            str(i).split('\\')[5].split('AndroidManifest')[0].replace(
                '_', ' '))
        # for app security percentage
        worksheet.write('B' + str(k), normal_safety)
        # for app normal permission percentage
        worksheet.write('C' + str(k), risky_safety)
        # for app risky permission percentage
        worksheet.write('D' + str(k), safety)
        k += 1

    workbook.close()

    shutil.move("D:\\Project\\Privacy Detection\\App Data Security.xlsx",
                "D:\\Project\\Privacy Detection\\Apps\\Excel Sheets")
    path = "D:\\Project\\Privacy Detection\\Apps\\Excel Sheets\\App Data Security.xlsx"
    return path
예제 #12
0
# -*- coding: utf-8 -*-
import xml.dom.expatbuilder as bad
import defusedxml.expatbuilder as good

bad.parse("filethatdoesntexist.xml")
good.parse("filethatdoesntexist.xml")

xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"

bad.parseString(xmlString)
good.parseString(xmlString)
예제 #13
0
import xml.dom.expatbuilder as bad
import defusedxml.expatbuilder as good

bad.parse('filethatdoesntexist.xml')
good.parse('filethatdoesntexist.xml')

xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"

bad.parseString(xmlString)
good.parseString(xmlString)
예제 #14
0
def get_dependencies_from_pom(main_pom_file, pom_file, poms_base_dir, libA, libB, versionMissing, logf):
	
	# print(pom_file)	

	# Checking if the pom file exist, otherwise add in log file
	try:
		tree = parse(pom_file)
	except xml.parsers.expat.ExpatError:
		tree = expatbuilder.parse(pom_file, False)	
	except Exception as e:
		logf.write(str(e) + ", --  Pom file %s does not exist when looked by the main pom file %s.\n" %(pom_file, main_pom_file))
		return

		
	# The main root to extract information
	root = bs(tree.toxml(), 'lxml')	

	# This is just to get the pom's groupId, artifactId, version and scope
	# To get the groupId, artifactId and version from the parent, if not mentioned in this pom

	project_gid = None
	project_aid = None
	project_vid = None							


	if root.project.find_all('groupid', recursive=False):
		root_gid = root.project.find_all('groupid', recursive=False)
		for rid in root_gid:
			project_gid = rid.text

	if root.project.find_all('artifactid', recursive=False):
		root_aid = root.project.find_all('artifactid', recursive=False)
		for rid in root_aid:
			project_aid = rid.text

	if root.project.find_all('version', recursive=False):
		root_vid = root.project.find_all('version', recursive=False)
		for rid in root_vid:
			project_vid = rid.text
	


	# To keep parent information
	has_parent = False
	parent_pom_file = None
	parent_project_gid = None
	parent_project_aid = None
	parent_project_vid = None

	parent = root.project.find_all('parent', recursive=False) # This is the parent tag, stores parents information
	# if parent is not None:
	for p in parent:
		if type(p) == bs4.element.Tag:	
			has_parent = True
			parent_project_gid = p.find('groupid').text
			parent_project_aid = p.find('artifactid').text
			parent_project_vid = p.find('version').text
			parent_pom_file = poms_base_dir + parent_project_gid +"-"+parent_project_aid+"-"+parent_project_vid+".pom"

	# To handle if the project groupId and version not giving, then we use the parent groupId and version	
	if project_gid is None:
		project_gid = parent_project_gid
	if project_vid is None:
		project_vid = parent_project_vid	

	# Adding the information of LibA here

	if libA[0]['groupid'] is None:
		libA[0]['groupid'] = project_gid
	if libA[0]['artifactid'] is None:
		libA[0]['artifactid'] = project_aid
	if libA[0]['version'] is None:
		libA[0]['version'] = project_vid


	direct_deps = root.project.find_all('dependencies', recursive=False)
	for deps in direct_deps: # Dependencies tag, and dep = dependency
		if type(deps) == bs4.element.Tag:
			for dep in deps:
				if type(dep) == bs4.element.Tag:
					
					temp_dict = {'groupid': None, 'artifactid': None, 'version': None, 'scope': None}
					
					if dep.find('groupid'):
						temp_dict['groupid'] = dep.find('groupid').text				
					if dep.find('artifactid'):
						temp_dict['artifactid'] = dep.find('artifactid').text
					if dep.find('version'):
						temp_dict['version'] = dep.find('version').text
					if dep.find('scope'):
						temp_dict['scope'] = dep.find('scope').text

					
					if temp_dict['scope'] == 'test' or temp_dict['scope'] == 'system': # Ignore 2 scopes
						pass
					
					else:
						if temp_dict['groupid'] is not None and temp_dict['artifactid'] is not None:
							
							if temp_dict['groupid'][0] == "$": # To handles the weird groupIds
								
								# weird_gid = temp_dict['groupid'][2:-1]

								weird_gid_split = temp_dict['groupid'].split('}')
								weird_gid = weird_gid_split[0][2:]
								gid_tail = weird_gid_split[1]

								weird_gid = weird_gid.lower() # To lower the tag name

								del weird_gid_split
								
								if weird_gid == 'project.groupid' or weird_gid == 'pom.groupid' or weird_gid == 'groupid':
									temp_dict['groupid'] = project_gid  + gid_tail

								elif weird_gid == 'project.parent.groupid' or weird_gid == 'parent.groupid':
									temp_dict['groupid'] = parent_project_gid + gid_tail

								else:

									gid_found = False

									root_parent_loop = root

									while(not gid_found):
										properties = root_parent_loop.project.find_all('properties', recursive=False)
										for prop in properties:
											if type(prop) == bs4.element.Tag:
												if prop.find(weird_gid):
													if prop.find(weird_gid).text[0] == '$' and prop.find(weird_gid).text[2:-1] == weird_gid:
														pass
													else:
														temp_dict['groupid'] = check_properties_for_groupid(prop, weird_gid, project_gid, parent_project_gid)
														temp_dict['groupid'] = temp_dict['groupid'] + gid_tail
														gid_found = True
										if gid_found:
											break	

										try:
											tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
											root_parent_loop = bs(tree_loop.toxml(), 'lxml')
											del tree_loop

										except xml.parsers.expat.ExpatError:
											tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
											root_parent_loop = bs(tree_loop.toxml(), 'lxml')
											del tree_loop	
											
										except Exception as e:
											# logf.write(str(e) + " Error on reading file: %s. \n " %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
											logf.write("Error: -->  %s. \n" %(str(e)))
											break
											
									
									del gid_found
									del root_parent_loop

							if temp_dict['artifactid'][0] == "$": # To handles the weird groupIds
								
								# weird_gid = temp_dict['groupid'][2:-1]

								weird_aid_split = temp_dict['artifactid'].split('}')
								weird_aid = weird_aid_split[0][2:]
								aid_tail = weird_aid_split[1]

								weird_aid = weird_aid.lower() # To lower the tag name

								del weird_aid_split
								
								if weird_aid == 'project.artifactid' or weird_aid == 'pom.artifactid' or weird_aid == 'artifactid':
									temp_dict['artifactid'] = project_aid  + aid_tail

								elif weird_aid == 'project.parent.artifactid' or weird_aid == 'parent.artifactid':
									temp_dict['artifactid'] = parent_project_aid + aid_tail

								else:

									aid_found = False

									root_parent_loop = root

									while(not aid_found):
										properties = root_parent_loop.project.find_all('properties', recursive=False)
										for prop in properties:
											if type(prop) == bs4.element.Tag:
												if prop.find(weird_aid):
													if prop.find(weird_aid).text[0] == '$' and prop.find(weird_aid).text[2:-1] == weird_aid:
														pass
													else:
														temp_dict['artifactid'] = check_properties_for_artifactid(prop, weird_aid, project_aid, parent_project_aid)
														temp_dict['artifactid'] = temp_dict['artifactid'] + aid_tail
														aid_found = True
										if aid_found:
											break	

										try:
											tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
											root_parent_loop = bs(tree_loop.toxml(), 'lxml')
											del tree_loop

										except xml.parsers.expat.ExpatError:
											tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
											root_parent_loop = bs(tree_loop.toxml(), 'lxml')
											del tree_loop	
											
										except Exception as e:
											# logf.write(str(e) + " Error on reading file: %s. \n " %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
											logf.write("Error: -->  %s. \n" %(str(e)))
											break
											
									
									del aid_found
									del root_parent_loop		
									
									
							if temp_dict['version'] is not None:
									
								if temp_dict['version'][0] == "$":

									# weird_vid = temp_dict['version'][2:-1]
									weird_vid_split = temp_dict['version'].split('}')
									weird_vid = weird_vid_split[0][2:]
									vid_tail = weird_vid_split[1]

									weird_vid = weird_vid.lower()

									del weird_vid_split


									if weird_vid == 'project.version' or weird_vid == 'pom.version' or weird_vid == 'version':
										temp_dict['version'] = project_vid + vid_tail

									elif weird_vid == 'project.parent.version' or weird_vid == 'parent.version':
										temp_dict['version'] = parent_project_vid + vid_tail

									else:

										vid_found = False
										root_parent_loop = root
										
										while(not vid_found):
											properties = root_parent_loop.project.find_all('properties', recursive=False)
											for prop in properties:
												if type(prop) == bs4.element.Tag:
													if prop.find(weird_vid):
														if prop.find(weird_vid).text[0] == '$' and prop.find(weird_vid).text[2:-1] == weird_vid:
															pass
														else:
															temp_dict['version'] = check_properties_for_version(prop, weird_vid, project_vid, parent_project_vid)
															temp_dict['version'] = temp_dict['version'] + vid_tail
															vid_found = True
															break
												
											if vid_found:
												break		
													
											
											try:
												tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop

											except xml.parsers.expat.ExpatError:
												tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop

											except Exception as e:
												# logf.write(str(e) + " Error on reading file: %s. \n "  %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
												logf.write("Error: -->  %s. \n" %(str(e)))
												break
																	
										del vid_found
										del root_parent_loop


								libB.append(temp_dict['groupid']+":"+temp_dict['artifactid']+":"+temp_dict['version'])

							if temp_dict['version'] is None:		

								versionMissing.update({len(libB):{'gid':temp_dict['groupid'], 'aid':temp_dict['artifactid']}})	
								libB.append(temp_dict['groupid']+":"+temp_dict['artifactid']+":"+"ver_none")

						else:
							try:
								libB.append(temp_dict['groupid']+":"+temp_dict['artifactid']+":"+temp_dict['version'])

							except Exception as e:
								if temp_dict['groupid'] is None:
									temp_dict['groupid'] = "None"
								if temp_dict['artifactid'] is None:
									temp_dict['artifactid'] = "None"
								if temp_dict['version'] is None:
									temp_dict['version'] = "None"		
								
								libB_temp = temp_dict['groupid']+":"+temp_dict['artifactid']+":"+temp_dict['version']				
								logf.write("The main pom file %s has a parent %s that has a dependency with invalid artifactId(g:a:v)--> %s.\n" % \
									(main_pom_file, pom_file, libB_temp))
								del libB_temp		
								pass


	del_version_idx = []
	if len(versionMissing) > 0:
		deps_manage = root.project.find_all('dependencymanagement', recursive=False)
		for key, value in versionMissing.items():
			version_found = False
			for deps in deps_manage: # deps = dependecies
				if type(deps) ==bs4.element.Tag:
					for dep in deps: # dep = dependency
						if type(dep) == bs4.element.Tag:
							for d in dep:
								if type(d) == bs4.element.Tag:

									depm_groupid = None
									depm_artifactid = None
									depm_version = None
									depm_scope = None

									if d.find('groupid'):
										depm_groupid = d.find('groupid').text
									if d.find('artifactid'):
										depm_artifactid = d.find('artifactid').text
									if d.find('version'):
										depm_version = d.find('version').text
									if d.find('scope'):
										depm_scope = d.find('scope').text 


									if depm_groupid[0] == "$":
										
										# weird_gid = depm_groupid[2:-1]
										weird_gid_split = depm_groupid.split('}')
										weird_gid = weird_gid_split[0][2:]
										gid_tail = weird_gid_split[1] 

										weird_gid = weird_gid.lower()

										del weird_gid_split

										if weird_gid == 'project.groupid' or weird_gid == 'pom.groupid' or weird_gid == 'groupid' :
											depm_groupid = project_gid + gid_tail

										elif weird_gid == 'project.parent.groupid' or weird_gid == 'parent.groupid':
											depm_groupid = parent_project_gid + gid_tail

										else:

											gid_found = False
											root_parent_loop = root

											while(not gid_found):
												properties = root_parent_loop.project.find_all('properties', recursive=False)
												for prop in properties:
													if type(prop) == bs4.element.Tag:
														if prop.find(weird_gid):
															if prop.find(weird_gid).text[0] == '$' and prop.find(weird_gid).text[2:-1] == weird_gid:
																pass
															else:
																depm_groupid = check_properties_for_groupid(prop, weird_gid, project_gid, parent_project_gid)
																gid_found = True
																break
												
												if gid_found:
													break				

												try:
													tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop

												except xml.parsers.expat.ExpatError:
													tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop	

												except Exception as e:
													# logf.write(str(e) + " Error on reading file: %s. \n " %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
													logf.write("Error: -->  %s. \n" %(str(e)))
													break
											
											del gid_found
											del root_parent_loop

									if depm_artifactid[0] == "$":
										
										# weird_gid = depm_groupid[2:-1]
										weird_aid_split = depm_artifactid.split('}')
										weird_aid = weird_aid_split[0][2:]
										aid_tail = weird_aid_split[1] 

										weird_aid = weird_aid.lower()

										del weird_aid_split

										if weird_aid == 'project.artifactid' or weird_aid == 'pom.artifactid' or weird_aid == 'artifactid' :
											depm_artifactid = project_aid + aid_tail

										elif weird_aid == 'project.parent.artifactid' or weird_aid == 'parent.artifactid':
											depm_artifactid = parent_project_aid + aid_tail

										else:

											aid_found = False
											root_parent_loop = root

											while(not aid_found):
												properties = root_parent_loop.project.find_all('properties', recursive=False)
												for prop in properties:
													if type(prop) == bs4.element.Tag:
														if prop.find(weird_aid):
															if prop.find(weird_aid).text[0] == '$' and prop.find(weird_aid).text[2:-1] == weird_aid:
																pass
															else:
																depm_artifactid = check_properties_for_artifactid(prop, weird_aid, project_aid, parent_project_aid)
																aid_found = True
																break
												
												if aid_found:
													break				

												try:
													tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop

												except xml.parsers.expat.ExpatError:
													tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop	

												except Exception as e:
													# logf.write(str(e) + " Error on reading file: %s. \n " %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
													logf.write("Error: -->  %s. \n" %(str(e)))
													break
											
											del aid_found
											del root_parent_loop

											
									if depm_groupid == value['gid'] and depm_artifactid == value['aid'] and depm_version[0] == '$' and depm_scope!='import':	
										
										# weird_vid = depm_version[2:-1]

										weird_vid_split = depm_version.split('}')
										weird_vid = weird_vid_split[0][2:]
										vid_tail = weird_vid_split[1] 

										weird_vid = weird_vid.lower()

										del weird_vid_split



										if weird_vid == 'project.version' or weird_vid == 'pom.version' or weird_vid == 'version':
											depm_version = project_vid 

										elif weird_vid == 'project.parent.version' or weird_vid == 'parent.version':
											depm_version = parent_project_vid

										else:

											vid_found = False
											root_parent_loop = root

											while(not vid_found):
												properties = root_parent_loop.project.find_all('properties', recursive=False)
												for prop in properties:
													if type(prop) == bs4.element.Tag:
														if prop.find(weird_vid):
															if prop.find(weird_vid).text[0] == '$' and prop.find(weird_vid).text[2:-1] == weird_vid:
																pass
															else:
																depm_version = check_properties_for_version(prop, weird_vid, project_vid, parent_project_vid)
																vid_found = True
																break
												if vid_found:
													break

												try:
													tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop

												except xml.parsers.expat.ExpatError:
													tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop	

												except Exception as e:
													# logf.write(str(e) + " Error on reading file: %s. \n" %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
													logf.write("Error: -->  %s. \n" %(str(e)))
													break

											del vid_found
											del root_parent_loop

										
									if depm_groupid == value['gid'] and depm_artifactid == value['aid'] and depm_scope!='import':
										
										libB_split = libB[key].split(":")
										libB[key] = libB_split[0] + ":" + libB_split[1] + ":" + depm_version
										del_version_idx.append(key)
										version_found = True

									if depm_scope == "import":

										if depm_version[0] == '$':

											weird_vid_split = depm_version.split('}')
											weird_vid = weird_vid_split[0][2:]
											vid_tail = weird_vid_split[1] 

											weird_vid = weird_vid.lower()

											del weird_vid_split


											if weird_vid == 'project.version' or weird_vid == 'pom.version' or weird_vid == 'version':
												depm_version = project_vid 

											elif weird_vid == 'project.parent.version' or weird_vid == 'parent.version':
												depm_version = parent_project_vid

											else:

												vid_found = False
												root_parent_loop = root

												while(not vid_found):
													properties = root_parent_loop.project.find_all('properties', recursive=False)
													for prop in properties:
														if type(prop) == bs4.element.Tag:
															if prop.find(weird_vid):
																if prop.find(weird_vid).text[0] == '$' and prop.find(weird_vid).text[2:-1] == weird_vid:
																	pass
																else:
																	depm_version = check_properties_for_version(prop, weird_vid, project_vid, parent_project_vid)
																	vid_found = True
																	break
													if vid_found:
														break

													try:
														tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
														root_parent_loop = bs(tree_loop.toxml(), 'lxml')
														del tree_loop

													except xml.parsers.expat.ExpatError:
														tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
														root_parent_loop = bs(tree_loop.toxml(), 'lxml')
														del tree_loop	

													except Exception as e:
														# logf.write(str(e) + " Error on reading file: %s. \n" %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
														logf.write("Error: -->  %s. \n" %(str(e)))
														break

												del vid_found
												del root_parent_loop

									
										depm_fname = depm_groupid + "-" + depm_artifactid + "-" + depm_version + ".pom"	
										missing_version = get_deps_man_from_import_scope(main_pom_file, depm_fname, poms_base_dir, key, value, logf)
										
										if missing_version:
											libB_split = libB[key].split(":")
											libB[key] = libB_split[0] + ":" + libB_split[1] + ":" + missing_version #  find missing version
											del_version_idx.append(key)
											version_found = True

								if version_found:
									break
						if version_found:
							break
				if version_found:
					break			 




	if len(del_version_idx)>0:
		for i in range(len(del_version_idx)):
			del versionMissing[del_version_idx[i]]						
	del del_version_idx


	if has_parent:
		# Recursively checking parents
		get_dependencies_from_pom(main_pom_file, parent_pom_file, poms_base_dir, libA, libB, versionMissing, logf)
							
	return
예제 #15
0
def get_deps_man_from_import_scope(main_pom_file, depm_fname, poms_base_dir, key, value, logf):

	depm_path = poms_base_dir + depm_fname

	try:
		depm_tree = parse(depm_path)
	except xml.parsers.expat.ExpatError:
		depm_tree = expatbuilder.parse(depm_path, False)	
	except Exception as e:
		logf.write(str(e) + ", --  Pom file %s does not exist when looked by the main pom file through dependencymanagement section --> %s.\n" %(depm_path, main_pom_file))
		return

	# The main root to extract information
	depm_root = bs(depm_tree.toxml(), 'lxml')	

	project_gid = None
	project_aid = None
	project_vid = None

	if depm_root.project.find_all('groupid', recursive=False):
		root_gid = depm_root.project.find_all('groupid', recursive=False)
		for rid in root_gid:
			project_gid = rid.text

	if depm_root.project.find_all('artifactid', recursive=False):
		root_aid = depm_root.project.find_all('artifactid', recursive=False)
		for rid in root_aid:
			project_aid = rid.text

	if depm_root.project.find_all('version', recursive=False):
		root_vid = depm_root.project.find_all('version', recursive=False)
		for rid in root_vid:
			project_vid = rid.text
	
	

	# To keep parent information
	has_parent = False
	parent_pom_fname = None
	parent_project_gid = None
	parent_project_aid = None
	parent_project_vid = None

	parent = depm_root.project.find_all('parent', recursive=False) # This is the parent tag, stores parents information
	# if parent is not None:
	for p in parent:
		if type(p) == bs4.element.Tag:	
			has_parent = True
			parent_project_gid = p.find('groupid').text
			parent_project_aid = p.find('artifactid').text
			parent_project_vid = p.find('version').text
			parent_pom_fname = parent_project_gid +"-"+parent_project_aid+"-"+parent_project_vid+".pom"
	

	# To handle if the project groupId and version not giving, then we use the parent groupId and version	
	if project_gid is None:
		project_gid = parent_project_gid
	if project_vid is None:
		project_vid = parent_project_vid	

	depm_with_import_list = []	

	deps_manage = depm_root.project.find_all('dependencymanagement', recursive=False)
	if deps_manage: # Check if has dependency management section
		for deps in deps_manage: # deps = dependecies
			if type(deps) ==bs4.element.Tag:
				for dep in deps: # dep = dependency
					if type(dep) == bs4.element.Tag:
						for d in dep:
							if type(d) == bs4.element.Tag:

								depm_groupid = None
								depm_artifactid = None
								depm_version = None
								depm_scope = None

								if d.find('groupid'):
									depm_groupid = d.find('groupid').text
								if d.find('artifactid'):
									depm_artifactid = d.find('artifactid').text
								if d.find('version'):
									depm_version = d.find('version').text
								if d.find('scope'):
									depm_scope = d.find('scope').text


								if depm_groupid[0] == "$":

									# weird_gid = depm_groupid[2:-1]

									weird_gid_split = depm_groupid.split('}')
									weird_gid = weird_gid_split[0][2:]

									gid_tail = weird_gid_split[1]

									weird_gid = weird_gid.lower() # To lower the tag name

									del weird_gid_split


									if weird_gid == 'project.groupid' or weird_gid == 'pom.groupid' or weird_gid == 'groupid':
										depm_groupid = project_gid + gid_tail 

									elif weird_gid == 'project.parent.groupid' or weird_gid == 'parent.groupid':
										depm_groupid = parent_project_gid + gid_tail

									else:

										gid_found = False
										root_parent_loop = depm_root

										while(not gid_found):
											properties = root_parent_loop.project.find_all('properties', recursive=False)
											for prop in properties:
												if type(prop) == bs4.element.Tag:	
													if prop.find(weird_gid):
														if prop.find(weird_gid).text[0] == '$' and prop.find(weird_gid).text[2:-1] == weird_gid: # handle infinite loop
															pass
														else:
															depm_groupid = check_properties_for_groupid(prop, weird_gid, project_gid, parent_project_gid)
															depm_groupid = depm_groupid + gid_tail
															gid_found = True
															break
											
											if gid_found:
												break		

											try:
												tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop

											except xml.parsers.expat.ExpatError:
												tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop	

											except Exception as e:
												# logf.write(str(e) + " Error on reading file: %s.\n" %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
												logf.write("Error: -->  %s. \n" %(str(e)))
												break
											
										
										del gid_found
										del root_parent_loop

													
								if depm_artifactid[0] == "$":
										
									# weird_gid = depm_groupid[2:-1]
									weird_aid_split = depm_artifactid.split('}')
									weird_aid = weird_aid_split[0][2:]
									aid_tail = weird_aid_split[1] 

									weird_aid = weird_aid.lower()

									del weird_aid_split

									if weird_aid == 'project.artifactid' or weird_aid == 'pom.artifactid' or weird_aid == 'artifactid' :
										depm_artifactid = project_aid + aid_tail

									elif weird_aid == 'project.parent.artifactid' or weird_aid == 'parent.artifactid':
										depm_artifactid = parent_project_aid + aid_tail

									else:

										aid_found = False
										root_parent_loop = root

										while(not aid_found):
											properties = root_parent_loop.project.find_all('properties', recursive=False)
											for prop in properties:
												if type(prop) == bs4.element.Tag:
													if prop.find(weird_aid):
														if prop.find(weird_aid).text[0] == '$' and prop.find(weird_aid).text[2:-1] == weird_aid:
															pass
														else:
															depm_artifactid = check_properties_for_artifactid(prop, weird_aid, project_aid, parent_project_aid)
															aid_found = True
															break
											
											if aid_found:
												break				

											try:
												tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop

											except xml.parsers.expat.ExpatError:
												tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop	

											except Exception as e:
												# logf.write(str(e) + " Error on reading file: %s. \n " %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
												logf.write("Error: -->  %s. \n" %(str(e)))
												break
										
										del aid_found
										del root_parent_loop


								if depm_groupid == value['gid'] and depm_artifactid == value['aid'] and depm_version[0] == '$' and depm_scope!='import':

									weird_vid_split = depm_version.split('}')
									weird_vid = weird_vid_split[0][2:]
									vid_tail = weird_vid_split[1]

									weird_vid = weird_vid.lower() # To lower the tag name

									del weird_vid_split 

									if weird_vid == 'project.version' or weird_vid == 'pom.version' or weird_vid == 'version':
										depm_version = project_vid + vid_tail 

									elif weird_vid == 'project.parent.version' or weird_vid == 'parent.version':
										depm_version = parent_project_vid + vid_tail

									else:

										vid_found = False
										root_parent_loop = depm_root

										while(not vid_found):
											properties = root_parent_loop.project.find_all('properties', recursive=False)
											for prop in properties:
												if type(prop) == bs4.element.Tag: 
													if prop.find(weird_vid):
														if prop.find(weird_vid).text[0] == '$' and prop.find(weird_vid).text[2:-1] == weird_vid:
															pass
														else:
															depm_version = check_properties_for_version(prop, weird_vid, project_vid, parent_project_vid)
															depm_version = depm_version + vid_tail
															vid_found = True
															break
											
											if vid_found:
												break
											
											try:
												tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop

											except xml.parsers.expat.ExpatError:
												tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
												root_parent_loop = bs(tree_loop.toxml(), 'lxml')
												del tree_loop	
												
											except Exception as e:
												# logf.write(str(e) + " Error on reading file: %s. \n " %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
												logf.write("Error: -->  %s. \n" %(str(e)))
												break
										
										del vid_found
										del root_parent_loop

										
								if depm_groupid == value['gid'] and depm_artifactid == value['aid'] and depm_scope != "import":
									
									return depm_version

								if depm_scope == "import":

									if depm_version[0] == '$':

										weird_vid_split = depm_version.split('}')
										weird_vid = weird_vid_split[0][2:]
										vid_tail = weird_vid_split[1]

										weird_vid = weird_vid.lower() # To lower the tag name

										del weird_vid_split 

										if weird_vid == 'project.version' or weird_vid == 'pom.version' or weird_vid == 'version':
											depm_version = project_vid + vid_tail 

										elif weird_vid == 'project.parent.version' or weird_vid == 'parent.version':
											depm_version = parent_project_vid + vid_tail

										else:

											vid_found = False
											root_parent_loop = depm_root

											while(not vid_found):
												properties = root_parent_loop.project.find_all('properties', recursive=False)
												for prop in properties:
													if type(prop) == bs4.element.Tag: 
														if prop.find(weird_vid):
															if prop.find(weird_vid).text[0] == '$' and prop.find(weird_vid).text[2:-1] == weird_vid:
																pass
															else:
																depm_version = check_properties_for_version(prop, weird_vid, project_vid, parent_project_vid)
																depm_version = depm_version + vid_tail
																vid_found = True
																break
												
												if vid_found:
													break
												
												try:
													tree_loop = parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom')
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop

												except xml.parsers.expat.ExpatError:
													tree_loop = expatbuilder.parse(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom', False)	
													root_parent_loop = bs(tree_loop.toxml(), 'lxml')
													del tree_loop
													
												except Exception as e:
													# logf.write(str(e) + " Error on reading file: %s. \n " %(poms_base_dir + root_parent_loop.find('parent').find('groupid').text + '-' + root_parent_loop.find('parent').find('artifactid').text + '-' + root_parent_loop.find('parent').find('version').text + '.pom'))
													logf.write("Error: -->  %s. \n" %(str(e)))
													break
											
											del vid_found
											del root_parent_loop
									
									depm_fname = depm_groupid + "-" + depm_artifactid + "-" + depm_version + ".pom"	
									depm_with_import_list.append(depm_fname)		


	for iter_ in range(len(depm_with_import_list)):
		capture_ = get_deps_man_from_import_scope(main_pom_file, depm_with_import_list[iter_], poms_base_dir, key, value, logf)							
		if capture_ == None:
			continue
		else:
			return capture_	

	if has_parent:
		return get_deps_man_from_import_scope(main_pom_file, parent_pom_fname, poms_base_dir, key, value, logf)