Beispiel #1
0
def countriesSource() -> InputSource:
    '''
    Provides the countries input source for the XML.
    '''
    source = InputSource()
    source.setByteStream(openURI(path.join(path.dirname(__file__), 'iso_3166-1_list_en.xml')))
    return source
Beispiel #2
0
 def deploy(self):
     '''
     Deploy the meta data and all handlers.
     '''
     self._metaType = metaTypeFor(self.session(), META_TYPE_KEY)
     self._thumbnail = thumbnailFor(self.session(), '%(size)s/other.jpg')
     referenceLast = self.thumbnailReferencer.timestampThumbnail(self._thumbnail.id)
     imagePath = join(pythonPath(), 'resources', 'other.jpg')
     if referenceLast is None or referenceLast < timestampURI(imagePath):
         self.thumbnailReferencer.processThumbnail(openURI(imagePath), self._thumbnail.id)
Beispiel #3
0
def updateDemoFile():
    try:
        bootPath = lib_folder_format() % "core/"
        with openURI(getGuiPath(ui_demo_file())) as f:
            out = f.read().replace(b"{server_url}", bytes(server_url(), "utf-8"))
            cdmGUI().publishFromFile(bootPath + ui_demo_file(), BytesIO(out))
    except Exception as e:
        print("Error publishing demo client file:", e)
        return
    assert log.debug("Client demo script published:", server_url() + getPublishedLib("core/" + ui_demo_file())) or True
Beispiel #4
0
def configureMongrel2():
    if not options.isFlag(FLAG_CONFIG_MONGREL2): return
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    folder = options.mongrel2Folder or 'workspace'

    for name in folders:
        folder = path.join(folder, name)
        if not path.isdir(folder): makedirs(folder)

    updateConfig = False
    if server_type() != 'mongrel2':
        updateConfig = True
        support.persist(server_type, 'mongrel2')

    sendIdent = send_ident()
    if sendIdent is None:
        updateConfig = True
        sendIdent = str(uuid4())
        support.persist(send_ident, sendIdent)

    replace = {}
    replace['${send_spec}'] = send_spec()
    replace['${send_ident}'] = sendIdent
    replace['${recv_spec}'] = recv_spec()
    replace['${recv_ident}'] = recv_ident()
    replace['${server_port}'] = str(server_port())

    if updateConfig: saveConfigurations(context.configurationsExtract())

    conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
    conf = codecs.getreader('utf8')(conf)
    conf = ReplaceInStream(conf, replace)
    with open(path.join(folder, 'ally.conf'), 'w') as f:
        pipe(conf, f)
    with open(path.join(folder, 'README-Mongrel2.txt'), 'wb') as f:
        pipe(
            openURI(path.join(pythonPath(), 'resources',
                              'README-Mongrel2.txt')), f)

    log.info('Configured \'%s\' mongrel2 workspace' % folder)
def defaultPosts():
    '''
    Reads posts data from posts.csv (CSV) file
    '''
    posts = []
    postsFile = join(dirname(abspath(__file__)), 'posts.csv')
    with openURI(postsFile, byteMode=False) as csvfile:
        postsRead = csv.reader(csvfile, delimiter=',', quotechar='"')
        for post in postsRead:
            posts.append(post)
    return posts
Beispiel #6
0
def defaultPosts():
    '''
    Reads posts data from posts.csv (CSV) file
    '''
    posts = []
    postsFile = join(dirname(abspath(__file__)), 'posts.csv')
    with openURI(postsFile, byteMode=False) as csvfile:
        postsRead = csv.reader(csvfile, delimiter=',', quotechar='"')
        for post in postsRead:
            posts.append(post)
    return posts
def defaultBlogs():
    '''
    Reads blogs data from blogs.csv (CSV) file
    '''
    blogs = {}
    blogsFile = join(dirname(abspath(__file__)), 'blogs.csv')
    with openURI(blogsFile, byteMode=False) as csvfile:
        blogsRead = csv.reader(csvfile, delimiter=',', quotechar='"')
        for blog in blogsRead:
            data = (BLOGS_DEFAULTS[0], blog[1], BLOGS_DEFAULTS[1], blog[2], datetime.now(), datetime.now())
            blogs[blog[0]] = data
    return blogs
