How to use all_headers method in Playwright Python

Best Python code snippet using playwright-python

nuxeo_get_metadata.py

Source:nuxeo_get_metadata.py Github

copy

Full Screen

1#!/usr/bin/env python2#This script requires unicodecsv to be installed3#This script allows the users to download metadata from nuxeo and place it either in a google spreadsheet or tsv file4#it also allows for metadata to be downloaded from the collection or item level5#it also asks if all headers should be downloaded or if the empty items should not be downloaded6#Nuxeo has to be installed for this script to work7__author__ = "Niqui O'Neill"89import unicodecsv as csv10import os11from pynux import utils1213def get_title(data2, x): #gets title14 data2['Title'] = x['properties']['dc:title']1516def get_filepath(data2, x): #gets filepath17 data2['File path'] = x['path']1819def get_type(data2, x, all_headers): #gets type, inputs are dictionary (data2), nuxeo (x), all_headers input20 if x['properties']['ucldc_schema:type'] != None and x['properties']['ucldc_schema:type'] != '':21 data2['Type'] = x['properties']['ucldc_schema:type']22 elif all_headers == 'y' or all_headers == 'Y':23 data2['Type'] = ''2425def get_alt_title(data2, x, all_headers): 26 altnumb = 027 if type(x['properties']['ucldc_schema:alternativetitle']) == list and len(x['properties']['ucldc_schema:alternativetitle']) > 0:28 while altnumb < len(x['properties']['ucldc_schema:alternativetitle']):29 numb = altnumb + 130 name = 'Alternative Title %d' % numb31 data2[name]= x['properties']['ucldc_schema:alternativetitle'][altnumb]32 altnumb += 133 elif all_headers == 'y' or all_headers == 'Y':34 data2['Alternative Title 1'] = ''35def get_identifier(data2, x, all_headers):36 if x['properties']['ucldc_schema:identifier'] != None and x['properties']['ucldc_schema:identifier'] != '':37 data2['Identifier'] = x['properties']['ucldc_schema:identifier']38 elif all_headers == 'y' or all_headers == 'Y':39 data2['Identifier'] = ''40def get_local_identifier(data2, x, all_headers):41 locnumb = 042 if type(x['properties']['ucldc_schema:localidentifier']) == list and len(x['properties']['ucldc_schema:localidentifier']) > 0:43 while locnumb < len(x['properties']['ucldc_schema:localidentifier']):44 numb = locnumb + 145 name = 'Local Identifier %d' % numb46 data2[name]= x['properties']['ucldc_schema:localidentifier'][locnumb]47 locnumb += 148 elif all_headers == 'y' or all_headers == 'Y':49 data2['Local Identifier 1'] = ''50def get_campus_unit(data2, x, all_headers):51 campnumb = 052 if type(x['properties']['ucldc_schema:campusunit']) == list and len(x['properties']['ucldc_schema:campusunit']) > 0:53 while campnumb < len(x['properties']['ucldc_schema:campusunit']):54 numb = campnumb + 155 name = 'Campus/Unit %d' % numb56 data2[name]= x['properties']['ucldc_schema:campusunit'][campnumb]57 campnumb += 158 elif all_headers == 'y' or all_headers == 'Y':59 data2['Campus/Unit 1'] = ''60def get_date(data2, x, all_headers):61 datenumb = 062 if type(x['properties']['ucldc_schema:date']) == list and len(x['properties']['ucldc_schema:date']) > 0:63 while datenumb < len(x['properties']['ucldc_schema:date']):64 numb = datenumb + 165 try:66 name = 'Date %d' % numb67 if x['properties']['ucldc_schema:date'][datenumb]['date'] != None and x['properties']['ucldc_schema:date'][datenumb]['date'] != '':68 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['date']69 elif all_headers == 'y' or all_headers == 'Y':70 data2[name] = ''71 except:72 pass73 try:74 name = 'Date %d Type' % numb75 if x['properties']['ucldc_schema:date'][datenumb]['datetype'] != None and x['properties']['ucldc_schema:date'][datenumb]['datetype'] != '':76 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['datetype']77 elif all_headers == 'y' or all_headers == 'Y':78 data2[name] = ''79 except:80 pass81 try:82 name = 'Date %d Inclusive Start' % numb83 if x['properties']['ucldc_schema:date'][datenumb]['inclusivestart'] != None and x['properties']['ucldc_schema:date'][datenumb]['inclusivestart'] != '':84 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['inclusivestart']85 elif all_headers == 'y' or all_headers == 'Y':86 data2[name] = ''87 except:88 pass89 try:90 name = 'Date %d Inclusive End' % numb91 if x['properties']['ucldc_schema:date'][datenumb]['inclusiveend'] != None and x['properties']['ucldc_schema:date'][datenumb]['inclusiveend'] != '':92 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['inclusiveend']93 elif all_headers == 'y' or all_headers == 'Y':94 data2[name] = ''95 except:96 pass97 try:98 name = 'Date %d Single' % numb99 if x['properties']['ucldc_schema:date'][datenumb]['single'] != None and x['properties']['ucldc_schema:date'][datenumb]['single'] != '':100 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['single']101 elif all_headers == 'y' or all_headers == 'Y':102 data2[name] = ''103 except:104 pass105 datenumb += 1106 elif all_headers == 'y' or all_headers == 'Y':107 data2['Date 1'] = ''108 data2['Date 1 Type'] = ''109 data2['Date 1 Inclusive Start'] = ''110 data2['Date 1 Inclusive End'] = ''111 data2['Date 1 Single'] = ''112def get_publication(data2, x, all_headers):113 pubnumb = 0114 if type(x['properties']['ucldc_schema:publisher']) == list and len(x['properties']['ucldc_schema:publisher']) > 0:115 while pubnumb < len(x['properties']['ucldc_schema:publisher']):116 numb = pubnumb + 1117 name = 'Publication/Origination Info %d' % numb118 data2[name]= x['properties']['ucldc_schema:publisher'][pubnumb]119 pubnumb += 1120 elif all_headers == 'y' or all_headers == 'Y':121 data2['Publication/Origination Info 1'] = ''122123def get_creator(data2, x, all_headers):124 creatnumb = 0125 if type(x['properties']['ucldc_schema:creator']) == list and len(x['properties']['ucldc_schema:creator']) > 0:126 while creatnumb < len(x['properties']['ucldc_schema:creator']):127 numb = creatnumb + 1128 try:129 name = 'Creator %d Name' % numb130 if x['properties']['ucldc_schema:creator'][creatnumb]['name'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['name'] != '':131 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['name']132 elif all_headers == 'y' or all_headers == 'Y':133 data2[name] = ''134 except:135 pass136 try:137 name = 'Creator %d Name Type' % numb138 if x['properties']['ucldc_schema:creator'][creatnumb]['nametype'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['nametype'] != '':139 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['nametype']140 elif all_headers == 'y' or all_headers == 'Y':141 data2[name] = ''142 except:143 pass144 try:145 name = 'Creator %d Role' % numb146 if x['properties']['ucldc_schema:creator'][creatnumb]['role'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['role'] != '':147 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['role']148 elif all_headers == 'y' or all_headers == 'Y':149 data2[name] = ''150 except:151 pass152 try:153 name = 'Creator %d Source' % numb154 if x['properties']['ucldc_schema:creator'][creatnumb]['source'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['source'] != '':155 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['source']156 elif all_headers == 'y' or all_headers == 'Y':157 data2[name] = ''158 except:159 pass160 try:161 name = 'Creator %d Authority ID' % numb162 if x['properties']['ucldc_schema:creator'][creatnumb]['authorityid'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['authorityid'] != '':163 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['authorityid']164 elif all_headers == 'y' or all_headers == 'Y':165 data2[name] = ''166 except:167 pass168 creatnumb += 1169 elif all_headers == 'y' or all_headers == 'Y':170 data2['Creator 1 Name'] = ''171 data2['Creator 1 Name Type'] = ''172 data2['Creator 1 Role'] = ''173 data2['Creator 1 Source'] = ''174 data2['Creator 1 Authority ID'] = ''175176def get_contributor(data2, x, all_headers):177 contnumb = 0178 if type(x['properties']['ucldc_schema:contributor']) == list and len(x['properties']['ucldc_schema:contributor']) > 0:179 while contnumb < len(x['properties']['ucldc_schema:contributor']):180 numb = contnumb + 1181 try:182 name = 'Contributor %d Name' % numb183 if x['properties']['ucldc_schema:contributor'][contnumb]['name'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['name'] != '':184 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['name']185 elif all_headers == 'y' or all_headers == 'Y':186 data2[name] = ''187 except:188 pass189 try:190 name = 'Contributor %d Name Type' % numb191 if x['properties']['ucldc_schema:contributor'][contnumb]['nametype'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['nametype'] != '':192 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['nametype']193 elif all_headers == 'y' or all_headers == 'Y':194 data2[name] = ''195 except:196 pass197 try:198 name = 'Contributor %d Role' % numb199 if x['properties']['ucldc_schema:contributor'][contnumb]['role'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['role'] != '':200 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['role']201 elif all_headers == 'y' or all_headers == 'Y':202 data2[name] = ''203 except:204 pass205 try:206 name = 'Contributor %d Source' % numb207 if x['properties']['ucldc_schema:contributor'][contnumb]['source'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['source'] != '':208 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['source']209 elif all_headers == 'y' or all_headers == 'Y':210 data2[name] = ''211 except:212 pass213 try:214 name = 'Contributor %d Authority ID' % numb215 if x['properties']['ucldc_schema:contributor'][contnumb]['authorityid'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['authorityid'] != '':216 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['authorityid']217 elif all_headers == 'y' or all_headers == 'Y':218 data2[name] = ''219 except:220 pass221 contnumb += 1222 elif all_headers == 'y' or all_headers == 'Y':223 data2['Contributor 1 Name'] = ''224 data2['Contributor 1 Name Type'] = ''225 data2['Contributor 1 Role'] = ''226 data2['Contributor 1 Source'] = ''227 data2['Contributor 1 Authority ID'] = ''228229def get_format(data2, x, all_headers):230 if x['properties']['ucldc_schema:physdesc'] != None and x['properties']['ucldc_schema:physdesc'] != '':231 data2['Format/Physical Description'] = x['properties']['ucldc_schema:physdesc']232 elif all_headers == 'y' or all_headers == 'Y':233 data2['Format/Physical Description'] = ''234def get_description(data2, x, all_headers):235 descnumb = 0236 if type(x['properties']['ucldc_schema:description']) == list and len(x['properties']['ucldc_schema:description']) > 0:237 while descnumb < len(x['properties']['ucldc_schema:description']):238 numb = descnumb + 1239 try:240 name = "Description %d Note" % numb241 if x['properties']['ucldc_schema:description'][descnumb]['item'] != None and x['properties']['ucldc_schema:description'][descnumb]['item'] != '':242 data2[name] = x['properties']['ucldc_schema:description'][descnumb]['item']243 elif all_headers == 'y' or all_headers == 'Y':244 data2[name] = ''245 except:246 pass247 try:248 name = "Description %d Type" % numb249 if x['properties']['ucldc_schema:description'][descnumb]['type'] != None and x['properties']['ucldc_schema:description'][descnumb]['type'] != '':250 data2[name] = x['properties']['ucldc_schema:description'][descnumb]['type']251 elif all_headers == 'y' or all_headers == 'Y':252 data2[name] = ''253 except:254 pass255 descnumb += 1256 elif all_headers == 'y' or all_headers == 'Y':257 data2['Description 1 Note'] = ''258 data2['Description 1 Type'] = ''259def get_extent(data2, x, all_headers):260 if x['properties']['ucldc_schema:extent'] != None and x['properties']['ucldc_schema:extent'] != '':261 data2['Extent'] = x['properties']['ucldc_schema:extent']262 elif all_headers == 'y' or all_headers == 'Y':263 data2['Extent'] = ''264def get_language(data2, x, all_headers):265 langnumb = 0266 if type(x['properties']['ucldc_schema:language']) == list and len(x['properties']['ucldc_schema:language']) > 0:267 while langnumb < len(x['properties']['ucldc_schema:language']):268 numb = langnumb + 1269 try:270 name = "Language %d" % numb271 if x['properties']['ucldc_schema:language'][langnumb]['language'] != None and x['properties']['ucldc_schema:language'][langnumb]['language'] != '':272 data2[name] = x['properties']['ucldc_schema:language'][langnumb]['language']273 elif all_headers == 'y' or all_headers == 'Y':274 data2[name] = ''275 except:276 pass277 try:278 name = "Language %d Code" % numb279 if x['properties']['ucldc_schema:language'][langnumb]['code'] != None and x['properties']['ucldc_schema:language'][langnumb]['code'] != '':280 data2[name] = x['properties']['ucldc_schema:language'][langnumb]['code']281 elif all_headers == 'y' or all_headers == 'Y':282 data2[name] = ''283 except:284 pass285 langnumb += 1286 elif all_headers == 'y' or all_headers == 'Y':287 data2['Language 1'] = ''288 data2['Language 1 Code'] = ''289290def get_temporal_coverage(data2, x, all_headers):291 tempnumb = 0292 if type(x['properties']['ucldc_schema:temporalcoverage']) == list and len(x['properties']['ucldc_schema:temporalcoverage']) > 0:293 while tempnumb < len(x['properties']['ucldc_schema:temporalcoverage']):294 numb = tempnumb + 1295 name = 'Temporal Coverage %d' % numb296 data2[name]= x['properties']['ucldc_schema:temporalcoverage'][tempnumb]297 tempnumb += 1298 elif all_headers == 'y' or all_headers == 'Y':299 data2['Temporal Coverage 1'] = ''300301def get_transcription(data2, x, all_headers):302 if x['properties']['ucldc_schema:transcription'] != None and x['properties']['ucldc_schema:transcription'] != '':303 data2['Transcription'] = x['properties']['ucldc_schema:transcription']304 elif all_headers == 'y' or all_headers == 'Y':305 data2['Transcription'] = ''306307def get_access_restrictions(data2, x, all_headers):308 if x['properties']['ucldc_schema:accessrestrict'] != None and x['properties']['ucldc_schema:accessrestrict'] != '':309 data2['Access Restrictions'] = x['properties']['ucldc_schema:accessrestrict']310 elif all_headers == 'y' or all_headers == 'Y':311 data2['Access Restrictions'] = ''312def get_rights_statement(data2, x, all_headers):313 if x['properties']['ucldc_schema:rightsstatement'] != None and x['properties']['ucldc_schema:rightsstatement'] != '':314 data2['Copyright Statement'] = x['properties']['ucldc_schema:rightsstatement']315 elif all_headers == 'y' or all_headers == 'Y':316 data2['Copyright Statement'] = ''317def get_rights_status(data2, x, all_headers):318 if x['properties']['ucldc_schema:rightsstatus'] != None and x['properties']['ucldc_schema:rightsstatus'] != '':319 data2['Copyright Status'] = x['properties']['ucldc_schema:rightsstatus']320 elif all_headers == 'y' or all_headers == 'Y':321 data2['Copyright Status'] = ''322def get_copyright_holder(data2, x, all_headers):323 rightsnumb = 0324 if type(x['properties']['ucldc_schema:rightsholder']) == list and len(x['properties']['ucldc_schema:rightsholder']) > 0:325 while rightsnumb < len(x['properties']['ucldc_schema:rightsholder']):326 numb = rightsnumb + 1327 try:328 name = 'Copyright Holder %d Name' % numb329 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name'] != '':330 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name']331 elif all_headers == 'y' or all_headers == 'Y':332 data2[name] = ''333 except:334 pass335 try:336 name = 'Copyright Holder %d Name Type' % numb337 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype'] != '':338 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype']339 elif all_headers == 'y' or all_headers == 'Y':340 data2[name] = ''341 except:342 pass343 try:344 name = 'Copyright Holder %d Source' % numb345 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source'] != '':346 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source']347 elif all_headers == 'y' or all_headers == 'Y':348 data2[name] = ''349 except:350 pass351 try:352 name = 'Copyright Holder %d Authority ID' % numb353 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid'] != '':354 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid']355 elif all_headers == 'y' or all_headers == 'Y':356 data2[name] = ''357 except:358 pass359 rightsnumb += 1360 elif all_headers == 'y' or all_headers == 'Y':361 data2['Copyright Holder 1 Name'] = ''362 data2['Copyright Holder 1 Name Type'] = ''363 data2['Copyright Holder 1 Source'] = ''364 data2['Copyright Holder 1 Authority ID'] = ''365366def get_copyright_info(data2, x, all_headers):367 if x['properties']['ucldc_schema:rightscontact'] != None and x['properties']['ucldc_schema:rightscontact'] != '':368 data2['Copyright Contact'] = x['properties']['ucldc_schema:rightscontact']369 elif all_headers == 'y' or all_headers == 'Y':370 data2['Copyright Contact'] = ''371372 if x['properties']['ucldc_schema:rightsnotice'] != None and x['properties']['ucldc_schema:rightsnotice'] != '':373 data2['Copyright Notice'] = x['properties']['ucldc_schema:rightsnotice']374 elif all_headers == 'y' or all_headers == 'Y':375 data2['Copyright Notice'] = ''376377 if x['properties']['ucldc_schema:rightsdeterminationdate'] != None and x['properties']['ucldc_schema:rightsdeterminationdate'] != '':378 data2['Copyright Determination Date'] = x['properties']['ucldc_schema:rightsdeterminationdate']379 elif all_headers == 'y' or all_headers == 'Y':380 data2['Copyright Determination Date'] = ''381382 if x['properties']['ucldc_schema:rightsstartdate'] != None and x['properties']['ucldc_schema:rightsstartdate'] != '':383 data2['Copyright Start Date'] = x['properties']['ucldc_schema:rightsstartdate']384 elif all_headers == 'y' or all_headers == 'Y':385 data2['Copyright Start Date'] = ''386387 if x['properties']['ucldc_schema:rightsenddate'] != None and x['properties']['ucldc_schema:rightsenddate'] != '':388 data2['Copyright End Date'] = x['properties']['ucldc_schema:rightsenddate']389 elif all_headers == 'y' or all_headers == 'Y':390 data2['Copyright End Date'] = ''391392 if x['properties']['ucldc_schema:rightsjurisdiction'] != None and x['properties']['ucldc_schema:rightsjurisdiction'] != '':393 data2['Copyright Jurisdiction'] = x['properties']['ucldc_schema:rightsjurisdiction']394 elif all_headers == 'y' or all_headers == 'Y':395 data2['Copyright Jurisdiction'] = ''396397 if x['properties']['ucldc_schema:rightsnote'] != None and x['properties']['ucldc_schema:rightsnote'] != '':398 data2['Copyright Note'] = x['properties']['ucldc_schema:rightsnote']399 elif all_headers == 'y' or all_headers == 'Y':400 data2['Copyright Note'] = ''401402def get_collection(data2, x, all_headers):403 collnumb = 0404 if type(x['properties']['ucldc_schema:collection']) == list and len(x['properties']['ucldc_schema:collection']) > 0:405 while collnumb < len(x['properties']['ucldc_schema:collection']):406 numb = collnumb + 1407 name = 'Collection %d' % numb408 data2[name]= x['properties']['ucldc_schema:collection'][collnumb]409 collnumb += 1410 elif all_headers == 'y' or all_headers == 'Y':411 data2['Collection 1'] = ''412413def get_related_resource(data2, x, all_headers):414 relnumb = 0415 if type(x['properties']['ucldc_schema:relatedresource']) == list and len(x['properties']['ucldc_schema:relatedresource']) > 0:416 while relnumb < len(x['properties']['ucldc_schema:relatedresource']):417 numb = relnumb + 1418 name = 'Related Resource %d' % numb419 data2[name]= x['properties']['ucldc_schema:relatedresource'][relnumb]420 relnumb += 1421 elif all_headers == 'y' or all_headers == 'Y':422 data2['Related Resource 1'] = ''423424def get_source(data2, x, all_headers):425 if x['properties']['ucldc_schema:source'] != None and x['properties']['ucldc_schema:source'] != '':426 data2['Source'] = x['properties']['ucldc_schema:source']427 elif all_headers == 'y' or all_headers == 'Y':428 data2['Source'] = ''429430def get_subject_name(data2, x, all_headers):431 subnumb = 0432 if type(x['properties']['ucldc_schema:subjectname']) == list and len(x['properties']['ucldc_schema:subjectname']) > 0:433 while subnumb < len(x['properties']['ucldc_schema:subjectname']):434 numb = subnumb + 1435 try:436 name = 'Subject (Name) %d Name' % numb437 if x['properties']['ucldc_schema:subjectname'][subnumb]['name'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['name'] != '':438 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['name']439 elif all_headers == 'y' or all_headers == 'Y':440 data2[name] = ''441 except:442 pass443 try:444 name = 'Subject (Name) %d Name Type' % numb445 if x['properties']['ucldc_schema:subjectname'][subnumb]['name_type'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['name_type'] != '':446 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['name_type']447 elif all_headers == 'y' or all_headers == 'Y':448 data2[name] = ''449 except:450 pass451 try:452 name = 'Subject (Name) %d Role' % numb453 if x['properties']['ucldc_schema:subjectname'][subnumb]['role'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['role'] != '':454 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['role']455 elif all_headers == 'y' or all_headers == 'Y':456 data2[name] = ''457 except:458 pass459 try:460 name = 'Subject (Name) %d Source' % numb461 if x['properties']['ucldc_schema:subjectname'][subnumb]['source'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['source'] != '':462 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['source']463 elif all_headers == 'y' or all_headers == 'Y':464 data2[name] = ''465 except:466 pass467 try:468 name = 'Subject (Name) %d Authority ID' % numb469 if x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid'] != '':470 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid']471 elif all_headers == 'y' or all_headers == 'Y':472 data2[name] = ''473 except:474 pass475 subnumb += 1476 elif all_headers == 'y' or all_headers == 'Y':477 data2['Subject (Name) 1 Name'] = ''478 data2['Subject (Name) 1 Name Type'] = ''479 data2['Subject (Name) 1 Role'] = ''480 data2['Subject (Name) 1 Source'] = ''481 data2['Subject (Name) 1 Authority ID'] = ''482483def get_place(data2, x, all_headers):484 plcnumb = 0485 if type(x['properties']['ucldc_schema:place']) == list and len(x['properties']['ucldc_schema:place']) > 0:486 while plcnumb < len(x['properties']['ucldc_schema:place']):487 numb = plcnumb + 1488 try:489 name = 'Place %d Name' % numb490 if x['properties']['ucldc_schema:place'][plcnumb]['name'] != None and x['properties']['ucldc_schema:place'][plcnumb]['name'] != '':491 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['name']492 elif all_headers == 'y' or all_headers == 'Y':493 data2[name] = ''494 except:495 pass496 try:497 name = 'Place %d Coordinates' % numb498 if x['properties']['ucldc_schema:place'][plcnumb]['coordinates'] != None and x['properties']['ucldc_schema:place'][plcnumb]['coordinates'] != '':499 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['coordinates']500 elif all_headers == 'y' or all_headers == 'Y':501 data2[name] = ''502 except:503 pass504 try:505 name = 'Place %d Source' % numb506 if x['properties']['ucldc_schema:place'][plcnumb]['source'] != None and x['properties']['ucldc_schema:place'][plcnumb]['source'] != '':507 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['source']508 elif all_headers == 'y' or all_headers == 'Y':509 data2[name] = ''510 except:511 pass512 try:513 name = 'Place %d Authority ID' % numb514 if x['properties']['ucldc_schema:place'][plcnumb]['authorityid'] != None and x['properties']['ucldc_schema:place'][plcnumb]['authorityid'] != '':515 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['authorityid']516 elif all_headers == 'y' or all_headers == 'Y':517 data2[name] = ''518 except:519 pass520 plcnumb += 1521 elif all_headers == 'y' or all_headers == 'Y':522 data2['Place 1 Name'] = ''523 data2['Place 1 Coordinates'] = ''524 data2['Place 1 Source'] = ''525 data2['Place 1 Authority ID'] = ''526527def get_subject_topic(data2, x, all_headers):528 topnumb = 0529 if type(x['properties']['ucldc_schema:subjecttopic']) == list and len(x['properties']['ucldc_schema:subjecttopic']) > 0:530 while topnumb < len(x['properties']['ucldc_schema:subjecttopic']):531 numb = topnumb + 1532 try:533 name = 'Subject (Topic) %d Heading' % numb534 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading'] != '':535 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading']536 elif all_headers == 'y' or all_headers == 'Y':537 data2[name] = ''538 except:539 pass540 try:541 name = 'Subject (Topic) %d Heading Type' % numb542 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype'] != '':543 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype']544 elif all_headers == 'y' or all_headers == 'Y':545 data2[name] = ''546 except:547 pass548 try:549 name = 'Subject (Topic) %d Source' % numb550 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['source'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['source'] != '':551 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['source']552 elif all_headers == 'y' or all_headers == 'Y':553 data2[name] = ''554 except:555 pass556 try:557 name = 'Subject (Topic) %d Authority ID' % numb558 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid'] != '':559 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid']560 elif all_headers == 'y' or all_headers == 'Y':561 data2[name] = ''562 except:563 pass564 topnumb += 1565 elif all_headers == 'y' or all_headers == 'Y':566 data2['Subject (Topic) 1 Heading'] = ''567 data2['Subject (Topic) 1 Heading Type'] = ''568 data2['Subject (Topic) 1 Source'] = ''569 data2['Subject (Topic) 1 Authority ID'] = ''570571def get_form_genre(data2, x, all_headers):572 formnumb = 0573 if type(x['properties']['ucldc_schema:formgenre']) == list and len(x['properties']['ucldc_schema:formgenre']) > 0:574 while formnumb < len(x['properties']['ucldc_schema:formgenre']):575 numb = formnumb + 1576 try:577 name = 'Form/Genre %d Heading' % numb578 if x['properties']['ucldc_schema:formgenre'][formnumb]['heading'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['heading'] != '':579 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['heading']580 elif all_headers == 'y' or all_headers == 'Y':581 data2[name] = ''582 except:583 pass584 try:585 name = 'Form/Genre %d Source' % numb586 if x['properties']['ucldc_schema:formgenre'][formnumb]['source'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['source'] != '':587 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['source']588 elif all_headers == 'y' or all_headers == 'Y':589 data2[name] = ''590 except:591 pass592 try:593 name = 'Form/Genre %d Authority ID' % numb594 if x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid'] != '':595 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid']596 elif all_headers == 'y' or all_headers == 'Y':597 data2[name] = ''598 except:599 pass600 formnumb += 1601 elif all_headers == 'y' or all_headers == 'Y':602 data2['Form/Genre 1 Heading'] = ''603 data2['Form/Genre 1 Source'] = ''604 data2['Form/Genre 1 Authority ID'] = ''605606def get_provenance(data2, x, all_headers):607 provnumb = 0608 if type(x['properties']['ucldc_schema:provenance']) == list and len(x['properties']['ucldc_schema:provenance']) > 0:609 while provnumb < len(x['properties']['ucldc_schema:provenance']):610 numb = provnumb + 1611 name = 'Provenance %d' % numb612 data2[name]= x['properties']['ucldc_schema:provenance'][provnumb]613 provnumb += 1614 elif all_headers == 'y' or all_headers == 'Y':615 data2['Provenance 1'] = ''616617def get_physical_location(data2, x, all_headers):618 if x['properties']['ucldc_schema:physlocation'] != None and x['properties']['ucldc_schema:physlocation'] != '':619 data2['Physical Location'] = x['properties']['ucldc_schema:physlocation']620 elif all_headers == 'y' or all_headers == 'Y':621 data2['Physical Location'] = ''622623def object_level(filepath):624 nx = utils.Nuxeo()625 data = []626 for n in nx.children(filepath):627 data2 = {}628 629 get_title(data2, n)630 get_filepath(data2, n)631 get_type(data2, n, all_headers)632 get_alt_title(data2, n, all_headers)633 get_identifier(data2, n, all_headers)634 get_local_identifier(data2, n, all_headers)635 get_campus_unit(data2, n, all_headers)636 get_date(data2, n, all_headers)637 get_publication(data2, n, all_headers)638 get_creator(data2, n, all_headers)639 get_contributor(data2, n, all_headers)640 get_format(data2, n, all_headers)641 get_description(data2, n, all_headers)642 get_extent(data2, n, all_headers)643 get_language(data2, n, all_headers)644 get_temporal_coverage(data2, n, all_headers)645 get_transcription(data2, n, all_headers)646 get_access_restrictions(data2, n, all_headers)647 get_rights_statement(data2, n, all_headers)648 get_rights_status(data2, n, all_headers)649 get_copyright_holder(data2, n, all_headers)650 get_copyright_info(data2, n, all_headers)651 get_collection(data2, n, all_headers)652 get_related_resource(data2, n, all_headers)653 get_source(data2, n, all_headers)654 get_subject_name(data2, n, all_headers)655 get_place(data2, n, all_headers)656 get_subject_topic(data2, n, all_headers)657 get_form_genre(data2, n, all_headers)658 get_provenance(data2, n, all_headers)659 get_physical_location(data2, n, all_headers)660661 data.append(data2)662663 fieldnames = ['File path', 'Title', 'Type'] #ensures that File path, Title and Type are the first three rows664 for data2 in data:665 for key, value in data2.items():666 if key not in fieldnames:667 fieldnames.append(key)668669 return {'fieldnames':fieldnames, 'data':data, 'filename':"nuxeo_object_%s.tsv"%nx.get_metadata(path=filepath)['properties']['dc:title']}670671def item_level(filepath):672 nx = utils.Nuxeo()673 data = []674 for n in nx.children(filepath):675 for x in nx.children(n['path']):676 data2 = {}677 get_title(data2, x)678 get_filepath(data2, x)679 get_type(data2, x, all_headers)680 get_alt_title(data2, x, all_headers)681 get_identifier(data2, x, all_headers)682 get_local_identifier(data2, x, all_headers)683 get_campus_unit(data2, x, all_headers)684 get_date(data2, x, all_headers)685 get_publication(data2, x, all_headers)686 get_creator(data2, x, all_headers)687 get_contributor(data2, x, all_headers)688 get_format(data2, x, all_headers)689 get_description(data2, x, all_headers)690 get_extent(data2, x, all_headers)691 get_language(data2, x, all_headers)692 get_temporal_coverage(data2, x, all_headers)693 get_transcription(data2, x, all_headers)694 get_access_restrictions(data2, x, all_headers)695 get_rights_statement(data2, x, all_headers)696 get_rights_status(data2, x, all_headers)697 get_copyright_holder(data2, x, all_headers)698 get_copyright_info(data2, x, all_headers)699 get_collection(data2, x, all_headers)700 get_related_resource(data2, x, all_headers)701 get_source(data2, x, all_headers)702 get_subject_name(data2, x, all_headers)703 get_place(data2, x, all_headers)704 get_subject_topic(data2, x, all_headers)705 get_form_genre(data2, x, all_headers)706 get_provenance(data2, x, all_headers)707 get_physical_location(data2, x, all_headers)708 data.append(data2)709710 fieldnames = ['File path', 'Title', 'Type'] #ensures that File path, Title and Type are the first three rows711 for data2 in data:712 for key, value in data2.items():713 if key not in fieldnames:714 fieldnames.append(key)715716 return {'fieldnames':fieldnames, 'data':data, 'filename':"nuxeo_item_%s.tsv"%nx.get_metadata(path=filepath)['properties']['dc:title']}717 #returns dictionary with fieldnames, data and filename; This is used for google functions and writing to tsv if google function not choosed718719def google_object(filepath, url):720 import gspread721 from oauth2client.service_account import ServiceAccountCredentials722 obj = object_level(filepath)723 nx = utils.Nuxeo()724 scope = ['https://spreadsheets.google.com/feeds',725 'https://www.googleapis.com/auth/drive']726 creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)727 client = gspread.authorize(creds)728 with open("temp.csv", "wb") as csvfile:729 writer = csv.DictWriter(csvfile, fieldnames=obj['fieldnames'])730 writer.writeheader()731 for row in obj['data']:732 writer.writerow(row)733 with open("temp.csv", encoding="utf8") as f:734 s = f.read() + '\n'735 sheet_id = client.open_by_url(url).id736 client.import_csv(sheet_id, s)737 client.open_by_key(sheet_id).sheet1.update_title("nuxeo_object_%s"%nx.get_metadata(path=filepath)['properties']['dc:title'])738 os.remove("temp.csv")739740def google_item(filepath, url):741 import gspread742 from oauth2client.service_account import ServiceAccountCredentials743 item = item_level(filepath)744 nx = utils.Nuxeo()745 scope = ['https://spreadsheets.google.com/feeds',746 'https://www.googleapis.com/auth/drive']747 creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)748 client = gspread.authorize(creds)749 with open("temp.csv", "wb") as csvfile: #creates temporary csv file750 writer = csv.DictWriter(csvfile, fieldnames=item['fieldnames'])751 writer.writeheader()752 for row in item['data']:753 writer.writerow(row)754 with open("temp.csv", encoding="utf8") as f: #opens and reads temporary csv file755 s = f.read() + '\n'756 sheet_id = client.open_by_url(url).id 757 client.import_csv(sheet_id, s)#writes csv file to google sheet758 client.open_by_key(sheet_id).sheet1.update_title("nuxeo_item_%s"%nx.get_metadata(path=filepath)['properties']['dc:title'])759 os.remove("temp.csv") #removes temporary csv760def main():761 try:762 filepath = raw_input('Enter Nuxeo File Path: ')763 except:764 filepath = input('Enter Nuxeo File Path: ')765 try:766 choice = raw_input('Object Level (ENTER O) or Item Level (ENTER I): ')767 except:768 choice = input('Object Level (ENTER O) or Item Level (ENTER I): ')769 try:770 url = raw_input('Enter Google Sheet URL: ')771 except:772 url = input('Enter Google Sheet URL: ')773 try:774 all_headers = raw_input('All Headers? (Y/N): ')775 except:776 all_headers = input('All Headers? (Y/N): ')777778 if 'O' in choice or 'o' in choice:779 if 'http' in url:780 try:781 google_object(filepath, url)782 except:783 print("\n*********\nWriting to Google document did not work. Make sure that Google document has been shared with API key email address")784 else:785 obj = object_level(filepath)786 with open(obj['filename'], "wb") as csvfile:787 writer = csv.DictWriter(csvfile, fieldnames=obj['fieldnames'], delimiter="\t")788 writer.writeheader()789 for row in obj['data']:790 writer.writerow(row)791 if 'I' in choice or 'i' in choice:792 if 'http' in url:793 try:794 google_item(filepath, url)795 except:796 print("\n*********\nWriting to Google document did not work. Make sure that Google document has been shared with API key email address")797 else:798 item = item_level(filepath)799 with open(item['filename'], "wb") as csvfile:800 writer = csv.DictWriter(csvfile, fieldnames=item['fieldnames'], delimiter="\t")801 writer.writeheader()802 for row in item['data']:803 writer.writerow(row)804805if __name__ == "__main__": ...

