Exemplo n.º 1
0
Arquivo: nomia.py Projeto: nycz/nomia
    def __init__(self, configdir, activation_event, dry_run):
        super().__init__()
        self.setWindowTitle('Nomia')
        if configdir:
            self.configdir = configdir
        else:
            self.configdir = join(getenv('HOME'), '.config', 'nomia')
        activation_event.connect(self.reload_settings)
        self.force_quit_flag = False

        # Create layouts
        self.stack = QtGui.QStackedLayout(self)

        # Index viewer
        self.index_viewer = IndexFrame(self, dry_run, self.configdir)
        self.stack.addWidget(self.index_viewer)

        # Popup viewer
        self.popup_viewer = FileViewer(self)
        self.stack.addWidget(self.popup_viewer)
        self.popuphomekey = QtGui.QShortcut(QtGui.QKeySequence(),
                                            self.popup_viewer,
                                            self.show_index)

        # Load settings
        self.defaultstyle = read_json(local_path('defaultstyle.json'))
        self.css_template = read_file(local_path(join('templates','template.css')))
        self.index_css_template = read_file(local_path(join('templates','index_page.css')))
        self.settings, self.style = {}, {}
        self.reload_settings()
        self.index_viewer.populate_view()

        # Misc
        #self.connect_signals()
        self.show()
Exemplo n.º 2
0
Arquivo: nomia.py Projeto: nycz/nomia
def read_config(configpath, defaultstyle):
    #if configdir:
    #    configpath = configdir
    #else:
    #    configpath = join(getenv('HOME'), '.config', 'nomia')
    configfile = join(configpath, 'settings.json')
    stylefile = join(configpath, 'style.json')
    make_sure_config_exists(configfile, local_path('defaultconfig.json'))
    make_sure_config_exists(stylefile, local_path('defaultstyle.json'))
    # Make sure to update the style with the defaultstyle's values
    newstyle = read_json(stylefile)
    style = defaultstyle.copy()
    style.update({k:v for k,v in newstyle.items() if k in defaultstyle})
    return read_json(configfile), style, stylefile
Exemplo n.º 3
0
def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('mode', choices=['stats', 'todo', 'update'])
    parser.add_argument('entryname',
                        nargs='?',
                        help='part of the name of the fic to update')
    sortalt = ['name', 'cur', 'mean', 'med', 'max', 'min']
    parser.add_argument('-s',
                        '--sort-stats',
                        choices=sortalt,
                        default=sortalt[0])
    parser.add_argument('-r', '--reverse', action='store_true')
    args = parser.parse_args()
    data = read_json(local_path('medusadata.json'))
    if args.mode == 'stats':
        show_stats(data,
                   sortalt.index(args.sort_stats) if args.sort_stats else None,
                   args.reverse)
    elif args.mode == 'todo':
        show_todo(data)
    elif args.mode == 'update':
        if not args.entryname or not args.entryname.strip():
            print('Error: No entry name specified')
            return
        run_update(data, args.entryname)
Exemplo n.º 4
0
def load_html_templates():
    html = namedtuple('HTMLTemplates', 'entry index_page tags progress')
    path = lambda fname: local_path(join('templates', fname))
    return html(read_file(path('entry_template.html')),
                read_file(path('index_page_template.html')),
                read_file(path('tags_template.html')),
                read_file(path('progress_template.html')))
Exemplo n.º 5
0
def load_html_templates():
    path = lambda fname: local_path(join('templates', fname))
    return {
        'entry': read_file(path('entry_template.html')),
        'page': read_file(path('index_page_template.html')),
        'tags': read_file(path('tags_template.html'))
    }
Exemplo n.º 6
0
    def __init__(self, parent):
        super().__init__(parent)
        self.fullscreen = False
        self.setDisabled(True)

        hotkeypairs = (
            ('home', self.goto_index),
            ('toggle fullscreen', self.toggle_fullscreen),
            ('zoom in', self.zoom_in),
            ('zoom out', self.zoom_out),
            ('reset zoom', self.zoom_reset)
        )
        self.hotkeys = {
            key: QtGui.QShortcut(QtGui.QKeySequence(), self, callback)
            for key, callback in hotkeypairs
        }

        self.template = read_file(local_path(join('templates', 'viewer_page_template.html')))
        self.css = "" # Is set every time the config is reloaded
        self.rawtext = ""
        self.formatconverters = []
        self.chapterstrings = []

        # Layout
        layout = QtGui.QVBoxLayout(self)
        kill_theming(layout)

        self.webview = QtWebKit.QWebView(self)
        layout.addWidget(self.webview)
        layout.setStretchFactor(self.webview, 1)
        self.webview.settings().setDefaultTextEncoding('utf-8')

        self.info_panel = InfoPanel(self)
        layout.addWidget(self.info_panel, 0)