def defaultBlogs():
    '''
    Reads blogs data from blogs.csv (CSV) file
    '''
    blogs = {}
    blogsFile = join(dirname(abspath(__file__)), 'blogs.csv')
    with openURI(blogsFile, byteMode=False) as csvfile:
        blogsRead = csv.reader(csvfile, delimiter=',', quotechar='"')
        for blog in blogsRead:
            data = (BLOGS_DEFAULTS[0], blog[1], BLOGS_DEFAULTS[1], blog[2], datetime.now(), datetime.now())
            blogs[blog[0]] = data
    return blogs
Beispiel #9
0
def configureMongrel2():
    if not options.isFlag(FLAG_CONFIG_MONGREL2): return
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    folder = options.mongrel2Folder or 'workspace'
    
    for name in folders:
        folder = path.join(folder, name)
        if not path.isdir(folder): makedirs(folder)
    
    updateConfig = False
    if server_type() != 'mongrel2':
        updateConfig = True
        support.persist(server_type, 'mongrel2')
    
    sendIdent = send_ident()
    if sendIdent is None:
        updateConfig = True
        sendIdent = str(uuid4())
        support.persist(send_ident, sendIdent)
    
    replace = {}
    replace['${send_spec}'] = send_spec()
    replace['${send_ident}'] = sendIdent
    replace['${recv_spec}'] = recv_spec()
    replace['${recv_ident}'] = recv_ident()
    replace['${server_port}'] = str(server_port())

    if updateConfig: saveConfigurations(context.configurationsExtract())
        
    conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
    conf = codecs.getreader('utf8')(conf)
    conf = ReplaceInStream(conf, replace)
    with open(path.join(folder, 'ally.conf'), 'w') as f: pipe(conf, f)
    with open(path.join(folder, 'README-Mongrel2.txt'), 'wb') as f:
        pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f)
    
    log.info('Configured \'%s\' mongrel2 workspace' % folder)
Beispiel #10
0
def updateStartup():
    if not publish_gui_resources(): return  # No publishing is allowed
    bootPath = lib_folder_format() % 'core/'
    fileList = []
    for x in js_core_libs():
        try: fileList.append(openURI(getGuiPath(js_core_libs_format() % x)))
        except: pass

    try: cdmGUI().remove(bootPath + js_bootstrap_file())
    except: pass
    cdmGUI().publishContent(bootPath + js_bootstrap_file(), BytesIO(b'\n'.join([fi.read() for fi in fileList])))

    for f in fileList: f.close()
Beispiel #11
0
def updateStartFile():
    if not publish_gui_resources(): return  # No publishing is allowed
    try:
        bootPath = lib_folder_format() % 'core/'
        with openURI(getGuiPath(ui_demo_file())) as f:
            out = f.read().replace(b'{server_url}', bytes(server_url(), 'utf-8'))
            out = out.replace(b'{gui}', bytes(gui_folder_format(), 'utf-8'));
            out = out.replace(b'{lib_core}', bytes(bootPath, 'utf-8'));
            cdmGUI().publishFromFile(bootPath + ui_demo_file(), BytesIO(out))
    except:
        log.exception('Error publishing demo client file')
    else:
        assert log.debug('Client start script published:', server_url() + getPublishedLib('core/' + ui_demo_file())) or True
Beispiel #12
0
def updateStartup():
    if not publish_gui_resources(): return  # No publishing is allowed
    bootPath = lib_folder_format() % 'core/'
    fileList = []
    for x in js_core_libs():
        try: fileList.append(openURI(getGuiPath(js_core_libs_format() % x)))
        except: pass

    try: cdmGUI().remove(bootPath + js_bootstrap_file())
    except: pass
    cdmGUI().publishContent(bootPath + js_bootstrap_file(), BytesIO(b'\n'.join([fi.read() for fi in fileList])))

    for f in fileList: f.close()