Full Screen

Full Screen

export_nuxeo.py

Source:export_nuxeo.py Github

copy

Full Screen

1#Written by Niqui O'Neill2#This script requires unicodecsv to be installed3#This script allows the users to download metadata from nuxeo and place it either in a google spreadsheet or tsv file4#it also allows for metadata to be downloaded from the collection or item level5#it also asks if all headers should be downloaded or if the empty items should not be downloaded6#Nuxeo has to be installed for this script to work7import unicodecsv as csv8import os9try:10 filepath = raw_input('Enter Nuxeo File Path: ')11except:12 filepath = input('Enter Nuxeo File Path: ')13try:14 choice = raw_input('Object Level (ENTER O) or Item Level (ENTER I): ')15except:16 choice = input('Object Level (ENTER O) or Item Level (ENTER I): ')17try:18 url = raw_input('Enter Google Sheet URL: ')19except:20 url = input('Enter Google Sheet URL: ')21try:22 all_headers = raw_input('All Headers? (Y/N): ')23except:24 all_headers = input('All Headers? (Y/N): ')2526from pynux import utils2728def get_title(data2, x): #gets title29 data2['Title'] = x['properties']['dc:title']3031def get_filepath(data2, x): #gets filepath32 data2['File path'] = x['path']3334def get_type(data2, x, all_headers): #gets type, inputs are dictionary (data2), nuxeo (x), all_headers input35 if x['properties']['ucldc_schema:type'] != None and x['properties']['ucldc_schema:type'] != '':36 data2['Type'] = x['properties']['ucldc_schema:type']37 elif all_headers == 'y' or all_headers == 'Y':38 data2['Type'] = ''3940def get_alt_title(data2, x, all_headers): 41 altnumb = 042 if type(x['properties']['ucldc_schema:alternativetitle']) == list and len(x['properties']['ucldc_schema:alternativetitle']) > 0:43 while altnumb < len(x['properties']['ucldc_schema:alternativetitle']):44 numb = altnumb + 145 name = 'Alternative Title %d' % numb46 data2[name]= x['properties']['ucldc_schema:alternativetitle'][altnumb]47 altnumb += 148 elif all_headers == 'y' or all_headers == 'Y':49 data2['Alternative Title 1'] = ''50def get_identifier(data2, x, all_headers):51 if x['properties']['ucldc_schema:identifier'] != None and x['properties']['ucldc_schema:identifier'] != '':52 data2['Identifier'] = x['properties']['ucldc_schema:identifier']53 elif all_headers == 'y' or all_headers == 'Y':54 data2['Identifier'] = ''55def get_local_identifier(data2, x, all_headers):56 locnumb = 057 if type(x['properties']['ucldc_schema:localidentifier']) == list and len(x['properties']['ucldc_schema:localidentifier']) > 0:58 while locnumb < len(x['properties']['ucldc_schema:localidentifier']):59 numb = locnumb + 160 name = 'Local Identifier %d' % numb61 data2[name]= x['properties']['ucldc_schema:localidentifier'][locnumb]62 locnumb += 163 elif all_headers == 'y' or all_headers == 'Y':64 data2['Local Identifier 1'] = ''65def get_campus_unit(data2, x, all_headers):66 campnumb = 067 if type(x['properties']['ucldc_schema:campusunit']) == list and len(x['properties']['ucldc_schema:campusunit']) > 0:68 while campnumb < len(x['properties']['ucldc_schema:campusunit']):69 numb = campnumb + 170 name = 'Campus/Unit %d' % numb71 data2[name]= x['properties']['ucldc_schema:campusunit'][campnumb]72 campnumb += 173 elif all_headers == 'y' or all_headers == 'Y':74 data2['Campus/Unit 1'] = ''75def get_date(data2, x, all_headers):76 datenumb = 077 if type(x['properties']['ucldc_schema:date']) == list and len(x['properties']['ucldc_schema:date']) > 0:78 while datenumb < len(x['properties']['ucldc_schema:date']):79 numb = datenumb + 180 try:81 name = 'Date %d' % numb82 if x['properties']['ucldc_schema:date'][datenumb]['date'] != None and x['properties']['ucldc_schema:date'][datenumb]['date'] != '':83 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['date']84 elif all_headers == 'y' or all_headers == 'Y':85 data2[name] = ''86 except:87 pass88 try:89 name = 'Date %d Type' % numb90 if x['properties']['ucldc_schema:date'][datenumb]['datetype'] != None and x['properties']['ucldc_schema:date'][datenumb]['datetype'] != '':91 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['datetype']92 elif all_headers == 'y' or all_headers == 'Y':93 data2[name] = ''94 except:95 pass96 try:97 name = 'Date %d Inclusive Start' % numb98 if x['properties']['ucldc_schema:date'][datenumb]['inclusivestart'] != None and x['properties']['ucldc_schema:date'][datenumb]['inclusivestart'] != '':99 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['inclusivestart']100 elif all_headers == 'y' or all_headers == 'Y':101 data2[name] = ''102 except:103 pass104 try:105 name = 'Date %d Inclusive End' % numb106 if x['properties']['ucldc_schema:date'][datenumb]['inclusiveend'] != None and x['properties']['ucldc_schema:date'][datenumb]['inclusiveend'] != '':107 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['inclusiveend']108 elif all_headers == 'y' or all_headers == 'Y':109 data2[name] = ''110 except:111 pass112 try:113 name = 'Date %d Single' % numb114 if x['properties']['ucldc_schema:date'][datenumb]['single'] != None and x['properties']['ucldc_schema:date'][datenumb]['single'] != '':115 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['single']116 elif all_headers == 'y' or all_headers == 'Y':117 data2[name] = ''118 except:119 pass120 datenumb += 1121 elif all_headers == 'y' or all_headers == 'Y':122 data2['Date 1'] = ''123 data2['Date 1 Type'] = ''124 data2['Date 1 Inclusive Start'] = ''125 data2['Date 1 Inclusive End'] = ''126 data2['Date 1 Single'] = ''127def get_publication(data2, x, all_headers):128 pubnumb = 0129 if type(x['properties']['ucldc_schema:publisher']) == list and len(x['properties']['ucldc_schema:publisher']) > 0:130 while pubnumb < len(x['properties']['ucldc_schema:publisher']):131 numb = pubnumb + 1132 name = 'Publication/Origination Info %d' % numb133 data2[name]= x['properties']['ucldc_schema:publisher'][pubnumb]134 pubnumb += 1135 elif all_headers == 'y' or all_headers == 'Y':136 data2['Publication/Origination Info 1'] = ''137138def get_creator(data2, x, all_headers):139 creatnumb = 0140 if type(x['properties']['ucldc_schema:creator']) == list and len(x['properties']['ucldc_schema:creator']) > 0:141 while creatnumb < len(x['properties']['ucldc_schema:creator']):142 numb = creatnumb + 1143 try:144 name = 'Creator %d Name' % numb145 if x['properties']['ucldc_schema:creator'][creatnumb]['name'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['name'] != '':146 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['name']147 elif all_headers == 'y' or all_headers == 'Y':148 data2[name] = ''149 except:150 pass151 try:152 name = 'Creator %d Name Type' % numb153 if x['properties']['ucldc_schema:creator'][creatnumb]['nametype'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['nametype'] != '':154 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['nametype']155 elif all_headers == 'y' or all_headers == 'Y':156 data2[name] = ''157 except:158 pass159 try:160 name = 'Creator %d Role' % numb161 if x['properties']['ucldc_schema:creator'][creatnumb]['role'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['role'] != '':162 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['role']163 elif all_headers == 'y' or all_headers == 'Y':164 data2[name] = ''165 except:166 pass167 try:168 name = 'Creator %d Source' % numb169 if x['properties']['ucldc_schema:creator'][creatnumb]['source'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['source'] != '':170 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['source']171 elif all_headers == 'y' or all_headers == 'Y':172 data2[name] = ''173 except:174 pass175 try:176 name = 'Creator %d Authority ID' % numb177 if x['properties']['ucldc_schema:creator'][creatnumb]['authorityid'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['authorityid'] != '':178 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['authorityid']179 elif all_headers == 'y' or all_headers == 'Y':180 data2[name] = ''181 except:182 pass183 creatnumb += 1184 elif all_headers == 'y' or all_headers == 'Y':185 data2['Creator 1 Name'] = ''186 data2['Creator 1 Name Type'] = ''187 data2['Creator 1 Role'] = ''188 data2['Creator 1 Source'] = ''189 data2['Creator 1 Authority ID'] = ''190191def get_contributor(data2, x, all_headers):192 contnumb = 0193 if type(x['properties']['ucldc_schema:contributor']) == list and len(x['properties']['ucldc_schema:contributor']) > 0:194 while contnumb < len(x['properties']['ucldc_schema:contributor']):195 numb = contnumb + 1196 try:197 name = 'Contributor %d Name' % numb198 if x['properties']['ucldc_schema:contributor'][contnumb]['name'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['name'] != '':199 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['name']200 elif all_headers == 'y' or all_headers == 'Y':201 data2[name] = ''202 except:203 pass204 try:205 name = 'Contributor %d Name Type' % numb206 if x['properties']['ucldc_schema:contributor'][contnumb]['nametype'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['nametype'] != '':207 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['nametype']208 elif all_headers == 'y' or all_headers == 'Y':209 data2[name] = ''210 except:211 pass212 try:213 name = 'Contributor %d Role' % numb214 if x['properties']['ucldc_schema:contributor'][contnumb]['role'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['role'] != '':215 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['role']216 elif all_headers == 'y' or all_headers == 'Y':217 data2[name] = ''218 except:219 pass220 try:221 name = 'Contributor %d Source' % numb222 if x['properties']['ucldc_schema:contributor'][contnumb]['source'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['source'] != '':223 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['source']224 elif all_headers == 'y' or all_headers == 'Y':225 data2[name] = ''226 except:227 pass228 try:229 name = 'Contributor %d Authority ID' % numb230 if x['properties']['ucldc_schema:contributor'][contnumb]['authorityid'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['authorityid'] != '':231 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['authorityid']232 elif all_headers == 'y' or all_headers == 'Y':233 data2[name] = ''234 except:235 pass236 contnumb += 1237 elif all_headers == 'y' or all_headers == 'Y':238 data2['Contributor 1 Name'] = ''239 data2['Contributor 1 Name Type'] = ''240 data2['Contributor 1 Role'] = ''241 data2['Contributor 1 Source'] = ''242 data2['Contributor 1 Authority ID'] = ''243244def get_format(data2, x, all_headers):245 if x['properties']['ucldc_schema:physdesc'] != None and x['properties']['ucldc_schema:physdesc'] != '':246 data2['Format/Physical Description'] = x['properties']['ucldc_schema:physdesc']247 elif all_headers == 'y' or all_headers == 'Y':248 data2['Format/Physical Description'] = ''249def get_description(data2, x, all_headers):250 descnumb = 0251 if type(x['properties']['ucldc_schema:description']) == list and len(x['properties']['ucldc_schema:description']) > 0:252 while descnumb < len(x['properties']['ucldc_schema:description']):253 numb = descnumb + 1254 try:255 name = "Description %d Note" % numb256 if x['properties']['ucldc_schema:description'][descnumb]['item'] != None and x['properties']['ucldc_schema:description'][descnumb]['item'] != '':257 data2[name] = x['properties']['ucldc_schema:description'][descnumb]['item']258 elif all_headers == 'y' or all_headers == 'Y':259 data2[name] = ''260 except:261 pass262 try:263 name = "Description %d Type" % numb264 if x['properties']['ucldc_schema:description'][descnumb]['type'] != None and x['properties']['ucldc_schema:description'][descnumb]['type'] != '':265 data2[name] = x['properties']['ucldc_schema:description'][descnumb]['type']266 elif all_headers == 'y' or all_headers == 'Y':267 data2[name] = ''268 except:269 pass270 descnumb += 1271 elif all_headers == 'y' or all_headers == 'Y':272 data2['Description 1 Note'] = ''273 data2['Description 1 Type'] = ''274def get_extent(data2, x, all_headers):275 if x['properties']['ucldc_schema:extent'] != None and x['properties']['ucldc_schema:extent'] != '':276 data2['Extent'] = x['properties']['ucldc_schema:extent']277 elif all_headers == 'y' or all_headers == 'Y':278 data2['Extent'] = ''279def get_language(data2, x, all_headers):280 langnumb = 0281 if type(x['properties']['ucldc_schema:language']) == list and len(x['properties']['ucldc_schema:language']) > 0:282 while langnumb < len(x['properties']['ucldc_schema:language']):283 numb = langnumb + 1284 try:285 name = "Language %d" % numb286 if x['properties']['ucldc_schema:language'][langnumb]['language'] != None and x['properties']['ucldc_schema:language'][langnumb]['language'] != '':287 data2[name] = x['properties']['ucldc_schema:language'][langnumb]['language']288 elif all_headers == 'y' or all_headers == 'Y':289 data2[name] = ''290 except:291 pass292 try:293 name = "Language %d Code" % numb294 if x['properties']['ucldc_schema:language'][langnumb]['code'] != None and x['properties']['ucldc_schema:language'][langnumb]['code'] != '':295 data2[name] = x['properties']['ucldc_schema:language'][langnumb]['code']296 elif all_headers == 'y' or all_headers == 'Y':297 data2[name] = ''298 except:299 pass300 langnumb += 1301 elif all_headers == 'y' or all_headers == 'Y':302 data2['Language 1'] = ''303 data2['Language 1 Code'] = ''304305def get_temporal_coverage(data2, x, all_headers):306 tempnumb = 0307 if type(x['properties']['ucldc_schema:temporalcoverage']) == list and len(x['properties']['ucldc_schema:temporalcoverage']) > 0:308 while tempnumb < len(x['properties']['ucldc_schema:temporalcoverage']):309 numb = tempnumb + 1310 name = 'Temporal Coverage %d' % numb311 data2[name]= x['properties']['ucldc_schema:temporalcoverage'][tempnumb]312 tempnumb += 1313 elif all_headers == 'y' or all_headers == 'Y':314 data2['Temporal Coverage 1'] = ''315316def get_transcription(data2, x, all_headers):317 if x['properties']['ucldc_schema:transcription'] != None and x['properties']['ucldc_schema:transcription'] != '':318 data2['Transcription'] = x['properties']['ucldc_schema:transcription']319 elif all_headers == 'y' or all_headers == 'Y':320 data2['Transcription'] = ''321322def get_access_restrictions(data2, x, all_headers):323 if x['properties']['ucldc_schema:accessrestrict'] != None and x['properties']['ucldc_schema:accessrestrict'] != '':324 data2['Access Restrictions'] = x['properties']['ucldc_schema:accessrestrict']325 elif all_headers == 'y' or all_headers == 'Y':326 data2['Access Restrictions'] = ''327def get_rights_statement(data2, x, all_headers):328 if x['properties']['ucldc_schema:rightsstatement'] != None and x['properties']['ucldc_schema:rightsstatement'] != '':329 data2['Copyright Statement'] = x['properties']['ucldc_schema:rightsstatement']330 elif all_headers == 'y' or all_headers == 'Y':331 data2['Copyright Statement'] = ''332def get_rights_status(data2, x, all_headers):333 if x['properties']['ucldc_schema:rightsstatus'] != None and x['properties']['ucldc_schema:rightsstatus'] != '':334 data2['Copyright Status'] = x['properties']['ucldc_schema:rightsstatus']335 elif all_headers == 'y' or all_headers == 'Y':336 data2['Copyright Status'] = ''337def get_copyright_holder(data2, x, all_headers):338 rightsnumb = 0339 if type(x['properties']['ucldc_schema:rightsholder']) == list and len(x['properties']['ucldc_schema:rightsholder']) > 0:340 while rightsnumb < len(x['properties']['ucldc_schema:rightsholder']):341 numb = rightsnumb + 1342 try:343 name = 'Copyright Holder %d Name' % numb344 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name'] != '':345 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name']346 elif all_headers == 'y' or all_headers == 'Y':347 data2[name] = ''348 except:349 pass350 try:351 name = 'Copyright Holder %d Name Type' % numb352 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype'] != '':353 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype']354 elif all_headers == 'y' or all_headers == 'Y':355 data2[name] = ''356 except:357 pass358 try:359 name = 'Copyright Holder %d Source' % numb360 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source'] != '':361 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source']362 elif all_headers == 'y' or all_headers == 'Y':363 data2[name] = ''364 except:365 pass366 try:367 name = 'Copyright Holder %d Authority ID' % numb368 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid'] != '':369 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid']370 elif all_headers == 'y' or all_headers == 'Y':371 data2[name] = ''372 except:373 pass374 rightsnumb += 1375 elif all_headers == 'y' or all_headers == 'Y':376 data2['Copyright Holder 1 Name'] = ''377 data2['Copyright Holder 1 Name Type'] = ''378 data2['Copyright Holder 1 Source'] = ''379 data2['Copyright Holder 1 Authority ID'] = ''380381def get_copyright_info(data2, x, all_headers):382 if x['properties']['ucldc_schema:rightscontact'] != None and x['properties']['ucldc_schema:rightscontact'] != '':383 data2['Copyright Contact'] = x['properties']['ucldc_schema:rightscontact']384 elif all_headers == 'y' or all_headers == 'Y':385 data2['Copyright Contact'] = ''386387 if x['properties']['ucldc_schema:rightsnotice'] != None and x['properties']['ucldc_schema:rightsnotice'] != '':388 data2['Copyright Notice'] = x['properties']['ucldc_schema:rightsnotice']389 elif all_headers == 'y' or all_headers == 'Y':390 data2['Copyright Notice'] = ''391392 if x['properties']['ucldc_schema:rightsdeterminationdate'] != None and x['properties']['ucldc_schema:rightsdeterminationdate'] != '':393 data2['Copyright Determination Date'] = x['properties']['ucldc_schema:rightsdeterminationdate']394 elif all_headers == 'y' or all_headers == 'Y':395 data2['Copyright Determination Date'] = ''396397 if x['properties']['ucldc_schema:rightsstartdate'] != None and x['properties']['ucldc_schema:rightsstartdate'] != '':398 data2['Copyright Start Date'] = x['properties']['ucldc_schema:rightsstartdate']399 elif all_headers == 'y' or all_headers == 'Y':400 data2['Copyright Start Date'] = ''401402 if x['properties']['ucldc_schema:rightsenddate'] != None and x['properties']['ucldc_schema:rightsenddate'] != '':403 data2['Copyright End Date'] = x['properties']['ucldc_schema:rightsenddate']404 elif all_headers == 'y' or all_headers == 'Y':405 data2['Copyright End Date'] = ''406407 if x['properties']['ucldc_schema:rightsjurisdiction'] != None and x['properties']['ucldc_schema:rightsjurisdiction'] != '':408 data2['Copyright Jurisdiction'] = x['properties']['ucldc_schema:rightsjurisdiction']409 elif all_headers == 'y' or all_headers == 'Y':410 data2['Copyright Jurisdiction'] = ''411412 if x['properties']['ucldc_schema:rightsnote'] != None and x['properties']['ucldc_schema:rightsnote'] != '':413 data2['Copyright Note'] = x['properties']['ucldc_schema:rightsnote']414 elif all_headers == 'y' or all_headers == 'Y':415 data2['Copyright Note'] = ''416417def get_collection(data2, x, all_headers):418 collnumb = 0419 if type(x['properties']['ucldc_schema:collection']) == list and len(x['properties']['ucldc_schema:collection']) > 0:420 while collnumb < len(x['properties']['ucldc_schema:collection']):421 numb = collnumb + 1422 name = 'Collection %d' % numb423 data2[name]= x['properties']['ucldc_schema:collection'][collnumb]424 collnumb += 1425 elif all_headers == 'y' or all_headers == 'Y':426 data2['Collection 1'] = ''427428def get_related_resource(data2, x, all_headers):429 relnumb = 0430 if type(x['properties']['ucldc_schema:relatedresource']) == list and len(x['properties']['ucldc_schema:relatedresource']) > 0:431 while relnumb < len(x['properties']['ucldc_schema:relatedresource']):432 numb = relnumb + 1433 name = 'Related Resource %d' % numb434 data2[name]= x['properties']['ucldc_schema:relatedresource'][relnumb]435 relnumb += 1436 elif all_headers == 'y' or all_headers == 'Y':437 data2['Related Resource 1'] = ''438439def get_source(data2, x, all_headers):440 if x['properties']['ucldc_schema:source'] != None and x['properties']['ucldc_schema:source'] != '':441 data2['Source'] = x['properties']['ucldc_schema:source']442 elif all_headers == 'y' or all_headers == 'Y':443 data2['Source'] = ''444445def get_subject_name(data2, x, all_headers):446 subnumb = 0447 if type(x['properties']['ucldc_schema:subjectname']) == list and len(x['properties']['ucldc_schema:subjectname']) > 0:448 while subnumb < len(x['properties']['ucldc_schema:subjectname']):449 numb = subnumb + 1450 try:451 name = 'Subject (Name) %d Name' % numb452 if x['properties']['ucldc_schema:subjectname'][subnumb]['name'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['name'] != '':453 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['name']454 elif all_headers == 'y' or all_headers == 'Y':455 data2[name] = ''456 except:457 pass458 try:459 name = 'Subject (Name) %d Name Type' % numb460 if x['properties']['ucldc_schema:subjectname'][subnumb]['name_type'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['name_type'] != '':461 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['name_type']462 elif all_headers == 'y' or all_headers == 'Y':463 data2[name] = ''464 except:465 pass466 try:467 name = 'Subject (Name) %d Role' % numb468 if x['properties']['ucldc_schema:subjectname'][subnumb]['role'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['role'] != '':469 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['role']470 elif all_headers == 'y' or all_headers == 'Y':471 data2[name] = ''472 except:473 pass474 try:475 name = 'Subject (Name) %d Source' % numb476 if x['properties']['ucldc_schema:subjectname'][subnumb]['source'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['source'] != '':477 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['source']478 elif all_headers == 'y' or all_headers == 'Y':479 data2[name] = ''480 except:481 pass482 try:483 name = 'Subject (Name) %d Authority ID' % numb484 if x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid'] != '':485 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid']486 elif all_headers == 'y' or all_headers == 'Y':487 data2[name] = ''488 except:489 pass490 subnumb += 1491 elif all_headers == 'y' or all_headers == 'Y':492 data2['Subject (Name) 1 Name'] = ''493 data2['Subject (Name) 1 Name Type'] = ''494 data2['Subject (Name) 1 Role'] = ''495 data2['Subject (Name) 1 Source'] = ''496 data2['Subject (Name) 1 Authority ID'] = ''497498def get_place(data2, x, all_headers):499 plcnumb = 0500 if type(x['properties']['ucldc_schema:place']) == list and len(x['properties']['ucldc_schema:place']) > 0:501 while plcnumb < len(x['properties']['ucldc_schema:place']):502 numb = plcnumb + 1503 try:504 name = 'Place %d Name' % numb505 if x['properties']['ucldc_schema:place'][plcnumb]['name'] != None and x['properties']['ucldc_schema:place'][plcnumb]['name'] != '':506 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['name']507 elif all_headers == 'y' or all_headers == 'Y':508 data2[name] = ''509 except:510 pass511 try:512 name = 'Place %d Coordinates' % numb513 if x['properties']['ucldc_schema:place'][plcnumb]['coordinates'] != None and x['properties']['ucldc_schema:place'][plcnumb]['coordinates'] != '':514 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['coordinates']515 elif all_headers == 'y' or all_headers == 'Y':516 data2[name] = ''517 except:518 pass519 try:520 name = 'Place %d Source' % numb521 if x['properties']['ucldc_schema:place'][plcnumb]['source'] != None and x['properties']['ucldc_schema:place'][plcnumb]['source'] != '':522 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['source']523 elif all_headers == 'y' or all_headers == 'Y':524 data2[name] = ''525 except:526 pass527 try:528 name = 'Place %d Authority ID' % numb529 if x['properties']['ucldc_schema:place'][plcnumb]['authorityid'] != None and x['properties']['ucldc_schema:place'][plcnumb]['authorityid'] != '':530 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['authorityid']531 elif all_headers == 'y' or all_headers == 'Y':532 data2[name] = ''533 except:534 pass535 plcnumb += 1536 elif all_headers == 'y' or all_headers == 'Y':537 data2['Place 1 Name'] = ''538 data2['Place 1 Coordinates'] = ''539 data2['Place 1 Source'] = ''540 data2['Place 1 Authority ID'] = ''541542def get_subject_topic(data2, x, all_headers):543 topnumb = 0544 if type(x['properties']['ucldc_schema:subjecttopic']) == list and len(x['properties']['ucldc_schema:subjecttopic']) > 0:545 while topnumb < len(x['properties']['ucldc_schema:subjecttopic']):546 numb = topnumb + 1547 try:548 name = 'Subject (Topic) %d Heading' % numb549 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading'] != '':550 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading']551 elif all_headers == 'y' or all_headers == 'Y':552 data2[name] = ''553 except:554 pass555 try:556 name = 'Subject (Topic) %d Heading Type' % numb557 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype'] != '':558 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype']559 elif all_headers == 'y' or all_headers == 'Y':560 data2[name] = ''561 except:562 pass563 try:564 name = 'Subject (Topic) %d Source' % numb565 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['source'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['source'] != '':566 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['source']567 elif all_headers == 'y' or all_headers == 'Y':568 data2[name] = ''569 except:570 pass571 try:572 name = 'Subject (Topic) %d Authority ID' % numb573 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid'] != '':574 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid']575 elif all_headers == 'y' or all_headers == 'Y':576 data2[name] = ''577 except:578 pass579 topnumb += 1580 elif all_headers == 'y' or all_headers == 'Y':581 data2['Subject (Topic) 1 Heading'] = ''582 data2['Subject (Topic) 1 Heading Type'] = ''583 data2['Subject (Topic) 1 Source'] = ''584 data2['Subject (Topic) 1 Authority ID'] = ''585586def get_form_genre(data2, x, all_headers):587 formnumb = 0588 if type(x['properties']['ucldc_schema:formgenre']) == list and len(x['properties']['ucldc_schema:formgenre']) > 0:589 while formnumb < len(x['properties']['ucldc_schema:formgenre']):590 numb = formnumb + 1591 try:592 name = 'Form/Genre %d Heading' % numb593 if x['properties']['ucldc_schema:formgenre'][formnumb]['heading'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['heading'] != '':594 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['heading']595 elif all_headers == 'y' or all_headers == 'Y':596 data2[name] = ''597 except:598 pass599 try:600 name = 'Form/Genre %d Source' % numb601 if x['properties']['ucldc_schema:formgenre'][formnumb]['source'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['source'] != '':602 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['source']603 elif all_headers == 'y' or all_headers == 'Y':604 data2[name] = ''605 except:606 pass607 try:608 name = 'Form/Genre %d Authority ID' % numb609 if x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid'] != '':610 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid']611 elif all_headers == 'y' or all_headers == 'Y':612 data2[name] = ''613 except:614 pass615 formnumb += 1616 elif all_headers == 'y' or all_headers == 'Y':617 data2['Form/Genre 1 Heading'] = ''618 data2['Form/Genre 1 Source'] = ''619 data2['Form/Genre 1 Authority ID'] = ''620621def get_provenance(data2, x, all_headers):622 provnumb = 0623 if type(x['properties']['ucldc_schema:provenance']) == list and len(x['properties']['ucldc_schema:provenance']) > 0:624 while provnumb < len(x['properties']['ucldc_schema:provenance']):625 numb = provnumb + 1626 name = 'Provenance %d' % numb627 data2[name]= x['properties']['ucldc_schema:provenance'][provnumb]628 provnumb += 1629 elif all_headers == 'y' or all_headers == 'Y':630 data2['Provenance 1'] = ''631632def get_physical_location(data2, x, all_headers):633 if x['properties']['ucldc_schema:physlocation'] != None and x['properties']['ucldc_schema:physlocation'] != '':634 data2['Physical Location'] = x['properties']['ucldc_schema:physlocation']635 elif all_headers == 'y' or all_headers == 'Y':636 data2['Physical Location'] = ''637638def object_level(filepath):639 nx = utils.Nuxeo()640 data = []641 for n in nx.children(filepath):642 data2 = {}643 644 get_title(data2, n)645 get_filepath(data2, n)646 get_type(data2, n, all_headers)647 get_alt_title(data2, n, all_headers)648 get_identifier(data2, n, all_headers)649 get_local_identifier(data2, n, all_headers)650 get_campus_unit(data2, n, all_headers)651 get_date(data2, n, all_headers)652 get_publication(data2, n, all_headers)653 get_creator(data2, n, all_headers)654 get_contributor(data2, n, all_headers)655 get_format(data2, n, all_headers)656 get_description(data2, n, all_headers)657 get_extent(data2, n, all_headers)658 get_language(data2, n, all_headers)659 get_temporal_coverage(data2, n, all_headers)660 get_transcription(data2, n, all_headers)661 get_access_restrictions(data2, n, all_headers)662 get_rights_statement(data2, n, all_headers)663 get_rights_status(data2, n, all_headers)664 get_copyright_holder(data2, n, all_headers)665 get_copyright_info(data2, n, all_headers)666 get_collection(data2, n, all_headers)667 get_related_resource(data2, n, all_headers)668 get_source(data2, n, all_headers)669 get_subject_name(data2, n, all_headers)670 get_place(data2, n, all_headers)671 get_subject_topic(data2, n, all_headers)672 get_form_genre(data2, n, all_headers)673 get_provenance(data2, n, all_headers)674 get_physical_location(data2, n, all_headers)675676 data.append(data2)677678 fieldnames = ['File path', 'Title', 'Type'] #ensures that File path, Title and Type are the first three rows679 for data2 in data:680 for key, value in data2.items():681 if key not in fieldnames:682 fieldnames.append(key)683684 return {'fieldnames':fieldnames, 'data':data, 'filename':"nuxeo_object_%s.tsv"%nx.get_metadata(path=filepath)['properties']['dc:title']}685686def item_level(filepath):687 nx = utils.Nuxeo()688 data = []689 for n in nx.children(filepath):690 for x in nx.children(n['path']):691 data2 = {}692 get_title(data2, x)693 get_filepath(data2, x)694 get_type(data2, x, all_headers)695 get_alt_title(data2, x, all_headers)696 get_identifier(data2, x, all_headers)697 get_local_identifier(data2, x, all_headers)698 get_campus_unit(data2, x, all_headers)699 get_date(data2, x, all_headers)700 get_publication(data2, x, all_headers)701 get_creator(data2, x, all_headers)702 get_contributor(data2, x, all_headers)703 get_format(data2, x, all_headers)704 get_description(data2, x, all_headers)705 get_extent(data2, x, all_headers)706 get_language(data2, x, all_headers)707 get_temporal_coverage(data2, x, all_headers)708 get_transcription(data2, x, all_headers)709 get_access_restrictions(data2, x, all_headers)710 get_rights_statement(data2, x, all_headers)711 get_rights_status(data2, x, all_headers)712 get_copyright_holder(data2, x, all_headers)713 get_copyright_info(data2, x, all_headers)714 get_collection(data2, x, all_headers)715 get_related_resource(data2, x, all_headers)716 get_source(data2, x, all_headers)717 get_subject_name(data2, x, all_headers)718 get_place(data2, x, all_headers)719 get_subject_topic(data2, x, all_headers)720 get_form_genre(data2, x, all_headers)721 get_provenance(data2, x, all_headers)722 get_physical_location(data2, x, all_headers)723 data.append(data2)724725 fieldnames = ['File path', 'Title', 'Type'] #ensures that File path, Title and Type are the first three rows726 for data2 in data:727 for key, value in data2.items():728 if key not in fieldnames:729 fieldnames.append(key)730731 return {'fieldnames':fieldnames, 'data':data, 'filename':"nuxeo_item_%s.tsv"%nx.get_metadata(path=filepath)['properties']['dc:title']}732 #returns dictionary with fieldnames, data and filename; This is used for google functions and writing to tsv if google function not choosed733734def google_object(filepath, url):735 import gspread736 from oauth2client.service_account import ServiceAccountCredentials737 obj = object_level(filepath)738 nx = utils.Nuxeo()739 scope = ['https://spreadsheets.google.com/feeds',740 'https://www.googleapis.com/auth/drive']741 creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)742 client = gspread.authorize(creds)743 with open("temp.csv", "wb") as csvfile:744 writer = csv.DictWriter(csvfile, fieldnames=obj['fieldnames'])745 writer.writeheader()746 for row in obj['data']:747 writer.writerow(row)748 with open("temp.csv", encoding="utf8") as f:749 s = f.read() + '\n'750 sheet_id = client.open_by_url(url).id751 client.import_csv(sheet_id, s)752 client.open_by_key(sheet_id).sheet1.update_title("nuxeo_object_%s"%nx.get_metadata(path=filepath)['properties']['dc:title'])753 os.remove("temp.csv")754755def google_item(filepath, url):756 import gspread757 from oauth2client.service_account import ServiceAccountCredentials758 item = item_level(filepath)759 nx = utils.Nuxeo()760 scope = ['https://spreadsheets.google.com/feeds',761 'https://www.googleapis.com/auth/drive']762 creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)763 client = gspread.authorize(creds)764 with open("temp.csv", "wb") as csvfile: #creates temporary csv file765 writer = csv.DictWriter(csvfile, fieldnames=item['fieldnames'])766 writer.writeheader()767 for row in item['data']:768 writer.writerow(row)769 with open("temp.csv", encoding="utf8") as f: #opens and reads temporary csv file770 s = f.read() + '\n'771 sheet_id = client.open_by_url(url).id 772 client.import_csv(sheet_id, s)#writes csv file to google sheet773 client.open_by_key(sheet_id).sheet1.update_title("nuxeo_item_%s"%nx.get_metadata(path=filepath)['properties']['dc:title'])774 os.remove("temp.csv") #removes temporary csv775776if 'O' in choice or 'o' in choice:777 if 'http' in url:778 try:779 google_object(filepath, url)780 except:781 print("\n*********\nWriting to Google document did not work. Make sure that Google document has been shared with API key email address")782 else:783 obj = object_level(filepath)784 with open(obj['filename'], "wb") as csvfile:785 writer = csv.DictWriter(csvfile, fieldnames=obj['fieldnames'], delimiter="\t")786 writer.writeheader()787 for row in obj['data']:788 writer.writerow(row)789if 'I' in choice or 'i' in choice:790 if 'http' in url:791 try:792 google_item(filepath, url)793 except:794 print("\n*********\nWriting to Google document did not work. Make sure that Google document has been shared with API key email address")795 else:796 item = item_level(filepath)797 with open(item['filename'], "wb") as csvfile:798 writer = csv.DictWriter(csvfile, fieldnames=item['fieldnames'], delimiter="\t")799 writer.writeheader()800 for row in item['data']: ...

