Exemplo n.º 1
0
def importxml(*files, **options):
	db = sqlbackend.connect(**options)
	fileList = []
	for file in files:
		fileList += glob.glob(file)
	for filename in fileList:
		warn("Processing '%s'...\n" % filename)
		processFile(filename, db, options['backend'])
	db.close()
Exemplo n.º 2
0
def export(printer=sys.stdout, **options):
	global StartTime
	StartTime = time.time()
	db = sqlbackend.connect(**options)
	cursor = db.cursor()

	if 'path' not in options:
		sys.exit("musicsql.database.exportxml.export: the 'path' argument is required.")
	command = "SELECT * FROM files WHERE path = '%s';"
	cursor.execute(command % options['path'])
	fileInfo = fetchrows(cursor)
	if fileInfo:
		fileInfo = fileInfo[0]
	else:
		sys.exit('Error: that file is not in the database!\n')
	if 'parts' in options:
		attrs = ', '.join(["'%s'" % x for x in options['parts'].split(',')])
		command = ('SELECT * FROM parts WHERE file_id = %%s ' +
				   'AND part_attr IN (%s)') % attrs
	else:
		command = 'SELECT * FROM parts WHERE file_id = %s'
	cursor.execute(command % fileInfo['row_id'])
	parts = fetchrows(cursor)
	if not parts:
		sys.exit('Error: no valid parts were found.')
	if 'ticks' in options:
		bounds = [int(x) for x in options['ticks'].split('-')]
		command = '''
		  SELECT _start_tick, number
		  FROM measures
		  WHERE file_id = %s
		  ORDER BY _start_tick
		''' % fileInfo['row_id']
		cursor.execute(command)
		results = cursor.fetchall()
		arr = [x[1] for x in results if int(x[0]) <= bounds[0]]
		bounds[0] = int(arr[-1])
		arr = [x[1] for x in results if int(x[0]) <= bounds[1]]
		bounds[1] = int(arr[-1])
		measures = '%d-%d' % tuple(bounds)
	else:
		measures = options.get('measures', None)
	output = '''<?xml version="1.0" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
'''
	printer.write(output)
	dom = xml.dom.minidom.Document()
	printer.write(fileHeader(dom, fileInfo, parts, cursor))
	highlighted = options.get('highlighted', None)
	addParts(dom, fileInfo, parts, db, cursor, options['backend'],
			 measures, highlighted, printer)
	printer.write('</score-partwise>\n')
	warn('Completed in %d seconds.\n' % (time.time() - StartTime))