Exemplo n.º 7
0
def get_updated_css(stylepath, current_style, css_template):
    """
    Return the style json and the complete css if it is valid and has been
    changed since last update, otherwise return None.

    current_style - a dict with keys to format() the template
    css_template - a format()-ready string that matches current_style
    """
    # Copy in the default theme if a customized doesn't exist
    if not os.path.exists(stylepath):
        defaultcss = common.local_path('defaultstyle.json')
        shutil.copyfile(defaultcss, stylepath)
    try:
        style = common.read_json(stylepath)
    except:
        print('Invalid style config: unable to parse it as json')
        return
    # Only update if something's changed
    if style != current_style:
        try:
            css = css_template.format(**style)
        except KeyError:
            print('Invalid style config: key missing')
            return
        else:
            return style, common.parse_stylesheet(css)
    return
Exemplo n.º 8
0
def get_anime_images(rootdir):
    from urllib.request import urlretrieve
    outdir = local_path('imgcache')
    rx = r'<a href="http://myanimelist.net/anime/\d+/.+?/pics">\s*<img src="(http://.+?)" alt'
    for fname in os.listdir(rootdir):
        rawdata = read_file(os.path.join(rootdir, fname))
        imgurl = re.search(rx, rawdata).group(1)
        urlretrieve(imgurl, os.path.join(outdir, fname + '.jpg'))
Exemplo n.º 9
0
def run_update(data, name):
    try:
        entryname = get_entry_name(data.keys(), name)
    except KeyError:
        print('Error: Can\'t find entry')
    else:
        today = date.today().strftime('%Y-%m-%d')
        data[entryname]['stats'].append(today)
        write_json(local_path('medusadata.json'), data)
        print('Updated today: {}'.format(entryname))
Exemplo n.º 10
0
def save_pages(path, name, pages):
    template = read_file(local_path('pagetemplate.html'))
    for n, page in enumerate(pages):
        controls = gen_controls(name, n, len(pages))
        out = template.format(controls=controls, **page)
        fpath = os.path.join(path, name)
        if len(pages) > 1:
            fpath += ' - Page {:03}'.format(n + 1)
        fpath += '.html'
        write_file(fpath, out)
Exemplo n.º 11
0
def run_update(data, name):
    try:
        entryname = get_entry_name(data.keys(), name)
    except KeyError:
        print('Error: Can\'t find entry')
    else:
        today = date.today().strftime('%Y-%m-%d')
        data[entryname]['stats'].append(today)
        write_json(local_path('medusadata.json'), data)
        print('Updated today: {}'.format(entryname))
Exemplo n.º 12
0
def save_pages(path, name, pages):
    template = read_file(local_path('pagetemplate.html'))
    for n, page in enumerate(pages):
        controls = gen_controls(name, n, len(pages))
        out = template.format(controls=controls, **page)
        fpath = os.path.join(path, name)
        if len(pages) > 1:
            fpath += ' - Page {:03}'.format(n+1)
        fpath += '.html'
        write_file(fpath, out)
Exemplo n.º 13
0
Arquivo: nomia.py Projeto: nycz/nomia
    def reload_settings(self):
        self.defaultstyle = read_json(local_path('defaultstyle.json'))
        self.css_template = read_file(local_path(join('templates','template.css')))
        self.index_css_template = read_file(local_path(join('templates','index_page.css')))

        settings, style, stylepath = read_config(self.configdir, self.defaultstyle)
        # TODO: FIX THIS UGLY ASS SHIT
        # Something somewhere f***s up and changes the settings dict,
        # therefor the deepcopy(). Fix pls.
        #if settings != self.settings:
        if settings['title']:
            self.setWindowTitle(settings['title'])
        else:
            self.setWindowTitle('Nomia')
        self.settings = copy.deepcopy(settings)
        self.index_viewer.update_settings(settings)
        self.popuphomekey.setKey(QtGui.QKeySequence(settings['hotkey home']))
        #if style != self.style:
        self.style = style.copy()
        self.update_style(style)
        write_json(stylepath, style)
