コード例 #1
0
def update_by_re(config_path, conf_d = {'datanucleus.schema.validateConstraints': None}):
    with codecs.open(config_path, 'r', 'utf-8') as fp:
        xml = fp.read()
        
    for k0,v0 in conf_d.items():
        re_str = "<name>(?P<key>{})</name>\s+<value>(?P<value>\w+)</value>".format(k0)
        m1 = regex.search(re_str, xml, regex.M)
        re_str = "<name>(?P<key>{})</name>\s+<value />".format(k0)
        m2 = regex.search(re_str, xml, regex.M)
        re_str = "<name>(?P<key>{})</name>\s+(?P<value><value.+?>)".format(k0)
        m3 = regex.search(re_str, xml, regex.M)
        if m1 and v0:
            target_dict = m1.groupdict()
            target_str = m1.group()
            target_str_new = target_str.replace(target_dict['value'], v0)
            xml = xml.replace(target_str, target_str_new)
            
        elif m2 and v0:
            target_str = m2.group()
            target_str_new = target_str.replace('<value />', '<value>{}</value>'.format(v0))
            xml = xml.replace(target_str, target_str_new)
            
        elif m3 and v0 is None:
            target_dict = m3.groupdict()
            xml = xml.replace(target_dict['value'], '<value />')
            
            
    with codecs.open(config_path, 'w', 'utf-8') as fp:
        fp.write(xml)
コード例 #2
0
ファイル: pysiidte1.py プロジェクト: TpcoDev/FEEX_11
def remove_plurals_xml(xml):
    pluralizeds = [
        'Actecos', 'Detalles', 'Referencias', 'DscRcgGlobals', 'ImptoRetens'
    ]
    for k in pluralizeds:
        xml = xml.replace('<%s>' % k, '').replace('</%s>' % k, '')
    return xml
コード例 #3
0
ファイル: pivot.py プロジェクト: judell/wordpress2pivot
  def __init__(self,wp='wp.xml',testing=False,do_images=True):

    self.wp = wp
    self.testing = testing
    self.do_images = do_images

    self.xml = None
    self.pivot_items_xml = ''
    self.images = []
    self.dzc_output = 'dzc_output'

    self.blurb_max_len = 500

    if self.testing:
      doc = minidom.parseString(testentry)
    else:
      f = codecs.open(self.wp, 'r', 'utf-8')
      xml = f.read()
      f.close()
      if xml.find('xmlns:atom="http://www.w3.org/2005/Atom"') == -1:
        xml = xml.replace('xmlns:wp="http://wordpress.org/export/1.0/"', 'xmlns:wp="http://wordpress.org/export/1.0/" xmlns:atom="http://www.w3.org/2005/Atom"')
        f = codecs.open(self.wp, 'w', 'utf-8')
        f.write(xml)
        f.close()
      doc = minidom.parse(self.wp)

    self.items = doc.getElementsByTagName('item')
コード例 #4
0
def main(argv):

    argc = len(argv)

    if (argc is not 1):
        print '\nWarning: incorrect argument(s) to knn.py. Expected arguments:\n\n' \
        '\t- directory (required)\t: directory containing  *.fts files with SIFT features.\n'
        sys.exit(1)

    dir = argv[0]

    xmls = []
    xmls.extend(glob.glob1(dir, '*.xml'))

    print '{} .xml files found in directory {}'.format(len(xmls), dir)

    deleted = 0

    for xml in xmls:
        xml1 = open(dir + '/' + xml)
        xml2 = minidom.parse(xml1)
        itemlist = xml2.getElementsByTagName('Type')
        xml1.close()

        if itemlist[0].firstChild.nodeValue == 'photograph' or itemlist[
                0].firstChild.nodeValue == 'pseudoscan':

            deleted += 1
            fts = dir + '/' + xml.replace('.xml', '.fts')
            jpg = dir + '/' + xml.replace('.xml', '.jpg')

            # If text file exists, delete it.
            if (os.path.isfile(fts)):
                os.remove(fts)

            if (os.path.isfile(jpg)):
                os.remove(jpg)

            os.remove(dir + '/' + xml)

    print '*.fts files of {} "photograph" and "pseudoscan" images deleted.'.format(
        deleted)