Full Screen

Full Screen

nuxeo_update_spreadsheet.py

Source:nuxeo_update_spreadsheet.py Github

copy

Full Screen

1#Written by Niqui O'Neill2#This script requires unicodecsv to be installed3#This script allows the users to download metadata from nuxeo and place it either in a google spreadsheet or tsv file4#it also allows for metadata to be downloaded from the collection or item level5#it also asks if all headers should be downloaded or if the empty items should not be downloaded6#Nuxeo has to be installed for this script to work7import unicodecsv as csv8import os9try:10 filepath = raw_input('Enter Nuxeo File Path: ')11except:12 filepath = input('Enter Nuxeo File Path: ')13try:14 choice = raw_input('Object Level (ENTER O) or Item Level (ENTER I): ')15except:16 choice = input('Object Level (ENTER O) or Item Level (ENTER I): ')17try:18 url = raw_input('Enter Google Sheet URL: ')19except:20 url = input('Enter Google Sheet URL: ')21try:22 all_headers = raw_input('All Headers? (Y/N): ')23except:24 all_headers = input('All Headers? (Y/N): ')2526from pynux import utils2728def get_title(data2, x): #gets title29 data2['Title'] = x['properties']['dc:title']3031def get_filepath(data2, x): #gets filepath32 data2['File path'] = x['path']3334def get_type(data2, x, all_headers): #gets type, inputs are dictionary (data2), nuxeo (x), all_headers input35 if x['properties']['ucldc_schema:type'] != None and x['properties']['ucldc_schema:type'] != '':36 data2['Type'] = x['properties']['ucldc_schema:type']37 elif all_headers == 'y' or all_headers == 'Y':38 data2['Type'] = ''3940def get_alt_title(data2, x, all_headers): 41 altnumb = 042 if type(x['properties']['ucldc_schema:alternativetitle']) == list and len(x['properties']['ucldc_schema:alternativetitle']) > 0:43 while altnumb < len(x['properties']['ucldc_schema:alternativetitle']):44 numb = altnumb + 145 name = 'Alternative Title %d' % numb46 data2[name]= x['properties']['ucldc_schema:alternativetitle'][altnumb]47 altnumb += 148 elif all_headers == 'y' or all_headers == 'Y':49 data2['Alternative Title 1'] = ''50def get_identifier(data2, x, all_headers):51 if x['properties']['ucldc_schema:identifier'] != None and x['properties']['ucldc_schema:identifier'] != '':52 data2['Identifier'] = x['properties']['ucldc_schema:identifier']53 elif all_headers == 'y' or all_headers == 'Y':54 data2['Identifier'] = ''55def get_local_identifier(data2, x, all_headers):56 locnumb = 057 if type(x['properties']['ucldc_schema:localidentifier']) == list and len(x['properties']['ucldc_schema:localidentifier']) > 0:58 while locnumb < len(x['properties']['ucldc_schema:localidentifier']):59 numb = locnumb + 160 name = 'Local Identifier %d' % numb61 data2[name]= x['properties']['ucldc_schema:localidentifier'][locnumb]62 locnumb += 163 elif all_headers == 'y' or all_headers == 'Y':64 data2['Local Identifier 1'] = ''65def get_campus_unit(data2, x, all_headers):66 campnumb = 067 if type(x['properties']['ucldc_schema:campusunit']) == list and len(x['properties']['ucldc_schema:campusunit']) > 0:68 while campnumb < len(x['properties']['ucldc_schema:campusunit']):69 numb = campnumb + 170 name = 'Campus/Unit %d' % numb71 data2[name]= x['properties']['ucldc_schema:campusunit'][campnumb]72 campnumb += 173 elif all_headers == 'y' or all_headers == 'Y':74 data2['Campus/Unit 1'] = ''75def get_date(data2, x, all_headers):76 datenumb = 077 if type(x['properties']['ucldc_schema:date']) == list and len(x['properties']['ucldc_schema:date']) > 0:78 while datenumb < len(x['properties']['ucldc_schema:date']):79 numb = datenumb + 180 try:81 name = 'Date %d' % numb82 if x['properties']['ucldc_schema:date'][datenumb]['date'] != None and x['properties']['ucldc_schema:date'][datenumb]['date'] != '':83 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['date']84 elif all_headers == 'y' or all_headers == 'Y':85 data2[name] = ''86 except:87 pass88 try:89 name = 'Date %d Type' % numb90 if x['properties']['ucldc_schema:date'][datenumb]['datetype'] != None and x['properties']['ucldc_schema:date'][datenumb]['datetype'] != '':91 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['datetype']92 elif all_headers == 'y' or all_headers == 'Y':93 data2[name] = ''94 except:95 pass96 try:97 name = 'Date %d Inclusive Start' % numb98 if x['properties']['ucldc_schema:date'][datenumb]['inclusivestart'] != None and x['properties']['ucldc_schema:date'][datenumb]['inclusivestart'] != '':99 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['inclusivestart']100 elif all_headers == 'y' or all_headers == 'Y':101 data2[name] = ''102 except:103 pass104 try:105 name = 'Date %d Inclusive End' % numb106 if x['properties']['ucldc_schema:date'][datenumb]['inclusiveend'] != None and x['properties']['ucldc_schema:date'][datenumb]['inclusiveend'] != '':107 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['inclusiveend']108 elif all_headers == 'y' or all_headers == 'Y':109 data2[name] = ''110 except:111 pass112 try:113 name = 'Date %d Single' % numb114 if x['properties']['ucldc_schema:date'][datenumb]['single'] != None and x['properties']['ucldc_schema:date'][datenumb]['single'] != '':115 data2[name] = x['properties']['ucldc_schema:date'][datenumb]['single']116 elif all_headers == 'y' or all_headers == 'Y':117 data2[name] = ''118 except:119 pass120 datenumb += 1121 elif all_headers == 'y' or all_headers == 'Y':122 data2['Date 1'] = ''123 data2['Date 1 Type'] = ''124 data2['Date 1 Inclusive Start'] = ''125 data2['Date 1 Inclusive End'] = ''126 data2['Date 1 Single'] = ''127def get_publication(data2, x, all_headers):128 pubnumb = 0129 if type(x['properties']['ucldc_schema:publisher']) == list and len(x['properties']['ucldc_schema:publisher']) > 0:130 while pubnumb < len(x['properties']['ucldc_schema:publisher']):131 numb = pubnumb + 1132 name = 'Publication/Origination Info %d' % numb133 data2[name]= x['properties']['ucldc_schema:publisher'][pubnumb]134 pubnumb += 1135 elif all_headers == 'y' or all_headers == 'Y':136 data2['Publication/Origination Info 1'] = ''137138def get_creator(data2, x, all_headers):139 creatnumb = 0140 if type(x['properties']['ucldc_schema:creator']) == list and len(x['properties']['ucldc_schema:creator']) > 0:141 while creatnumb < len(x['properties']['ucldc_schema:creator']):142 numb = creatnumb + 1143 try:144 name = 'Creator %d Name' % numb145 if x['properties']['ucldc_schema:creator'][creatnumb]['name'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['name'] != '':146 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['name']147 elif all_headers == 'y' or all_headers == 'Y':148 data2[name] = ''149 except:150 pass151 try:152 name = 'Creator %d Name Type' % numb153 if x['properties']['ucldc_schema:creator'][creatnumb]['nametype'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['nametype'] != '':154 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['nametype']155 elif all_headers == 'y' or all_headers == 'Y':156 data2[name] = ''157 except:158 pass159 try:160 name = 'Creator %d Role' % numb161 if x['properties']['ucldc_schema:creator'][creatnumb]['role'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['role'] != '':162 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['role']163 elif all_headers == 'y' or all_headers == 'Y':164 data2[name] = ''165 except:166 pass167 try:168 name = 'Creator %d Source' % numb169 if x['properties']['ucldc_schema:creator'][creatnumb]['source'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['source'] != '':170 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['source']171 elif all_headers == 'y' or all_headers == 'Y':172 data2[name] = ''173 except:174 pass175 try:176 name = 'Creator %d Authority ID' % numb177 if x['properties']['ucldc_schema:creator'][creatnumb]['authorityid'] != None and x['properties']['ucldc_schema:creator'][creatnumb]['authorityid'] != '':178 data2[name] = x['properties']['ucldc_schema:creator'][creatnumb]['authorityid']179 elif all_headers == 'y' or all_headers == 'Y':180 data2[name] = ''181 except:182 pass183 creatnumb += 1184 elif all_headers == 'y' or all_headers == 'Y':185 data2['Creator 1 Name'] = ''186 data2['Creator 1 Name Type'] = ''187 data2['Creator 1 Role'] = ''188 data2['Creator 1 Source'] = ''189 data2['Creator 1 Authority ID'] = ''190191def get_contributor(data2, x, all_headers):192 contnumb = 0193 if type(x['properties']['ucldc_schema:contributor']) == list and len(x['properties']['ucldc_schema:contributor']) > 0:194 while contnumb < len(x['properties']['ucldc_schema:contributor']):195 numb = contnumb + 1196 try:197 name = 'Contributor %d Name' % numb198 if x['properties']['ucldc_schema:contributor'][contnumb]['name'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['name'] != '':199 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['name']200 elif all_headers == 'y' or all_headers == 'Y':201 data2[name] = ''202 except:203 pass204 try:205 name = 'Contributor %d Name Type' % numb206 if x['properties']['ucldc_schema:contributor'][contnumb]['nametype'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['nametype'] != '':207 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['nametype']208 elif all_headers == 'y' or all_headers == 'Y':209 data2[name] = ''210 except:211 pass212 try:213 name = 'Contributor %d Role' % numb214 if x['properties']['ucldc_schema:contributor'][contnumb]['role'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['role'] != '':215 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['role']216 elif all_headers == 'y' or all_headers == 'Y':217 data2[name] = ''218 except:219 pass220 try:221 name = 'Contributor %d Source' % numb222 if x['properties']['ucldc_schema:contributor'][contnumb]['source'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['source'] != '':223 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['source']224 elif all_headers == 'y' or all_headers == 'Y':225 data2[name] = ''226 except:227 pass228 try:229 name = 'Contributor %d Authority ID' % numb230 if x['properties']['ucldc_schema:contributor'][contnumb]['authorityid'] != None and x['properties']['ucldc_schema:contributor'][contnumb]['authorityid'] != '':231 data2[name] = x['properties']['ucldc_schema:contributor'][contnumb]['authorityid']232 elif all_headers == 'y' or all_headers == 'Y':233 data2[name] = ''234 except:235 pass236 contnumb += 1237 elif all_headers == 'y' or all_headers == 'Y':238 data2['Contributor 1 Name'] = ''239 data2['Contributor 1 Name Type'] = ''240 data2['Contributor 1 Role'] = ''241 data2['Contributor 1 Source'] = ''242 data2['Contributor 1 Authority ID'] = ''243244def get_format(data2, x, all_headers):245 if x['properties']['ucldc_schema:physdesc'] != None and x['properties']['ucldc_schema:physdesc'] != '':246 data2['Format/Physical Description'] = x['properties']['ucldc_schema:physdesc']247 elif all_headers == 'y' or all_headers == 'Y':248 data2['Format/Physical Description'] = ''249def get_description(data2, x, all_headers):250 descnumb = 0251 if type(x['properties']['ucldc_schema:description']) == list and len(x['properties']['ucldc_schema:description']) > 0:252 while descnumb < len(x['properties']['ucldc_schema:description']):253 numb = descnumb + 1254 try:255 name = "Description %d Note" % numb256 if x['properties']['ucldc_schema:description'][descnumb]['item'] != None and x['properties']['ucldc_schema:description'][descnumb]['item'] != '':257 data2[name] = x['properties']['ucldc_schema:description'][descnumb]['item']258 elif all_headers == 'y' or all_headers == 'Y':259 data2[name] = ''260 except:261 pass262 try:263 name = "Description %d Type" % numb264 if x['properties']['ucldc_schema:description'][descnumb]['type'] != None and x['properties']['ucldc_schema:description'][descnumb]['type'] != '':265 data2[name] = x['properties']['ucldc_schema:description'][descnumb]['type']266 elif all_headers == 'y' or all_headers == 'Y':267 data2[name] = ''268 except:269 pass270 descnumb += 1271 elif all_headers == 'y' or all_headers == 'Y':272 data2['Description 1 Note'] = ''273 data2['Description 1 Type'] = ''274def get_extent(data2, x, all_headers):275 if x['properties']['ucldc_schema:extent'] != None and x['properties']['ucldc_schema:extent'] != '':276 data2['Extent'] = x['properties']['ucldc_schema:extent']277 elif all_headers == 'y' or all_headers == 'Y':278 data2['Extent'] = ''279def get_language(data2, x, all_headers):280 langnumb = 0281 if type(x['properties']['ucldc_schema:language']) == list and len(x['properties']['ucldc_schema:language']) > 0:282 while langnumb < len(x['properties']['ucldc_schema:language']):283 numb = langnumb + 1284 try:285 name = "Language %d" % numb286 if x['properties']['ucldc_schema:language'][langnumb]['language'] != None and x['properties']['ucldc_schema:language'][langnumb]['language'] != '':287 data2[name] = x['properties']['ucldc_schema:language'][langnumb]['language']288 elif all_headers == 'y' or all_headers == 'Y':289 data2[name] = ''290 except:291 pass292 try:293 name = "Language %d Code" % numb294 if x['properties']['ucldc_schema:language'][langnumb]['code'] != None and x['properties']['ucldc_schema:language'][langnumb]['code'] != '':295 data2[name] = x['properties']['ucldc_schema:language'][langnumb]['code']296 elif all_headers == 'y' or all_headers == 'Y':297 data2[name] = ''298 except:299 pass300 langnumb += 1301 elif all_headers == 'y' or all_headers == 'Y':302 data2['Language 1'] = ''303 data2['Language 1 Code'] = ''304305def get_temporal_coverage(data2, x, all_headers):306 tempnumb = 0307 if type(x['properties']['ucldc_schema:temporalcoverage']) == list and len(x['properties']['ucldc_schema:temporalcoverage']) > 0:308 while tempnumb < len(x['properties']['ucldc_schema:temporalcoverage']):309 numb = tempnumb + 1310 name = 'Temporal Coverage %d' % numb311 data2[name]= x['properties']['ucldc_schema:temporalcoverage'][tempnumb]312 tempnumb += 1313 elif all_headers == 'y' or all_headers == 'Y':314 data2['Temporal Coverage 1'] = ''315316def get_transcription(data2, x, all_headers):317 if x['properties']['ucldc_schema:transcription'] != None and x['properties']['ucldc_schema:transcription'] != '':318 data2['Transcription'] = x['properties']['ucldc_schema:transcription']319 elif all_headers == 'y' or all_headers == 'Y':320 data2['Transcription'] = ''321322def get_access_restrictions(data2, x, all_headers):323 if x['properties']['ucldc_schema:accessrestrict'] != None and x['properties']['ucldc_schema:accessrestrict'] != '':324 data2['Access Restrictions'] = x['properties']['ucldc_schema:accessrestrict']325 elif all_headers == 'y' or all_headers == 'Y':326 data2['Access Restrictions'] = ''327def get_rights_statement(data2, x, all_headers):328 if x['properties']['ucldc_schema:rightsstatement'] != None and x['properties']['ucldc_schema:rightsstatement'] != '':329 data2['Copyright Statement'] = x['properties']['ucldc_schema:rightsstatement']330 elif all_headers == 'y' or all_headers == 'Y':331 data2['Copyright Statement'] = ''332def get_rights_status(data2, x, all_headers):333 if x['properties']['ucldc_schema:rightsstatus'] != None and x['properties']['ucldc_schema:rightsstatus'] != '':334 data2['Copyright Status'] = x['properties']['ucldc_schema:rightsstatus']335 elif all_headers == 'y' or all_headers == 'Y':336 data2['Copyright Status'] = ''337def get_copyright_holder(data2, x, all_headers):338 rightsnumb = 0339 if type(x['properties']['ucldc_schema:rightsholder']) == list and len(x['properties']['ucldc_schema:rightsholder']) > 0:340 while rightsnumb < len(x['properties']['ucldc_schema:rightsholder']):341 numb = rightsnumb + 1342 try:343 name = 'Copyright Holder %d Name' % numb344 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name'] != '':345 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['name']346 elif all_headers == 'y' or all_headers == 'Y':347 data2[name] = ''348 except:349 pass350 try:351 name = 'Copyright Holder %d Name Type' % numb352 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype'] != '':353 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['nametype']354 elif all_headers == 'y' or all_headers == 'Y':355 data2[name] = ''356 except:357 pass358 try:359 name = 'Copyright Holder %d Source' % numb360 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source'] != '':361 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['source']362 elif all_headers == 'y' or all_headers == 'Y':363 data2[name] = ''364 except:365 pass366 try:367 name = 'Copyright Holder %d Authority ID' % numb368 if x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid'] != None and x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid'] != '':369 data2[name] = x['properties']['ucldc_schema:rightsholder'][rightsnumb]['authorityid']370 elif all_headers == 'y' or all_headers == 'Y':371 data2[name] = ''372 except:373 pass374 rightsnumb += 1375 elif all_headers == 'y' or all_headers == 'Y':376 data2['Copyright Holder 1 Name'] = ''377 data2['Copyright Holder 1 Name Type'] = ''378 data2['Copyright Holder 1 Source'] = ''379 data2['Copyright Holder 1 Authority ID'] = ''380381def get_copyright_info(data2, x, all_headers):382 if x['properties']['ucldc_schema:rightscontact'] != None and x['properties']['ucldc_schema:rightscontact'] != '':383 data2['Copyright Contact'] = x['properties']['ucldc_schema:rightscontact']384 elif all_headers == 'y' or all_headers == 'Y':385 data2['Copyright Contact'] = ''386387 if x['properties']['ucldc_schema:rightsnotice'] != None and x['properties']['ucldc_schema:rightsnotice'] != '':388 data2['Copyright Notice'] = x['properties']['ucldc_schema:rightsnotice']389 elif all_headers == 'y' or all_headers == 'Y':390 data2['Copyright Notice'] = ''391392 if x['properties']['ucldc_schema:rightsdeterminationdate'] != None and x['properties']['ucldc_schema:rightsdeterminationdate'] != '':393 data2['Copyright Determination Date'] = x['properties']['ucldc_schema:rightsdeterminationdate']394 elif all_headers == 'y' or all_headers == 'Y':395 data2['Copyright Determination Date'] = ''396397 if x['properties']['ucldc_schema:rightsstartdate'] != None and x['properties']['ucldc_schema:rightsstartdate'] != '':398 data2['Copyright Start Date'] = x['properties']['ucldc_schema:rightsstartdate']399 elif all_headers == 'y' or all_headers == 'Y':400 data2['Copyright Start Date'] = ''401402 if x['properties']['ucldc_schema:rightsenddate'] != None and x['properties']['ucldc_schema:rightsenddate'] != '':403 data2['Copyright End Date'] = x['properties']['ucldc_schema:rightsenddate']404 elif all_headers == 'y' or all_headers == 'Y':405 data2['Copyright End Date'] = ''406407 if x['properties']['ucldc_schema:rightsjurisdiction'] != None and x['properties']['ucldc_schema:rightsjurisdiction'] != '':408 data2['Copyright Jurisdiction'] = x['properties']['ucldc_schema:rightsjurisdiction']409 elif all_headers == 'y' or all_headers == 'Y':410 data2['Copyright Jurisdiction'] = ''411412 if x['properties']['ucldc_schema:rightsnote'] != None and x['properties']['ucldc_schema:rightsnote'] != '':413 data2['Copyright Note'] = x['properties']['ucldc_schema:rightsnote']414 elif all_headers == 'y' or all_headers == 'Y':415 data2['Copyright Note'] = ''416417def get_collection(data2, x, all_headers):418 collnumb = 0419 if type(x['properties']['ucldc_schema:collection']) == list and len(x['properties']['ucldc_schema:collection']) > 0:420 while collnumb < len(x['properties']['ucldc_schema:collection']):421 numb = collnumb + 1422 name = 'Collection %d' % numb423 data2[name]= x['properties']['ucldc_schema:collection'][collnumb]424 collnumb += 1425 elif all_headers == 'y' or all_headers == 'Y':426 data2['Collection 1'] = ''427428def get_related_resource(data2, x, all_headers):429 relnumb = 0430 if type(x['properties']['ucldc_schema:relatedresource']) == list and len(x['properties']['ucldc_schema:relatedresource']) > 0:431 while relnumb < len(x['properties']['ucldc_schema:relatedresource']):432 numb = relnumb + 1433 name = 'Related Resource %d' % numb434 data2[name]= x['properties']['ucldc_schema:relatedresource'][relnumb]435 relnumb += 1436 elif all_headers == 'y' or all_headers == 'Y':437 data2['Related Resource 1'] = ''438439def get_source(data2, x, all_headers):440 if x['properties']['ucldc_schema:source'] != None and x['properties']['ucldc_schema:source'] != '':441 data2['Source'] = x['properties']['ucldc_schema:source']442 elif all_headers == 'y' or all_headers == 'Y':443 data2['Source'] = ''444445def get_subject_name(data2, x, all_headers):446 subnumb = 0447 if type(x['properties']['ucldc_schema:subjectname']) == list and len(x['properties']['ucldc_schema:subjectname']) > 0:448 while subnumb < len(x['properties']['ucldc_schema:subjectname']):449 numb = subnumb + 1450 try:451 name = 'Subject (Name) %d Name' % numb452 if x['properties']['ucldc_schema:subjectname'][subnumb]['name'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['name'] != '':453 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['name']454 elif all_headers == 'y' or all_headers == 'Y':455 data2[name] = ''456 except:457 pass458 try:459 name = 'Subject (Name) %d Name Type' % numb460 if x['properties']['ucldc_schema:subjectname'][subnumb]['name_type'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['name_type'] != '':461 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['name_type']462 elif all_headers == 'y' or all_headers == 'Y':463 data2[name] = ''464 except:465 pass466 try:467 name = 'Subject (Name) %d Role' % numb468 if x['properties']['ucldc_schema:subjectname'][subnumb]['role'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['role'] != '':469 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['role']470 elif all_headers == 'y' or all_headers == 'Y':471 data2[name] = ''472 except:473 pass474 try:475 name = 'Subject (Name) %d Source' % numb476 if x['properties']['ucldc_schema:subjectname'][subnumb]['source'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['source'] != '':477 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['source']478 elif all_headers == 'y' or all_headers == 'Y':479 data2[name] = ''480 except:481 pass482 try:483 name = 'Subject (Name) %d Authority ID' % numb484 if x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid'] != None and x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid'] != '':485 data2[name] = x['properties']['ucldc_schema:subjectname'][subnumb]['authorityid']486 elif all_headers == 'y' or all_headers == 'Y':487 data2[name] = ''488 except:489 pass490 subnumb += 1491 elif all_headers == 'y' or all_headers == 'Y':492 data2['Subject (Name) 1 Name'] = ''493 data2['Subject (Name) 1 Name Type'] = ''494 data2['Subject (Name) 1 Role'] = ''495 data2['Subject (Name) 1 Source'] = ''496 data2['Subject (Name) 1 Authority ID'] = ''497498def get_place(data2, x, all_headers):499 plcnumb = 0500 if type(x['properties']['ucldc_schema:place']) == list and len(x['properties']['ucldc_schema:place']) > 0:501 while plcnumb < len(x['properties']['ucldc_schema:place']):502 numb = plcnumb + 1503 try:504 name = 'Place %d Name' % numb505 if x['properties']['ucldc_schema:place'][plcnumb]['name'] != None and x['properties']['ucldc_schema:place'][plcnumb]['name'] != '':506 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['name']507 elif all_headers == 'y' or all_headers == 'Y':508 data2[name] = ''509 except:510 pass511 try:512 name = 'Place %d Coordinates' % numb513 if x['properties']['ucldc_schema:place'][plcnumb]['coordinates'] != None and x['properties']['ucldc_schema:place'][plcnumb]['coordinates'] != '':514 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['coordinates']515 elif all_headers == 'y' or all_headers == 'Y':516 data2[name] = ''517 except:518 pass519 try:520 name = 'Place %d Source' % numb521 if x['properties']['ucldc_schema:place'][plcnumb]['source'] != None and x['properties']['ucldc_schema:place'][plcnumb]['source'] != '':522 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['source']523 elif all_headers == 'y' or all_headers == 'Y':524 data2[name] = ''525 except:526 pass527 try:528 name = 'Place %d Authority ID' % numb529 if x['properties']['ucldc_schema:place'][plcnumb]['authorityid'] != None and x['properties']['ucldc_schema:place'][plcnumb]['authorityid'] != '':530 data2[name] = x['properties']['ucldc_schema:place'][plcnumb]['authorityid']531 elif all_headers == 'y' or all_headers == 'Y':532 data2[name] = ''533 except:534 pass535 plcnumb += 1536 elif all_headers == 'y' or all_headers == 'Y':537 data2['Place 1 Name'] = ''538 data2['Place 1 Coordinates'] = ''539 data2['Place 1 Source'] = ''540 data2['Place 1 Authority ID'] = ''541542def get_subject_topic(data2, x, all_headers):543 topnumb = 0544 if type(x['properties']['ucldc_schema:subjecttopic']) == list and len(x['properties']['ucldc_schema:subjecttopic']) > 0:545 while topnumb < len(x['properties']['ucldc_schema:subjecttopic']):546 numb = topnumb + 1547 try:548 name = 'Subject (Topic) %d Heading' % numb549 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading'] != '':550 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['heading']551 elif all_headers == 'y' or all_headers == 'Y':552 data2[name] = ''553 except:554 pass555 try:556 name = 'Subject (Topic) %d Heading Type' % numb557 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype'] != '':558 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['headingtype']559 elif all_headers == 'y' or all_headers == 'Y':560 data2[name] = ''561 except:562 pass563 try:564 name = 'Subject (Topic) %d Source' % numb565 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['source'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['source'] != '':566 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['source']567 elif all_headers == 'y' or all_headers == 'Y':568 data2[name] = ''569 except:570 pass571 try:572 name = 'Subject (Topic) %d Authority ID' % numb573 if x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid'] != None and x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid'] != '':574 data2[name] = x['properties']['ucldc_schema:subjecttopic'][topnumb]['authorityid']575 elif all_headers == 'y' or all_headers == 'Y':576 data2[name] = ''577 except:578 pass579 topnumb += 1580 elif all_headers == 'y' or all_headers == 'Y':581 data2['Subject (Topic) 1 Heading'] = ''582 data2['Subject (Topic) 1 Heading Type'] = ''583 data2['Subject (Topic) 1 Source'] = ''584 data2['Subject (Topic) 1 Authority ID'] = ''585586def get_form_genre(data2, x, all_headers):587 formnumb = 0588 if type(x['properties']['ucldc_schema:formgenre']) == list and len(x['properties']['ucldc_schema:formgenre']) > 0:589 while formnumb < len(x['properties']['ucldc_schema:formgenre']):590 numb = formnumb + 1591 try:592 name = 'Form/Genre %d Heading' % numb593 if x['properties']['ucldc_schema:formgenre'][formnumb]['heading'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['heading'] != '':594 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['heading']595 elif all_headers == 'y' or all_headers == 'Y':596 data2[name] = ''597 except:598 pass599 try:600 name = 'Form/Genre %d Source' % numb601 if x['properties']['ucldc_schema:formgenre'][formnumb]['source'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['source'] != '':602 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['source']603 elif all_headers == 'y' or all_headers == 'Y':604 data2[name] = ''605 except:606 pass607 try:608 name = 'Form/Genre %d Authority ID' % numb609 if x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid'] != None and x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid'] != '':610 data2[name] = x['properties']['ucldc_schema:formgenre'][formnumb]['authorityid']611 elif all_headers == 'y' or all_headers == 'Y':612 data2[name] = ''613 except:614 pass615 formnumb += 1616 elif all_headers == 'y' or all_headers == 'Y':617 data2['Form/Genre 1 Heading'] = ''618 data2['Form/Genre 1 Source'] = ''619 data2['Form/Genre 1 Authority ID'] = ''620621def get_provenance(data2, x, all_headers):622 provnumb = 0623 if type(x['properties']['ucldc_schema:provenance']) == list and len(x['properties']['ucldc_schema:provenance']) > 0:624 while provnumb < len(x['properties']['ucldc_schema:provenance']):625 numb = provnumb + 1626 name = 'Provenance %d' % numb627 data2[name]= x['properties']['ucldc_schema:provenance'][provnumb]628 provnumb += 1629 elif all_headers == 'y' or all_headers == 'Y':630 data2['Provenance 1'] = ''631632def get_physical_location(data2, x, all_headers):633 if x['properties']['ucldc_schema:physlocation'] != None and x['properties']['ucldc_schema:physlocation'] != '':634 data2['Physical Location'] = x['properties']['ucldc_schema:physlocation']635 elif all_headers == 'y' or all_headers == 'Y':636 data2['Physical Location'] = ''637638def object_level(filepath):639 nx = utils.Nuxeo()640 data = []641 for n in nx.children(filepath):642 data2 = {}643 644 get_title(data2, n)645 get_filepath(data2, n)646 get_type(data2, n, all_headers)647 get_alt_title(data2, n, all_headers)648 get_identifier(data2, n, all_headers)649 get_local_identifier(data2, n, all_headers)650 get_campus_unit(data2, n, all_headers)651 get_date(data2, n, all_headers)652 get_publication(data2, n, all_headers)653 get_creator(data2, n, all_headers)654 get_contributor(data2, n, all_headers)655 get_format(data2, n, all_headers)656 get_description(data2, n, all_headers)657 get_extent(data2, n, all_headers)658 get_language(data2, n, all_headers)659 get_temporal_coverage(data2, n, all_headers)660 get_transcription(data2, n, all_headers)661 get_access_restrictions(data2, n, all_headers)662 get_rights_statement(data2, n, all_headers)663 get_rights_status(data2, n, all_headers)664 get_copyright_holder(data2, n, all_headers)665 get_copyright_info(data2, n, all_headers)666 get_collection(data2, n, all_headers)667 get_related_resource(data2, n, all_headers)668 get_source(data2, n, all_headers)669 get_subject_name(data2, n, all_headers)670 get_place(data2, n, all_headers)671 get_subject_topic(data2, n, all_headers)672 get_form_genre(data2, n, all_headers)673 get_provenance(data2, n, all_headers)674 get_physical_location(data2, n, all_headers)675676 data.append(data2)677678 fieldnames = ['File path', 'Title', 'Type'] #ensures that File path, Title and Type are the first three rows679 for data2 in data:680 for key, value in data2.items():681 if key not in fieldnames:682 fieldnames.append(key)683684 return {'fieldnames':fieldnames, 'data':data, 'filename':"nuxeo_object_%s.tsv"%nx.get_metadata(path=filepath)['properties']['dc:title']}685686def item_level(filepath):687 nx = utils.Nuxeo()688 data = []689 for n in nx.children(filepath):690 for x in nx.children(n['path']):691 data2 = {}692 get_title(data2, x)693 get_filepath(data2, x)694 get_type(data2, x, all_headers)695 get_alt_title(data2, x, all_headers)696 get_identifier(data2, x, all_headers)697 get_local_identifier(data2, x, all_headers)698 get_campus_unit(data2, x, all_headers)699 get_date(data2, x, all_headers)700 get_publication(data2, x, all_headers)701 get_creator(data2, x, all_headers)702 get_contributor(data2, x, all_headers)703 get_format(data2, x, all_headers)704 get_description(data2, x, all_headers)705 get_extent(data2, x, all_headers)706 get_language(data2, x, all_headers)707 get_temporal_coverage(data2, x, all_headers)708 get_transcription(data2, x, all_headers)709 get_access_restrictions(data2, x, all_headers)710 get_rights_statement(data2, x, all_headers)711 get_rights_status(data2, x, all_headers)712 get_copyright_holder(data2, x, all_headers)713 get_copyright_info(data2, x, all_headers)714 get_collection(data2, x, all_headers)715 get_related_resource(data2, x, all_headers)716 get_source(data2, x, all_headers)717 get_subject_name(data2, x, all_headers)718 get_place(data2, x, all_headers)719 get_subject_topic(data2, x, all_headers)720 get_form_genre(data2, x, all_headers)721 get_provenance(data2, x, all_headers)722 get_physical_location(data2, x, all_headers)723 data.append(data2)724725 fieldnames = ['File path', 'Title', 'Type'] #ensures that File path, Title and Type are the first three rows726 for data2 in data:727 for key, value in data2.items():728 if key not in fieldnames:729 fieldnames.append(key)730731 return {'fieldnames':fieldnames, 'data':data, 'filename':"nuxeo_item_%s.tsv"%nx.get_metadata(path=filepath)['properties']['dc:title']}732 #returns dictionary with fieldnames, data and filename; This is used for google functions and writing to tsv if google function not choosed733734def google_object(filepath, url):735 import gspread736 from oauth2client.service_account import ServiceAccountCredentials737 obj = object_level(filepath)738 nx = utils.Nuxeo()739 scope = ['https://spreadsheets.google.com/feeds',740 'https://www.googleapis.com/auth/drive']741 creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)742 client = gspread.authorize(creds)743 with open("temp.csv", "wb") as csvfile:744 writer = csv.DictWriter(csvfile, fieldnames=obj['fieldnames'])745 writer.writeheader()746 for row in obj['data']:747 writer.writerow(row)748 with open("temp.csv", encoding="utf8") as f:749 s = f.read() + '\n'750 sheet_id = client.open_by_url(url).id751 client.import_csv(sheet_id, s)752 client.open_by_key(sheet_id).sheet1.update_title("nuxeo_object_%s"%nx.get_metadata(path=filepath)['properties']['dc:title'])753 os.remove("temp.csv")754755def google_item(filepath, url):756 import gspread757 from oauth2client.service_account import ServiceAccountCredentials758 item = item_level(filepath)759 nx = utils.Nuxeo()760 scope = ['https://spreadsheets.google.com/feeds',761 'https://www.googleapis.com/auth/drive']762 creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)763 client = gspread.authorize(creds)764 with open("temp.csv", "wb") as csvfile: #creates temporary csv file765 writer = csv.DictWriter(csvfile, fieldnames=item['fieldnames'])766 writer.writeheader()767 for row in item['data']:768 writer.writerow(row)769 with open("temp.csv", encoding="utf8") as f: #opens and reads temporary csv file770 s = f.read() + '\n'771 sheet_id = client.open_by_url(url).id 772 client.import_csv(sheet_id, s)#writes csv file to google sheet773 client.open_by_key(sheet_id).sheet1.update_title("nuxeo_item_%s"%nx.get_metadata(path=filepath)['properties']['dc:title'])774 os.remove("temp.csv") #removes temporary csv775776if 'O' in choice or 'o' in choice:777 if 'http' in url:778 try:779 google_object(filepath, url)780 except:781 print("\n*********\nWriting to Google document did not work. Make sure that Google document has been shared with API key email address")782 else:783 obj = object_level(filepath)784 with open(obj['filename'], "wb") as csvfile:785 writer = csv.DictWriter(csvfile, fieldnames=obj['fieldnames'], delimiter="\t")786 writer.writeheader()787 for row in obj['data']:788 writer.writerow(row)789if 'I' in choice or 'i' in choice:790 if 'http' in url:791 try:792 google_item(filepath, url)793 except:794 print("\n*********\nWriting to Google document did not work. Make sure that Google document has been shared with API key email address")795 else:796 item = item_level(filepath)797 with open(item['filename'], "wb") as csvfile:798 writer = csv.DictWriter(csvfile, fieldnames=item['fieldnames'], delimiter="\t")799 writer.writeheader()800 for row in item['data']: ...