Exemplo n.º 14
0
    def __init__(self, configdir):
        super().__init__()
        self.paths = get_paths(configdir)
        for x in ('config_dir', 'plugins', 'spellcheck-pwl'):
            if not exists(self.paths[x]):
                os.makedirs(self.paths[x], mode=0o755, exist_ok=True)
        self.current_style = {}
        self.css_template = common.read_file(common.local_path('template.css'))

        self.default_config = get_default_config()
        self.auto_setting_acronyms = get_auto_setting_acronym(self.default_config)
        self.setting_types = get_setting_types(self.default_config)
        self.setting_callbacks = defaultdict(list)

        self.auto_settings, self.manual_settings = {}, {}
        self.settings = ChainMap()
Exemplo n.º 15
0
def get_paths(custom_config_dir):
    import platform
    # Paths init
    if custom_config_dir and os.path.isdir(custom_config_dir):
        config_dir = custom_config_dir
    elif platform.system() == 'Linux':
        config_dir = join(os.getenv('HOME'), '.config', 'kalpana')
    else: # Windows
        config_dir = common.local_path('')
    path = lambda fname: join(config_dir, fname)

    return {
        'config_dir':   config_dir,
        'config_file':  path('kalpana.conf'),
        'style':        path('style.conf'),
        'loadorder':    path('loadorder.conf'),
        'plugins':      path('plugins'),
        'spellcheck-pwl': path('spellcheck-pwl')
    }
Exemplo n.º 16
0
def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('mode', choices=['stats', 'todo', 'update'])
    parser.add_argument('entryname', nargs='?',
                        help='part of the name of the fic to update')
    sortalt = ['name', 'cur', 'mean', 'med', 'max', 'min']
    parser.add_argument('-s', '--sort-stats', choices=sortalt, default=sortalt[0])
    parser.add_argument('-r', '--reverse', action='store_true')
    args = parser.parse_args()
    data = read_json(local_path('medusadata.json'))
    if args.mode == 'stats':
        show_stats(data, sortalt.index(args.sort_stats) if args.sort_stats else None,
                   args.reverse)
    elif args.mode == 'todo':
        show_todo(data)
    elif args.mode == 'update':
        if not args.entryname or not args.entryname.strip():
            print('Error: No entry name specified')
            return
        run_update(data, args.entryname)
Exemplo n.º 17
0
def get_default_config():
    return common.read_json(common.local_path('defaultconfig.json'))
Exemplo n.º 18
0
def main():
    template = read_json(os.path.join(local_path('templates'), 'defaultentry-meta.json'))
    malanimelist = ET.parse(local_path('animelist-2016-05-26.xml'))
    htmldata = extract_html_data(local_path('malanimetempcache'))
    entries = parse_animelist_xml(malanimelist.getroot(), htmldata, template)
    write_json(local_path('animelisttest.json'), entries)
Exemplo n.º 19
0
Arquivo: urd.py Projeto: cefyr/urd
def read_config():
    config_file = os.path.join(os.getenv('HOME'), '.config', 'urd', 'urd.conf')
    common.make_sure_config_exists(config_file,
                                   common.local_path('default_config.json'))
    return common.read_json(config_file)
Exemplo n.º 20
0
Arquivo: urd.py Projeto: nycz/urd
def read_config():
    config_file = os.path.join(os.getenv("HOME"), ".config", "urd", "urd.conf")
    common.make_sure_config_exists(config_file, common.local_path("default_config.json"))
    return common.read_json(config_file)
Exemplo n.º 21
0
def load_settings():
    config_file = os.path.join(os.getenv('HOME'), '.config', 'sapfo-dl',
                               'settings.json')
    make_sure_config_exists(config_file, local_path('default_settings.json'))
    return read_json(os.path.join(config_file))
Exemplo n.º 22
0
 def cmd_show_readme(self, arg):
     self.show_readme.emit('', local_path('README.md'), None, 'markdown')
Exemplo n.º 23
0
def load_settings():
    config_file = os.path.join(os.getenv('HOME'), '.config', 'sapfo-dl', 'settings.json')
    make_sure_config_exists(config_file, local_path('default_settings.json'))
    return read_json(os.path.join(config_file))