Beispiel #13
0
def updateStartFile():
    if not publish_gui_resources(): return  # No publishing is allowed
    try:
        bootPath = lib_folder_format() % 'core/'
        with openURI(getGuiPath(ui_demo_file())) as f:
            out = f.read().replace(b'{server_url}', bytes(server_url(), 'utf-8'))
            out = out.replace(b'{gui}', bytes(gui_folder_format(), 'utf-8'));
            out = out.replace(b'{lib_core}', bytes(bootPath, 'utf-8'));
            cdmGUI().publishFromFile(bootPath + ui_demo_file(), BytesIO(out))
    except:
        log.exception('Error publishing demo client file')
    else:
        assert log.debug('Client start script published:', server_url() + getPublishedLib('core/' + ui_demo_file())) or True
Beispiel #14
0
def updateDemoEmbedFile():
    if not publish_gui_resources(): return  # No publishing is allowed
    bootPath = lib_folder_format() % 'livedesk-embed/'
    for file in ui_demo_embed_files():
        try:        
            with openURI(getGuiPath(file)) as f:
                out = f.read().replace(b'{server_url}', bytes(embed_server_url(), 'utf-8'))
                out = out.replace(b'{gui}', bytes(gui_folder_format(), 'utf-8'));
                out = out.replace(b'{lib_core}', bytes(lib_folder_format() % 'core/', 'utf-8'));
                cdmGUI().publishContent(bootPath + file, BytesIO(out))
        except:
            log.exception('Error publishing demo client file')
        else:
            assert log.debug('Client demo script published: \'%s\'', embed_server_url() + getPublishedLib('livedesk-embed/' + file)) or True
Beispiel #15
0
def updateStartup():
    bootPath = lib_folder_format() % "core/"
    fileList = []
    for x in js_core_libs():
        try:
            fileList.append(openURI(getGuiPath(js_core_libs_format() % x)))
        except:
            pass

    try:
        cdmGUI().removePath(bootPath + js_bootstrap_file())
    except:
        pass
    cdmGUI().publishFromFile(bootPath + js_bootstrap_file(), BytesIO(b"\n".join([fi.read() for fi in fileList])))

    for f in fileList:
        f.close()
Beispiel #16
0
def updateDemoEmbedFile():
    if not publish_gui_resources(): return  # No publishing is allowed
    try:
        bootPath = lib_folder_format() % 'livedesk-embed/'
        with openURI(getGuiPath(ui_demo_embed_file())) as f:
            out = f.read().replace(b'{server_url}',
                                   bytes(embed_server_url(), 'utf-8'))
            out = out.replace(b'{gui}', bytes(gui_folder_format(), 'utf-8'))
            out = out.replace(b'{lib_core}',
                              bytes(lib_folder_format() % 'core/', 'utf-8'))
            cdmGUI().publishContent(bootPath + ui_demo_embed_file(),
                                    BytesIO(out))
    except:
        log.exception('Error publishing demo client file')
    else:
        assert log.debug(
            'Client demo script published:',
            embed_server_url() +
            getPublishedLib('livedesk-embed/' + ui_demo_embed_file())) or True
Beispiel #17
0
def updateDemoEmbedFile():
    if not publish_gui_resources(): return  # No publishing is allowed
    moduleName, modulePath = __name__, __file__
    for _k in range(0, moduleName.count('.') + 1):
        modulePath = os.path.dirname(modulePath)
    path = os.path.join(modulePath, 'node_modules')

    cdmGUI().publishFromDir('lib/embed/scripts/js/node_modules', path)
    bootPath = lib_folder_format() % 'embed/'
    for file in embed_html_files():
        try:        
            with openURI(getGuiPath(file)) as f:
                out = f.read().replace(b'{server_url}', bytes(embed_server_host(), 'utf-8'))
                out = out.replace(b'{gui}', bytes(gui_folder_format(), 'utf-8'));
                out = out.replace(b'{lib_core}', bytes(lib_folder_format() % 'core/', 'utf-8'));
                cdmGUI().publishContent(bootPath + file, BytesIO(out))
        except:
            log.exception('Error publishing demo client file')
        else:
            assert log.debug('Client demo script published: \'%s\'', embed_server_host() + getPublishedLib('embed/' + file)) or True
Beispiel #18
0
def config():
    assert isinstance(application.options, OptionsMongrel2), 'Invalid application options %s' % application.options
    if not application.options.configMongrel2: return
    workspace = application.options.configMongrel2
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    for name in folders:
        folder = path.join(workspace, name)
        if not path.isdir(folder): makedirs(folder)
    
    configFile = application.options.configurationPath
    if path.isfile(configFile):
        with open(configFile, 'r') as f: config = load(f)
    else:
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option, also change the application properties "server_type" configuration to "mongrel2" '
              'and also adjust the "recv_spec", "send_spec" and "server_port" accordingly' % configFile, file=sys.stderr)
        sys.exit(1)
        
    try:
        context.open(aop.modulesIn('__setup__.**'), config=config)
    
        updateConfig = False
        if server_type() != 'mongrel2':
            updateConfig = True
            support.persist(server_type, 'mongrel2')
        
        sendIdent = send_ident()
        if sendIdent is None:
            updateConfig = True
            sendIdent = str(uuid4())
            support.persist(send_ident, sendIdent)
        
        replace = {}
        try:
            replace['${send_spec}'] = send_spec()
            replace['${send_ident}'] = sendIdent
            replace['${recv_spec}'] = recv_spec()
            replace['${recv_ident}'] = recv_ident()
            replace['${server_port}'] = str(server_port())
        
            if updateConfig:
                if path.isfile(configFile): renames(configFile, configFile + '.bak')
                with open(configFile, 'w') as f: save(context.configurations(force=True), f)
                print('Updated the "%s" configuration file' % configFile)
        finally: context.deactivate()
    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while configuring Mongrel2', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
    else:
        conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
        conf = codecs.getreader('utf8')(conf)
        conf = ReplaceInFile(conf, replace)
        with open(path.join(workspace, 'ally.conf'), 'w') as f: pipe(conf, f)
        with open(path.join(workspace, 'README-Mongrel2.txt'), 'wb') as f:
            pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f)
        
        print('Configured "%s" mongrel2 workspace' % workspace)
Beispiel #19
0
def config():
    assert isinstance(application.options, OptionsMongrel2), 'Invalid application options %s' % application.options
    if not application.options.configMongrel2: return
    workspace = application.options.configMongrel2
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    for name in folders:
        folder = path.join(workspace, name)
        if not path.isdir(folder): makedirs(folder)
    
    configFile = application.options.configurationPath
    if path.isfile(configFile):
        with open(configFile, 'r') as f: config = load(f)
    else:
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option, also change the application properties "server_type" configuration to "mongrel2" '
              'and also adjust the "recv_spec", "send_spec" and "server_port" accordingly' % configFile, file=sys.stderr)
        sys.exit(1)
        
    try:
        context.open(aop.modulesIn('__setup__.**'), config=config)
    
        updateConfig = False
        if server_type() != 'mongrel2':
            updateConfig = True
            support.persist(server_type, 'mongrel2')
        
        sendIdent = send_ident()
        if sendIdent is None:
            updateConfig = True
            sendIdent = str(uuid4())
            support.persist(send_ident, sendIdent)
        
        replace = {}
        try:
            replace['${send_spec}'] = send_spec()
            replace['${send_ident}'] = sendIdent
            replace['${recv_spec}'] = recv_spec()
            replace['${recv_ident}'] = recv_ident()
            replace['${server_port}'] = str(server_port())
        
            if updateConfig:
                if path.isfile(configFile): renames(configFile, configFile + '.bak')
                with open(configFile, 'w') as f: save(context.configurations(force=True), f)
                print('Updated the "%s" configuration file' % configFile)
        finally: context.deactivate()
    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while configuring Mongrel2', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
    else:
        conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
        conf = codecs.getreader('utf8')(conf)
        conf = ReplaceInFile(conf, replace)
        with open(path.join(workspace, 'ally.conf'), 'w') as f: pipe(conf, f)
        with open(path.join(workspace, 'README-Mongrel2.txt'), 'wb') as f:
            pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f)
        
        print('Configured "%s" mongrel2 workspace' % workspace)