Full Screen

Full Screen

include_checker.py

Source:include_checker.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2#3# include_checker.py4#5# This file is part of NEST.6#7# Copyright (C) 2004 The NEST Initiative8#9# NEST is free software: you can redistribute it and/or modify10# it under the terms of the GNU General Public License as published by11# the Free Software Foundation, either version 2 of the License, or12# (at your option) any later version.13#14# NEST is distributed in the hope that it will be useful,15# but WITHOUT ANY WARRANTY; without even the implied warranty of16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17# GNU General Public License for more details.18#19# You should have received a copy of the GNU General Public License20# along with NEST. If not, see <http://www.gnu.org/licenses/>.21import os22import re23import sys24"""25This script suggest C/CPP include orders that conform to the NEST coding style26guidelines. Call the script like (from NEST sources):27For one file:28 python extras/include_checker.py -nest $PWD -f nest/main.cpp29For one directory:30 python extras/include_checker.py -nest $PWD -d nest31If everything is OK, or only few includes are in the wrong order, it will print32something like:33 Includes for main.cpp are OK! Includes in wrong order: 034If something is wrong, it will print the suggestion:35 Includes for neststartup.h are WRONG! Includes in wrong order: 536 ##############################37 Suggested includes for neststartup.h:38 ##############################39 // C includes:40 #include <neurosim/pyneurosim.h>41 // C++ includes:42 #include <string>43 // Generated includes:44 #include "config.h"45 // Includes from conngen:46 #include "conngenmodule.h"47 // Includes from sli:48 #include "datum.h"49"""50# We would like to have files that are not actually provided by51# the NEST Initiative, e.g. implementing the Google Sparsetable,52# to be exactly like they come from the upstream source.53excludes_files = ["sparsetable.h", "libc_allocator_with_realloc.h",54 "hashtable-common.h", "sparseconfig.h", "template_util.h"]55class IncludeInfo():56 filename = ""57 name = ""58 spiky = False59 origin = "a_unknown"60 def __init__(self, filename, name, spiky, all_headers):61 self.filename = filename62 self.name = name63 self.spiky = spiky64 self.set_origin(all_headers)65 def is_header_include(self):66 return (self.name.split('.')[0] == self.filename.split('.')[0] or67 self.name.split('.')[0] == self.filename.split('_impl.')[0])68 def is_cpp_include(self):69 return (not self.name.endswith('.h') and70 not self.name.endswith('.hpp') and self.spiky)71 def is_c_include(self):72 return self.name.endswith('.h') and self.spiky73 def is_project_include(self):74 return (not self.spiky and75 (self.name.endswith('.h') or self.name.endswith('.hpp')))76 def set_origin(self, includes):77 for k, v in includes.iteritems():78 if self.name in v:79 self.origin = k80 break81 def cmp_value(self):82 v = 8 if self.is_header_include() else 083 v += 4 if self.is_c_include() else 084 v += 2 if self.is_cpp_include() else 085 v += 1 if self.is_project_include() else 086 return v87 def __cmp__(self, other):88 s = self.cmp_value()89 o = other.cmp_value()90 val = o - s91 if val == 0:92 val = cmp(self.origin, other.origin)93 if val == 0:94 return cmp(self.name, other.name)95 else:96 return val97 else:98 return val99 def to_string(self):100 l_guard = '<' if self.spiky else '"'101 r_guard = '>' if self.spiky else '"'102 return '#include ' + l_guard + self.name + r_guard103def all_includes(path):104 result = {}105 dirs = [d for d in next(os.walk(path))[1] if d[0] != '.']106 for d in dirs:107 for root, dirs, files in os.walk(os.path.join(path, d)):108 tmp = [f for f in files if f.endswith(".h") or f.endswith(".hpp")]109 if len(tmp) > 0:110 result[d] = tmp111 return result112def create_include_info(line, filename, all_headers):113 match = re.search('^#include ([<"])(.*)([>"])', line)114 name = match.group(2)115 spiky = match.group(1) == '<'116 return IncludeInfo(filename, name, spiky, all_headers)117def get_includes_from(file, all_headers):118 includes = []119 with open(file, 'r') as f:120 for line in f:121 if line.startswith('#include'):122 includes += [create_include_info(line,123 os.path.basename(file),124 all_headers)]125 return includes126def is_include_order_ok(includes):127 s_incs = sorted(includes)128 return len(includes) - len([i for i, s in zip(includes, s_incs)129 if i.name == s.name])130def print_includes(includes):131 s_incs = sorted(includes)132 is_c = False133 is_cpp = False134 origin = ""135 for i in s_incs:136 if not i.is_header_include():137 if not is_c and i.is_c_include():138 is_c = True139 is_cpp = False140 origin = ""141 print("\n// C includes:")142 if not is_cpp and i.is_cpp_include():143 is_c = False144 is_cpp = True145 origin = ""146 print("\n// C++ includes:")147 if i.is_project_include() and origin != i.origin:148 is_c = False149 is_cpp = False150 origin = i.origin151 if i.origin == "a_unknown":152 print("\n// Generated includes:")153 else:154 print("\n// Includes from " + i.origin + ":")155 print(i.to_string())156def process_source(path, f, all_headers, print_suggestion):157 if f in excludes_files:158 print("Not checking file " + f + " as it is in the exclude list. " +159 "Please do not change the order of includes.")160 return 0161 includes = get_includes_from(os.path.join(path, f), all_headers)162 order_ok = is_include_order_ok(includes)163 if order_ok <= 2:164 print("Includes for " + f + " are OK! Includes in wrong order: " +165 str(order_ok))166 if order_ok > 2:167 print("Includes for " + f + " are WRONG! Includes in wrong order: " +168 str(order_ok))169 if print_suggestion:170 print("\n##############################")171 print("Suggested includes for " + f + ":")172 print("##############################\n")173 print_includes(includes)174 print("\n##############################")175 return order_ok176def process_all_sources(path, all_headers, print_suggestion):177 count = 0178 for root, dirs, files in os.walk(path):179 for f in files:180 if re.search("\.h$|\.hpp$|\.c$|\.cc|\.cpp$", f):181 # valid source file182 count += process_source(root, f, all_headers, print_suggestion)183 for d in dirs:184 count += process_all_sources(os.path.join(root, d), all_headers,185 print_suggestion)186 return count187def usage(exitcode):188 print("Use like:")189 print(" " + sys.argv[0] + " -nest <nest-base-dir>" +190 " (-f <filename> | -d <base-directory>)")191 sys.exit(exitcode)192if __name__ == '__main__':193 print_suggestion = True194 if len(sys.argv) != 5:195 usage(1)196 if sys.argv[1] == '-nest' and os.path.isdir(sys.argv[2]):197 all_headers = all_includes(sys.argv[2])198 else:199 usage(2)200 if sys.argv[3] == '-f' and os.path.isfile(sys.argv[4]):201 path = os.path.dirname(sys.argv[4])202 file = os.path.basename(sys.argv[4])203 process_source(path, file, all_headers, print_suggestion)204 elif sys.argv[3] == '-d' and os.path.isdir(sys.argv[4]):205 dir = sys.argv[4]206 process_all_sources(dir, all_headers, print_suggestion)207 else:...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful