def __init__(self, editor_id): gallery_url = get_url_service().expand_url(['gallery']) gallery_dir = get_fs_service().expand_path(['gallery']) self.rte_insert_image = RichTextEditorInsertImageCallback(editor_id) super(Gallery, self).__init__(gallery_url, gallery_dir, self.rte_insert_image.callback_name)
def generate_supervisord_config(mailrelay_user, mailrelay_password): data_dir = filesystem.get_fs_service().data_dir eureka_egg_dir = pkg_resources.get_distribution('eureka').location application_dir = os.path.dirname(os.path.dirname(sys.executable)) with open(os.path.join(eureka_egg_dir, 'contrib/supervisord.conf.template')) as template_file: template = template_file.read() supervisord_conf = template.format(data_dir=data_dir, application_dir=application_dir, eureka_os_egg_dir=eureka_egg_dir, mailrelay_user="******".format(mailrelay_user), mailrelay_password="******".format(mailrelay_password)) return supervisord_conf
def last_board_export(self): board_dir = get_fs_service().expand_path(['board']) if not os.path.exists(board_dir): return None, None zip_files = sorted(glob.glob(os.path.join(board_dir, '*.zip'))) if not zip_files: return None, None last_export_filename = os.path.basename(zip_files[-1]) date_string = os.path.splitext(last_export_filename)[0].split('_')[1] date = datetime.strptime(date_string, '%Y%m%d') url = get_url_service().expand_url(['board', last_export_filename]) return url, date
def generate_restore_backup_script(): """Generates an Apache HTTPD Configuration snippet for your Eureka In: - ``parser`` -- the optparse.OptParser object used to parse the configuration file - ``options`` -- options in the command lines - ``args`` -- arguments in the command lines """ eureka_egg_dir = os.path.dirname(os.path.dirname(eureka.__file__)) app_dir = os.path.dirname(os.path.dirname(sys.executable)) data_dir = filesystem.get_fs_service().data_dir with open(os.path.join(eureka_egg_dir, "contrib", "demo", "restore_snapshot.sh.in")) as template_file: template = template_file.read() script = template.format(app_dir=app_dir, data_dir=data_dir, backup_file=os.path.join(app_dir, 'dumps', 'demo.archive.tgz'), name='eureka') return script
def generate_httpd_config(): """Generates an Apache HTTPD Configuration snippet for your Eureka In: - ``parser`` -- the optparse.OptParser object used to parse the configuration file - ``options`` -- options in the command lines - ``args`` -- arguments in the command lines """ parser = OptionParser(usage='Usage: %prog [options]', description=generate_httpd_config.__doc__) set_options(parser) (__, __) = parser.parse_args() options = parser.values _validate(options) eureka_egg_dir = os.path.dirname(os.path.dirname(eureka.__file__)) data_dir = filesystem.get_fs_service().data_dir with open(os.path.join(eureka_egg_dir, 'contrib/httpd.conf.template')) as template_file: template = template_file.read() httpd_conf = template.format( apache_servername=options.server_name, apache_alias_servername=options.alias_server_name, data_dir=data_dir, fastcgi_host=options.fastcgi_host, fastcgi_port=options.fastcgi_port, nagare_egg_dir=os.path.dirname(nagare.__path__[0]), eureka_os_egg_dir=eureka_egg_dir, ) if not options.alias_server_name: httpd_conf = '\n'.join([ line for line in httpd_conf.splitlines() if 'ServerAlias' not in line ]) return httpd_conf
def generate_httpd_config(): """Generates an Apache HTTPD Configuration snippet for your Eureka In: - ``parser`` -- the optparse.OptParser object used to parse the configuration file - ``options`` -- options in the command lines - ``args`` -- arguments in the command lines """ parser = OptionParser(usage='Usage: %prog [options]', description=generate_httpd_config.__doc__) set_options(parser) (__, __) = parser.parse_args() options = parser.values _validate(options) eureka_egg_dir = os.path.dirname(os.path.dirname(eureka.__file__)) data_dir = filesystem.get_fs_service().data_dir with open(os.path.join(eureka_egg_dir, 'contrib/httpd.conf.template') ) as template_file: template = template_file.read() httpd_conf = template.format( apache_servername=options.server_name, apache_alias_servername=options.alias_server_name, data_dir=data_dir, fastcgi_host=options.fastcgi_host, fastcgi_port=options.fastcgi_port, nagare_egg_dir=os.path.dirname(nagare.__path__[0]), eureka_os_egg_dir=eureka_egg_dir, ) if not options.alias_server_name: httpd_conf = '\n'.join([line for line in httpd_conf.splitlines() if 'ServerAlias' not in line]) return httpd_conf
def generate_build_backup_script(): """Generates an Apache HTTPD Configuration snippet for your Eureka In: - ``parser`` -- the optparse.OptParser object used to parse the configuration file - ``options`` -- options in the command lines - ``args`` -- arguments in the command lines """ eureka_egg_dir = os.path.dirname(os.path.dirname(eureka.__file__)) app_dir = os.path.dirname(os.path.dirname(sys.executable)) data_dir = filesystem.get_fs_service().data_dir with open(os.path.join(eureka_egg_dir, "contrib", "demo", "build_backup.sh.in")) as template_file: template = template_file.read() script = template.format( app_dir=app_dir, data_dir=data_dir, backup_dir=os.path.join(app_dir, 'dumps'), name="eureka") return script fs = filesystem.get_fs_service() # configure the batch environment print(generate_build_backup_script())
def init_shell_static_content(self, url, *args): logger = log.get_logger('.' + __name__) logger.debug('Serving static content: %s' % '/'.join(url)) path = get_fs_service().expand_path(url) serve_static_content(path)
def edit_article(self, id=None, type=None): # handles None being passed as a id for convenience id = -1 if id is None else id # creates the editor editor = ArticleEditor(self, id, type=type, mobile_access=self.mobile_access) # starts edition if self.content.call(editor): # gets the article type article_type = editor.get_type() article_topic = ArticleTopicData.get_by(label=editor.get_topic()) # write the thumbnail down thumbnails_dir = get_fs_service().expand_path( ['articles-thumbnails']) thumbnail = editor.get_thumbnail() thumbnail_filename = None thumbnail_path = None if thumbnail: thumbnail_extension = os.path.splitext( editor.get_thumbnail_filename())[1].lower() os.path.splitext(editor.get_thumbnail_filename())[1].lower() os.path.splitext(editor.get_thumbnail_filename())[1].lower() thumbnail_filename = uuid.uuid4().hex + thumbnail_extension # random filename thumbnail_path = os.path.join(thumbnails_dir, thumbnail_filename) with open(thumbnail_path, 'wb') as target: shutil.copyfileobj(StringIO(thumbnail), target) # creates the article if it does not exist yet article_repository = ArticleRepository() article = article_repository.get_by_id(id) # FIXME: we should save the article in the ArticleEditor, not here if article: if article.thumbnail_filename: if thumbnail: # removes the old thumbnail if a new thumbnail has been uploaded tools.remove_silently(os.path.join(thumbnails_dir, article.thumbnail_filename)) else: # otherwise, keep the old thumbnail thumbnail_filename = article.thumbnail_filename article.type = article_type article.topic = article_topic article.title = editor.get_title() article.thumbnail_filename = thumbnail_filename article.content = editor.get_content() article.mobile_content = editor.get_mobile_content() article.tags = editor.get_tags() else: # FIXME: this algorithm is not scalable. Ranks should be reversed in that case for n in article_repository.get_by_type(article_type): n.rank += 1 article_repository.create(type=article_type, topic=article_topic, title=editor.get_title(), creation_date=datetime.now(), thumbnail_filename=thumbnail_filename, content=editor.get_content(), mobile_content=editor.get_mobile_content(), tags=editor.get_tags(), rank=1, published=False)
def generate_build_backup_script(): """Generates an Apache HTTPD Configuration snippet for your Eureka In: - ``parser`` -- the optparse.OptParser object used to parse the configuration file - ``options`` -- options in the command lines - ``args`` -- arguments in the command lines """ eureka_egg_dir = os.path.dirname(os.path.dirname(eureka.__file__)) app_dir = os.path.dirname(os.path.dirname(sys.executable)) data_dir = filesystem.get_fs_service().data_dir with open( os.path.join(eureka_egg_dir, "contrib", "demo", "build_backup.sh.in")) as template_file: template = template_file.read() script = template.format(app_dir=app_dir, data_dir=data_dir, backup_dir=os.path.join(app_dir, 'dumps'), name="eureka") return script fs = filesystem.get_fs_service() # configure the batch environment print(generate_build_backup_script())
def edit_article(self, id=None, type=None): # handles None being passed as a id for convenience id = -1 if id is None else id # creates the editor editor = ArticleEditor(self, id, type=type, mobile_access=self.mobile_access) # starts edition if self.content.call(editor): # gets the article type article_type = editor.get_type() article_topic = ArticleTopicData.get_by(label=editor.get_topic()) # write the thumbnail down thumbnails_dir = get_fs_service().expand_path( ['articles-thumbnails']) thumbnail = editor.get_thumbnail() thumbnail_filename = None thumbnail_path = None if thumbnail: thumbnail_extension = os.path.splitext( editor.get_thumbnail_filename())[1].lower() os.path.splitext(editor.get_thumbnail_filename())[1].lower() os.path.splitext(editor.get_thumbnail_filename())[1].lower() thumbnail_filename = uuid.uuid4( ).hex + thumbnail_extension # random filename thumbnail_path = os.path.join(thumbnails_dir, thumbnail_filename) with open(thumbnail_path, 'wb') as target: shutil.copyfileobj(StringIO(thumbnail), target) # creates the article if it does not exist yet article_repository = ArticleRepository() article = article_repository.get_by_id(id) # FIXME: we should save the article in the ArticleEditor, not here if article: if article.thumbnail_filename: if thumbnail: # removes the old thumbnail if a new thumbnail has been uploaded tools.remove_silently( os.path.join(thumbnails_dir, article.thumbnail_filename)) else: # otherwise, keep the old thumbnail thumbnail_filename = article.thumbnail_filename article.type = article_type article.topic = article_topic article.title = editor.get_title() article.thumbnail_filename = thumbnail_filename article.content = editor.get_content() article.mobile_content = editor.get_mobile_content() article.tags = editor.get_tags() else: # FIXME: this algorithm is not scalable. Ranks should be reversed in that case for n in article_repository.get_by_type(article_type): n.rank += 1 article_repository.create( type=article_type, topic=article_topic, title=editor.get_title(), creation_date=datetime.now(), thumbnail_filename=thumbnail_filename, content=editor.get_content(), mobile_content=editor.get_mobile_content(), tags=editor.get_tags(), rank=1, published=False)
def _thumbnail_path(format): return get_fs_service().expand_path(['profile-thumbnails', format])
def _photo_path(): return get_fs_service().expand_path(['profile-photo'])