def main(): from geobox.config import GeoBoxConfig, GeoBoxState config = GeoBoxConfig.from_file('./geobox.ini') if not config: sys.exit(1) app_state = GeoBoxState(config) session = app_state.user_db_session() # create test tasks tasks = [] tasks.append( VectorImportTask(db_name='foobar', file_name=path('../example_data/points.shp'))) tasks.append( VectorImportTask(db_name='foobar', file_name=path('../example_data/lines.shp'))) tasks.append( ReplicationTask(db_name='foobar', remote_db_url='http://127.0.0.1:5984', remote_db_name='foobar2', push=True)) tasks.append( ReplicationTask(db_name='foobar', remote_db_url='http://127.0.0.1:5984', remote_db_name='foobar2', pull=True)) source = model.ExternalWMTSSource( name='test', url="http://a.tile.openstreetmap.org/%(z)s/%(x)s/%(y)s.png", format='png') layer = session.query(model.RasterLayer).filter_by(name='osm').all() if layer: layer = layer[0] else: layer = model.RasterLayer(name='osm') import_task = model.RasterImportTask(source=source, layer=layer, zoom_level_start=0, zoom_level_end=5) tasks.append(import_task) tasks.append( ExportProject(title="test project", download_level_start=2, download_level_end=10, raster_tasks=[ RasterExportTask( layer=RasterLayer(name='test raster layer'), export_format='jpeg') ])) for t in tasks: session.add(t) session.commit() # list all tasks for t in session.query(model.Task).with_polymorphic('*'): print t
def build_app_command(): """Build GeoBox Python application as .exe""" pyinstaller_spec_tpl = open(path('geobox.spec.tpl')).read() template = string.Template(pyinstaller_spec_tpl) pyinstaller_spec = path('geobox.spec') pyinstaller_spec.write_text(template.substitute(config)) call(['python', config['pyinstaller_dir'] / 'pyinstaller.py', pyinstaller_spec, '-y'])
def prepare_command(): log.mark('preparing couchdb') log.info('removing unneeded erlang packages') with config['couchdb_dir'].as_working_dir(): lib_dir = path('lib') for lib_name in rm_erl_libs: lib = lib_dir.dirs(lib_name) if lib: lib[0].rmtree() else: log.warn('could not find %s' % lib_name) for rm in [ 'erts-*/src', 'erts-*/include', 'erts-*/man', 'erts-*/doc', 'lib/*/src', 'lib/*/examples', 'lib/*/include', 'share/info', 'share/couchdb/www/docs/', ]: for p in path('.').glob(rm): p.rmtree(ignore_errors=True)
def build_app_command(): """Build GeoBox Python application as .exe""" pyinstaller_spec_tpl = open(path('geobox.spec.tpl')).read() template = string.Template(pyinstaller_spec_tpl) pyinstaller_spec = path('geobox.spec') pyinstaller_spec.write_text(template.substitute(config)) call([ 'python', config['pyinstaller_dir'] / 'pyinstaller.py', pyinstaller_spec, '-y' ])
def tar(self, dest, archive_base=None): dest = path(dest) if archive_base is None: archive_base = path(self.dest.basename()).splitext()[0] tar = tarfile.open(dest, 'w:gz') for f in self: log.info('adding %s', f) tar.add(f, arcname=archive_base / f, recursive=False) tar.close()
def tar(self, dest, archive_base=None): dest = path(dest) if archive_base is None: archive_base = path(self.dest.basename()).splitext()[0] tar = tarfile.open(dest, 'w:gz') for f in self: log.info('adding %s', f) tar.add(f, arcname=archive_base/f, recursive=False) tar.close()
def zipdist_command(): print 'creating scriptine.zip' if __file__ is None: print 'ERROR: creating zipdist from zipped scriptine is not supported.' return 1 from zipfile import ZipFile, ZIP_DEFLATED zipfile = ZipFile('scriptine.zip', 'w', compression=ZIP_DEFLATED) scripyt_src = path(__file__).dirname() for filename in path(scripyt_src).files('*.py'): arcname = path().joinpath(*filename.splitall()[-2:]) zipfile.write(filename, arcname) zipfile.close()
def zipdist_command(): print('creating scriptine.zip') if __file__ is None: print('ERROR: creating zipdist from zipped scriptine is not supported.') return 1 from zipfile import ZipFile, ZIP_DEFLATED zipfile = ZipFile('scriptine.zip', 'w', compression=ZIP_DEFLATED) scripyt_src = path(__file__).dirname() for filename in path(scripyt_src).files('*.py'): arcname = path().joinpath(*filename.splitall()[-2:]) zipfile.write(filename, arcname) zipfile.close()
def load_build_conf(): parser = ConfigParser() parser.readfp(open(path(__file__).dirname() + 'build.ini')) config = {} for key, value in parser.items('build'): if value.startswith(('./', '/')) or value[1:3] == ':\\': config[key.lower()] = path(value).abspath() else: config[key.lower()] = value # modify version for console builds if config['build_with_console'] == 'True': config['version'] += '-console' return config
def create_ticket_filepath(cls, folder_name, extensionless_filename, extension='.pdf'): tickets_directory = scriptine.path(settings.STATIC_ROOT).joinpath('tickets') if not tickets_directory.exists(): tickets_directory.mkdir() specific_tickets_directory = tickets_directory.joinpath(folder_name) if not specific_tickets_directory.exists(): specific_tickets_directory.mkdir() filepath = specific_tickets_directory.joinpath(extensionless_filename) filepath += extension return filepath
def main(): from geobox.config import GeoBoxConfig, GeoBoxState config = GeoBoxConfig.from_file('./geobox.ini') if not config: sys.exit(1) app_state = GeoBoxState(config) session = app_state.user_db_session() # create test tasks tasks = [] tasks.append(VectorImportTask(db_name='foobar', file_name=path('../example_data/points.shp') )) tasks.append(VectorImportTask(db_name='foobar', file_name=path('../example_data/lines.shp') )) tasks.append(ReplicationTask(db_name='foobar', remote_db_url='http://127.0.0.1:5984', remote_db_name='foobar2', push=True)) tasks.append(ReplicationTask(db_name='foobar', remote_db_url='http://127.0.0.1:5984', remote_db_name='foobar2', pull=True)) source = model.ExternalWMTSSource(name='test', url="http://a.tile.openstreetmap.org/%(z)s/%(x)s/%(y)s.png", format='png') layer = session.query(model.RasterLayer).filter_by(name='osm').all() if layer: layer = layer[0] else: layer = model.RasterLayer(name='osm') import_task = model.RasterImportTask(source=source, layer=layer, zoom_level_start=0, zoom_level_end=5) tasks.append(import_task) tasks.append(ExportProject(title="test project", download_level_start=2, download_level_end=10, raster_tasks=[ RasterExportTask(layer= RasterLayer(name = 'test raster layer') , export_format='jpeg') ])) for t in tasks: session.add(t) session.commit() # list all tasks for t in session.query(model.Task).with_polymorphic('*'): print t
def mysqldump(): for DB in config['databases']: # check/fix paths in BACKUP_DIR - remove trailing slash BACKUP_DIR = config['rsync']['backup_dir'] if not BACKUP_DIR[-1] == '/': pass else: BACKUP_DIR = config['rsync']['backup_dir'][:-1] # check/fix paths in mysql_backup_dir - add leading slash MYSQL_DIR = config['mysql']['backup_dir'] if MYSQL_DIR[0] == '/': pass else: MYSQL_DIR = '/' + MYSQL_DIR # check/fix paths in mysql_backup_dir - add trailing slash if MYSQL_DIR[-1] == '/': pass else: MYSQL_DIR = MYSQL_DIR + '/' # fix paths in DATETIME - add trailing slash DATETIME = time.strftime("%d-%m-%Y") DATETIME = DATETIME + '/' MYSQL_ROOT_DIR = BACKUP_DIR + MYSQL_DIR REAL_DIR = BACKUP_DIR + MYSQL_DIR + DATETIME # ensure that backup_dirs exist outdir = path(REAL_DIR) if not outdir.exists(): log.mark('Creating mysql dir %s' % outdir) outdir.makedirs() # dumping all databases sh('/usr/bin/echo Dumping %s >> %s' % (DB, config['rsync']['log_file'])) sh('/usr/bin/mysqldump -h %s -u %s -p%s %s | gzip -9 > %s%s.sql.gz' % (config['mysql']['server'], config['mysql']['user'], config['mysql']['password'], DB, REAL_DIR, DB)) sh('/usr/bin/echo Done >> %s' %config['rsync']['log_file']) # cleaning old databases in mysql_backup_dir sh('/usr/bin/find %s -type d -mtime +%s -exec /bin/rm -rf {} \; &>/dev/null' % (MYSQL_ROOT_DIR, config['find']['days']))
def rsync(): """ Sync everything from config['dirs'] to config['backup_dir'] """ for DIRS in config['dirs']: # check/fix paths in BACKUP_DIR - remove trailing slash BACKUP_DIR = config['rsync']['backup_dir'] if not config['rsync']['backup_dir'][-1] == '/': pass else: BACKUP_DIR = config['rsync']['backup_dir'][:-1] # check/fix paths in DIRS - add colon before dir and trailing slash in the end if DIRS[-1] == '/': REAL_DIR = DIRS pass else: REAL_DIR = DIRS + '/' if REAL_DIR[0] == ':': pass else: REAL_DIR = ':' + REAL_DIR # ensure that backup_dirs exist for dirname in config['dirs']: outdir = path( BACKUP_DIR + dirname) if not outdir.exists(): log.mark('Creating backup_dirs %s' % outdir) outdir.makedirs() # check/fix USER - add trailing @ to the username USER = config['rsync']['user'] if config['rsync']['user'][-1] == '@': pass else: USER = USER + '@' log.mark('Starting rsync.....') sh('/usr/bin/rsync %s %s%s%s %s%s &>>%s' % (config['rsync']['args'], USER, config['rsync']['server'], REAL_DIR, config['rsync']['backup_dir'][:-1], REAL_DIR[1:], config['rsync']['log_file']))
def clean_all_command(): path('build/').rmtree(ignore_errors=True) for pyc in path.cwd().walkfiles('*.pyc'): pyc.remove()
def test_path_guard(): options.dry = True path("/tmp/foobarbaz.txt").install("hello", chmod=0644)
def create_iss_config_command(): iss_tpl = open(path('installer.iss.tpl')).read() template = string.Template(iss_tpl) (config['build_dir'] / 'installer.iss').write_text( template.substitute(config))
def build_app_command(): """Build GeoBox Python application as .exe.""" geobox_conf = config.get('appconfig') if geobox_conf: path(geobox_conf).copy(path('../app/geobox/appconfig.py')) gbi_editor = path('../app/geobox/web/static/js/gbi-editor') if gbi_editor.exists() and not gbi_editor.isdir(): print "remove gbi-editor link!" sys.exit(2) print "copying gbi-editor" if gbi_editor.exists(): gbi_editor.rmtree() path('../gbi-editor/src').copytree(gbi_editor) # insert version app_content = path('../app/geobox/app.py').bytes() app_content = re.sub(r"version = '[^']*'", "version = '%s'" % config['version'], app_content) path('../app/geobox/app.py').write_bytes(app_content) pyinstaller_spec_tpl = open(path('geobox.spec.tpl')).read() template = string.Template(pyinstaller_spec_tpl) pyinstaller_spec = path('geobox.spec') pyinstaller_spec.write_text(template.substitute(config)) call([ 'python', config['pyinstaller_dir'] / 'pyinstaller.py', pyinstaller_spec, '-y' ])
def test_path_guard(): options.dry = True path('/tmp/foobarbaz.txt').install('hello', chmod=0o644)
def clean_all_command(): path("build/").rmtree(ignore_errors=True) for pyc in path.cwd().walkfiles("*.pyc"): pyc.remove()
from django.core.files import File import scriptine from ticket_exchange.pdfs import ProcessTicket, ProcessBaseTicket pdf_filepath = scriptine.path('/home/michael/Documents/Ticket Exchange/ticket pdfs/eTicket.pdf') pdf = File(open(pdf_filepath)) pdf_object = ProcessBaseTicket(pdf)
def build_app_command(): """Build GeoBox Python application as .exe.""" geobox_conf = config.get('appconfig') if geobox_conf: path(geobox_conf).copy(path('../app/geobox/appconfig.py')) gbi_editor = path('../app/geobox/web/static/js/gbi-editor') if gbi_editor.exists() and not gbi_editor.isdir(): print "remove gbi-editor link!" sys.exit(2) print "copying gbi-editor" if gbi_editor.exists(): gbi_editor.rmtree() path('../gbi-editor/src').copytree(gbi_editor) # insert version app_content = path('../app/geobox/app.py').bytes() app_content = re.sub(r"version = '[^']*'", "version = '%s'" % config['version'], app_content) path('../app/geobox/app.py').write_bytes(app_content) pyinstaller_spec_tpl = open(path('geobox.spec.tpl')).read() template = string.Template(pyinstaller_spec_tpl) pyinstaller_spec = path('geobox.spec') pyinstaller_spec.write_text(template.substitute(config)) call(['python', config['pyinstaller_dir'] / 'pyinstaller.py', pyinstaller_spec, '-y'])
def create_iss_config_command(): iss_tpl = open(path('installer.iss.tpl')).read() template = string.Template(iss_tpl) (config['build_dir'] / 'installer.iss').write_text(template.substitute(config))
def __init__(self): self.files = [] self.base = path('.')