1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import os
import string
import time
import sys
import configparser
import platform
import ontology_prefixes
import tools
# all ontology modules
import ncal
import nmm
import nco
import nfo
import mfo
import mto
import nmo
import mlo
import slo
import tracker
def recent_enough_python ():
"""
True if it is 2.6 or more recent
"""
print("Running generate with python", platform.python_version ())
version = platform.python_version_tuple ()
return (int(version[0]) >= 2 and int(version[1]) >= 6)
####################################################################################
def argument_parser():
parser = argparse.ArgumentParser(description="Nepomuk test data generator")
parser.add_argument('config_file', nargs=1)
parser.add_argument('output_dir', nargs='?')
return parser
args = argument_parser().parse_args()
config = configparser.RawConfigParser()
try:
loaded_files = config.read(args.config_file)
# config.read
# in 2.3 return None
# in 2.6+ returns a list of loaded files
if recent_enough_python ():
if (len (loaded_files) != 1):
print("Cannot open %s" % (args.config_file))
sys.exit (-1)
except Exception as e:
print("Failed to read configuration file %s (%s)" % (args.config_file, e))
sys.exit (-1)
if args.output_dir:
if not os.path.exists(args.output_dir):
os.makedirs(args.output_dir)
def get_counter (section, option):
if config.has_option (section, option):
return config.getint (section, option)
else:
return 1
# set up all known types
tools.addType( 'nco#EmailAddress', 10 )
tools.addType( 'nco#PostalAddress', 11 )
tools.addType( 'nco#PhoneNumber', 12 )
tools.addType( 'nco#IMAddress', 13 )
tools.addType( 'nco#ContactEmail', 14 )
tools.addType( 'nco#ContactCall', 15 )
tools.addType( 'nco#ContactIM', 16 )
tools.addType( 'nco#PersonContact', 18 )
tools.addType( 'slo#GeoLocation', 20 )
tools.addType( 'slo#Landmark', 21 )
tools.addType( 'mlo#GeoPoint', 26 )
tools.addType( 'mlo#LocationBoundingBox', 27 )
tools.addType( 'mlo#GeoLocation', 28 )
tools.addType( 'mlo#Landmark', 29 )
tools.addType( 'nmo#MailAccount', 30 )
tools.addType( 'nmo#MailFolder', 31 )
tools.addType( 'nmo#Email', 32 )
tools.addType( 'nmo#CommunicationChannel', 35 )
tools.addType( 'nmo#IMMessage', 36 )
tools.addType( 'nmo#SMSMessage', 37 )
tools.addType( 'nmo#Call', 38 )
tools.addType( 'nmm#Artist', 40 )
tools.addType( 'nmm#MusicAlbumDisc', 40)
tools.addType( 'nmm#MusicAlbum', 41 )
tools.addType( 'nmm#MusicPiece', 42 )
tools.addType( 'nfo#Equipment', 44 )
tools.addType( 'nmm#Photo', 45 )
tools.addType( 'nmm#Video', 46 )
tools.addType( 'tracker#Volume', 50 )
tools.addType( 'nfo#PlainTextDocument', 51 )
tools.addType( 'nfo#SoftwareCategory', 60 )
tools.addType( 'nfo#SoftwareApplication', 61 )
tools.addType( 'nfo#WebHistory', 65 )
tools.addType( 'ncal#Alarm', 70 )
tools.addType( 'ncal#Calendar', 71 )
tools.addType( 'ncal#Event', 72 )
tools.addType( 'ncal#Todo', 73 )
tools.addType( 'mfo#FeedChannel', 80 )
tools.addType( 'mfo#FeedMessage', 81 )
tools.addType( 'mto#TransferElement', 90 )
tools.addType( 'mto#UploadTransfer', 91 )
print("Generating Contacts")
count_contacts = get_counter('counts','contacts')
for contact in range(1, count_contacts+1):
if (contact % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nco.generateEmailAddress( contact )
nco.generateContactEmail( contact )
nco.generatePostalAddress( contact )
nco.generatePhoneNumber( contact )
nco.generateContactCall( contact )
nco.generateIMAddress( contact )
nco.generateContactIM( contact )
nco.generatePersonContact( contact )
print("Done")
print("Generating Locations and landmarks")
count_locations = get_counter('counts','locations')
for location in range(1, count_locations+1):
if (location % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
slo.generateGeoLocation( location )
slo.generateLandmark( location )
count_locations = get_counter('counts','locations')
for location in range(1, count_locations+1):
if (location % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
mlo.generateGeoPoint( location )
mlo.generateLocationBoundingBox( location )
mlo.generateGeoLocation( location )
mlo.generateLandmark( location )
print("Done")
print("Generate Emails")
count_accounts = get_counter('counts','accounts')
count_folders = get_counter('counts','folders')
count_emails = get_counter('counts','emails')
for account in range(1, count_accounts+1):
sys.stdout.write('.')
sys.stdout.flush()
nmo.generateMailAccount( account*count_folders*count_emails )
for folder in range(1, count_folders+1):
nmo.generateMailFolder( account*count_folders*count_emails+folder*count_emails )
for email in range(1, count_emails+1):
nmo.generateEmail( account*count_folders*count_emails+folder*count_emails+email )
print("Done")
print("Generate IM messages")
count_comchans = get_counter('counts','comchans')
count_ims = get_counter('counts','ims')
for comchannel in range(1, count_comchans+1):
sys.stdout.write('.')
sys.stdout.flush()
nmo.generateCommunicationChannel( comchannel )
for im in range(1, count_ims+1):
nmo.generateIMMessage( comchannel*count_ims+im )
print("Done")
print("Generate SMS messages")
count_sms = get_counter('counts','sms')
for sms in range(1, count_sms+1):
if (sms % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nmo.generateSMSMessage( sms )
print("Done")
print("Generate calls")
count_calls = get_counter('counts','calls')
for call in range(1, count_calls+1):
if (call % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nmo.generateCall( call )
print("Done")
print("* Starting with file system based content")
print("Generate volumes")
count_volumes = get_counter('counts','volumes')
for volume in range(1, count_volumes+1):
sys.stdout.write('.')
sys.stdout.flush()
tracker.generateVolume( volume )
print("Done")
print("Generating Music")
count_artists = get_counter('counts','artists')
count_albums = get_counter('counts','albums')
count_songs = get_counter('counts','songs')
count_discs = get_counter('counts','discs')
song_index = 0
for artist in range(1, count_artists+1):
sys.stdout.write('.')
sys.stdout.flush()
nmm.generateArtist( artist*count_albums*count_songs )
for album in range(1, count_albums+1):
nmm.generateAlbum( artist*count_albums*count_songs+album )
for disc in range(1, count_discs+1):
discUri = nmm.generateMusicAlbumDisc( artist*count_albums*count_songs+album+disc )
for song in range(1, count_songs+1):
nmm.generateMusicPiece( song_index, discUri )
song_index = song_index + 1
print("Done")
print("Generate Equipment")
count_equipment = get_counter('counts','equipment')
nmm.generateOwnEquipment ()
for equipment in range(1, count_equipment):
if (equipment % 2 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nmm.generateEquipment( equipment )
print("Done")
print("Generate Photos")
count_images = get_counter('counts','images')
for photo in range(1, count_images+1):
if (photo % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nmm.generatePhoto( photo )
print("Done")
print("Generate Videos")
count_videos = get_counter('counts','videos')
for video in range(1, count_videos+1):
if (video % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nmm.generateVideo( video )
print("Done")
print("Generate plain text documents")
count_docs = get_counter('counts','docs')
for doc in range(1, count_docs+1):
if (doc % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nfo.generatePlainTextDocument( doc )
print("Done")
print("Generate feeds")
count_fchans = get_counter('counts','fchans')
count_fms = get_counter('counts','fms')
for fchan in range(1, count_fchans+1):
sys.stdout.write('.')
sys.stdout.flush()
mfo.generateFeedChannel( fchan*count_fms )
for fm in range(1, count_fms+1):
mfo.generateFeedMessage( fchan*count_fms+fm )
print("Done")
print("Generate software")
count_softcats = get_counter('counts','softcats')
count_softapps = get_counter('counts','softapps')
for softcat in range(1, count_softcats+1):
sys.stdout.write('.')
sys.stdout.flush()
nfo.generateSoftwareCategory( softcat*count_softapps )
for softapp in range(1, count_softapps+1):
nfo.generateSoftwareApplication( softcat*count_softapps+softapp )
print("Done")
print("Generate something for the rest")
count_others = get_counter('counts','others')
for index in range(1,count_others+1):
if (index % 10 == 0):
sys.stdout.write('.')
sys.stdout.flush()
nfo.generateWebHistory( index )
ncal.generateAlarm( index )
ncal.generateCalendar( index )
ncal.generateEvent( index )
ncal.generateTodo( index )
mto.generateTransferElement( index )
mto.generateUploadTransfer( index )
print("Done")
# dump all files
tools.saveResult(output_dir=args.output_dir)
|