コード例 #5
0
ファイル: delete.py プロジェクト: MaartenvdVelde/ML-leaf
def main(argv):

	argc = len(argv)
	
	if (argc is not 1):
		print '\nWarning: incorrect argument(s) to knn.py. Expected arguments:\n\n' \
		'\t- directory (required)\t: directory containing  *.fts files with SIFT features.\n'
		sys.exit(1)
	
	dir = argv[0]
	
	xmls = []
	xmls.extend(glob.glob1(dir, '*.xml'))
	
	print '{} .xml files found in directory {}'.format(len(xmls), dir)
	
	deleted = 0
	
	for xml in xmls:
		xml1 = open(dir + '/' + xml)
		xml2 = minidom.parse(xml1)
		itemlist =  xml2.getElementsByTagName('Type')
		xml1.close()
		
		if itemlist[0].firstChild.nodeValue == 'photograph' or itemlist[0].firstChild.nodeValue == 'pseudoscan':
			
			deleted += 1
			fts = dir + '/' + xml.replace('.xml','.fts')
			jpg = dir + '/' + xml.replace('.xml','.jpg')
			
			
			# If text file exists, delete it.
			if (os.path.isfile(fts)):
				os.remove(fts)
			
			if (os.path.isfile(jpg)):
				os.remove(jpg)
			
			os.remove(dir + '/' + xml)
			
	print '*.fts files of {} "photograph" and "pseudoscan" images deleted.'.format(deleted)
コード例 #6
0
ファイル: top32classes.py プロジェクト: fpecek/ML-leaf
    'Ulmus minor', 'Phillyrea angustifolia', 'Buxus sempervirens',
    'Quercus ilex', 'Olea europaea', 'Viburnum tinus', 'Pittosporum tobira',
    'Hedera helix', 'Ruscus aculeatus', 'Celtis australis',
    'Cercis siliquastrum', 'Populus nigra', 'Nerium oleander',
    'Euphorbia characias', 'Corylus avellana', 'Pistacia lentiscus',
    'Acer campestre', 'Rhus coriaria', 'Acer monspessulanum',
    'Cotinus coggygria', 'Crataegus monogyna', 'Juniperus oxycedrus',
    'Ginkgo biloba', 'Daphne cneorum', 'Populus alba', 'Platanus x hispanica',
    'Arbutus unedo', 'Fraxinus angustifolia', 'Robinia pseudoacacia',
    'Laurus nobilis', 'Diospyros kaki', 'Punica granatum'
]

count = len(xmls)

for xml in xmls:
    xml1 = open(os.path.abspath(os.path.dirname(__file__)) + '/' + xml)
    xml2 = minidom.parse(xml1)
    itemlist = xml2.getElementsByTagName('ClassId')
    if itemlist[0].firstChild.nodeValue not in top32classes:
        count -= 1
        jpg = xml.replace('.xml', '.jpg')
        fts = xml.replace('.xml', '.fts')
        hst = xml.replace('.xml', '.hst')
        if (os.path.isfile(jpg)):
            os.remove(os.path.abspath(os.path.dirname(__file__)) + '/' + jpg)
        if (os.path.isfile(fts)):
            os.remove(os.path.abspath(os.path.dirname(__file__)) + '/' + fts)
        if (os.path.isfile(hst)):
            os.remove(os.path.abspath(os.path.dirname(__file__)) + '/' + hst)

print '{} items deleted'.format(count)
コード例 #7
0
'Ginkgo biloba',
'Daphne cneorum',
'Populus alba',
'Platanus x hispanica',
'Arbutus unedo',
'Fraxinus angustifolia',
'Robinia pseudoacacia',
'Laurus nobilis',
'Diospyros kaki',
'Punica granatum'
]

count = len(xmls)

for xml in xmls:
	xml1 = open(os.path.abspath(os.path.dirname(__file__)) + '/' + xml)
	xml2 = minidom.parse(xml1)
	itemlist =  xml2.getElementsByTagName('ClassId')
	if itemlist[0].firstChild.nodeValue not in top32classes:
		count -= 1
		jpg = xml.replace('.xml','.jpg')
		fts = xml.replace('.xml','.fts')
		hst = xml.replace('.xml','.hst') 
		if (os.path.isfile(jpg)):
			os.remove(os.path.abspath(os.path.dirname(__file__)) + '/' + jpg)
		if(os.path.isfile(fts)):
			os.remove(os.path.abspath(os.path.dirname(__file__)) + '/' + fts)
		if(os.path.isfile(hst)):
			os.remove(os.path.abspath(os.path.dirname(__file__)) + '/' + hst)

print '{} items deleted'.format(count)