コード例 #1
0
ファイル: worker.py プロジェクト: poliorcetics/ffn-downloader
    def update_infos(self, dic: dict):
        """
        Update the informations for each story in each path provided.

        Args:
            dic (dict): the dictionnary containing the paths as key and the
                        list of stories as value. Example:
                           {
                               '/Users/user/foo': [
                                   'url_1',
                                   'url_2',
                               ],
                               '/Users/user/bar': [
                                   'url_3',
                                   'url_4',
                               ],
                           }

        N.B:
            - Even if the path isn't a full path, the M_PATH variable is used
            to complete it.
        """

        paths = sorted(dic.keys())

        for path in paths:
            tls.chdir(self._get_full_path(path))

            urls = tls.get_urls_from_folder(os.getcwd())
            writer = story.StoryWriter()

            for url in urls:
                st = story.Story(url)
                writer.update_infos(st)
                del st
コード例 #2
0
ファイル: worker.py プロジェクト: poliorcetics/ffn-downloader
    def update_stories(self, dic: dict):
        """
        Update multiple stories in differents paths or not.

        Args:
            dic (dict): the dictionnary containing the paths as key and the
                        list of stories as value. Example:
                           {
                               '/Users/user/foo': [
                                   'url_1',
                                   'url_2',
                               ],
                               '/Users/user/bar': [
                                   'url_3',
                                   'url_4',
                               ],
                           }

        N.B:
            - Even if the path isn't a full path, the M_PATH variable is used
            to complete it.
            - Update the stats of the differents paths, but not the main stats
            because if not all paths were given, those missing will not be
            accounted for.
        """

        paths = sorted(dic.keys())
        updated_stories = {}

        for path in paths:
            tls.chdir(self._get_full_path(path))
            urls = dic[path]

            updated_stories[path] = []

            for url in urls:
                result = m.main(url, True)
                # If the story was in need of an update, its url is saved
                if result == 0:
                    updated_stories[path].append(url)

        self.update_stats(paths, False, False)

        # Print the updated stories, by folder
        for path in updated_stories.keys():
            if updated_stories[path] != []:
                print(f'\n\nStories updated in: {path}\n')
                for url in updated_stories[path]:
                    print(f'     - {url}')
コード例 #3
0
ファイル: stats.py プロジェクト: poliorcetics/ffn-downloader
    def _del_old_stats_file(path: str):
        """
        Deletes all old stats file in a given directory.

        Args:
            path (str): the path to work with.
        """
        base_path = os.getcwd()
        tls.chdir(path, False)

        for file in os.listdir():
            if re.fullmatch(c.STATS_FILE_REGEX, file) is not None:
                os.remove(file)

        os.chdir(base_path)
コード例 #4
0
ファイル: worker.py プロジェクト: poliorcetics/ffn-downloader
    def update_infos_in_paths(self, paths: list):
        """
        Update the informations of all the stories contained in all the *dirs*.

        Args:
            paths (list): the pathes containing the stories.
        """

        for path in paths:
            tls.chdir(self._get_full_path(path))

            urls = tls.get_urls_from_folder(os.getcwd())
            writer = story.StoryWriter()

            for url in urls:
                st = story.Story(url)
                writer.update_infos(st)
                del st
コード例 #5
0
ファイル: test_mako.py プロジェクト: zcodes/bottle
 def test_inherit(self):
     """ Templates: Mako lookup and inherience """
     with chdir(__file__):
         t = MakoTemplate(name="mako_inherit", lookup=["./views/"]).render(var="v")
         self.assertEqual("o\ncvc\no\n", t)
         t = MakoTemplate('<%inherit file="mako_base.tpl"/>\nc${var}c\n', lookup=["./views/"]).render(var="v")
         self.assertEqual("o\ncvc\no\n", t)
         t = MakoTemplate('<%inherit file="views/mako_base.tpl"/>\nc${var}c\n', lookup=["./"]).render(var="v")
         self.assertEqual("o\ncvc\no\n", t)
コード例 #6
0
 def test_view(self):
     """ WSGI: Test view-decorator (should override autojson) """
     with chdir(__file__):
         @bottle.route('/tpl')
         @bottle.view('stpl_t2main')
         def test():
             return dict(content='1234')
         result = '+base+\n+main+\n!1234!\n+include+\n-main-\n+include+\n-base-\n'
         self.assertHeader('Content-Type', 'text/html; charset=UTF-8', '/tpl')
         self.assertBody(result, '/tpl')
コード例 #7
0
ファイル: test_stpl.py プロジェクト: myzhan/bottle
 def test_view_decorator_issue_407(self):
     with chdir(__file__):
         @view('stpl_no_vars')
         def test():
             pass
         self.assertEqual(touni('hihi'), test())
         @view('aaa {{x}}', x='bbb')
         def test2():
             pass
         self.assertEqual(touni('aaa bbb'), test2())
コード例 #8
0
 def test_inherit(self):
     """ Templates: Mako lookup and inherience """
     with chdir(__file__):
         t = MakoTemplate(name='mako_inherit',
                          lookup=['./views/']).render(var='v')
         self.assertEqual('o\ncvc\no\n', t)
         t = MakoTemplate('<%inherit file="mako_base.tpl"/>\nc${var}c\n',
                          lookup=['./views/']).render(var='v')
         self.assertEqual('o\ncvc\no\n', t)
         t = MakoTemplate(
             '<%inherit file="views/mako_base.tpl"/>\nc${var}c\n',
             lookup=['./']).render(var='v')
         self.assertEqual('o\ncvc\no\n', t)
コード例 #9
0
ファイル: test_stpl.py プロジェクト: sydneybrokeit/dotfiles
    def test_view_decorator_issue_407(self):
        with chdir(__file__):

            @view('stpl_no_vars')
            def test():
                pass

            self.assertEqual(touni('hihi'), test())

            @view('aaa {{x}}', x='bbb')
            def test2():
                pass

            self.assertEqual(touni('aaa bbb'), test2())
コード例 #10
0
ファイル: worker.py プロジェクト: poliorcetics/ffn-downloader
    def new_stories(self, dic: dict):
        """
        Download multiple stories in differents paths or not.

        Args:
            dic (dict): the dictionnary containing the paths as key and the
                        list of stories as value. Example:
                           {
                               '/Users/user/foo': [
                                   'url_1',
                                   'url_2',
                               ],
                               '/Users/user/bar': [
                                   'url_3',
                                   'url_4',
                               ],
                           }

        N.B:
            - Even if the path isn't a full path, the M_PATH variable is used
            to complete it.
            - Update the stats of the differents paths, but not the main stats
            because if not all paths were given, those missing will not be
            accounted for.
        """

        paths = sorted(dic.keys())

        for path in paths:
            tls.chdir(self._get_full_path(path))
            urls = dic[path]

            for url in urls:
                m.main(url)

        self.update_stats(paths, False, False)
コード例 #11
0
ファイル: test_stpl.py プロジェクト: myzhan/bottle
 def test_rebase(self):
     """ Templates: %rebase and method passing """
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_t2main', lookup=['./views/'])
         result='+base+\n+main+\n!1234!\n+include+\n-main-\n+include+\n-base-\n'
         self.assertRenders(t, result, content='1234')
コード例 #12
0
ファイル: test_mako.py プロジェクト: zcodes/bottle
 def test_file(self):
     """ Templates: Mako file"""
     with chdir(__file__):
         t = MakoTemplate(name="./views/mako_simple.tpl").render(var="var")
         self.assertEqual("start var end\n", t)
コード例 #13
0
ファイル: test_jinja2.py プロジェクト: zxypetre/bottle
 def test_name(self):
     """ Templates: Jinja2 lookup by name """
     with chdir(__file__):
         t = Jinja2Template(name='jinja2_simple',
                            lookup=['./views/']).render(var='var')
         self.assertEqual('start var end', ''.join(t))
コード例 #14
0
ファイル: test_stpl.py プロジェクト: myzhan/bottle
 def test_include(self):
     """ Templates: Include statements"""
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_include', lookup=['./views/'])
         self.assertRenders(t, 'before\nstart var end\nafter\n', var='var')
コード例 #15
0
 def test_file(self):
     """ Templates: Mako file"""
     with chdir(__file__):
         t = MakoTemplate(name='./views/mako_simple.tpl').render(var='var')
         self.assertEqual('start var end\n', t)
コード例 #16
0
 def test_name(self):
     """ Templates: Mako lookup by name """
     with chdir(__file__):
         t = MakoTemplate(name='mako_simple',
                          lookup=['./views/']).render(var='var')
         self.assertEqual('start var end\n', t)
コード例 #17
0
ファイル: test_mako.py プロジェクト: zcodes/bottle
 def test_name(self):
     """ Templates: Mako lookup by name """
     with chdir(__file__):
         t = MakoTemplate(name="mako_simple", lookup=["./views/"]).render(var="var")
         self.assertEqual("start var end\n", t)
コード例 #18
0
ファイル: test_jinja2.py プロジェクト: sideffect0/bottle
 def test_inherit(self):
     """ Templates: Jinja2 lookup and inherience """
     with chdir(__file__):
         t = Jinja2Template(name='jinja2_inherit', lookup=['./views/']).render()
         self.assertEqual('begin abc end', ''.join(t))
コード例 #19
0
ファイル: test_stpl.py プロジェクト: myzhan/bottle
 def test_file(self):
     with chdir(__file__):
         t = SimpleTemplate(name='./views/stpl_simple.tpl')
         self.assertRenders(t, 'start var end\n', var='var')
コード例 #20
0
ファイル: test_stpl.py プロジェクト: myzhan/bottle
 def test_unicode_code(self):
     """ Templates: utf8 code in file"""
     with chdir(__file__):
         t = SimpleTemplate(name='./views/stpl_unicode.tpl')
         self.assertRenders(t, 'start ñç äöü end\n', var=touni('äöü'))
コード例 #21
0
ファイル: test_stpl.py プロジェクト: sydneybrokeit/dotfiles
 def test_unicode_code(self):
     """ Templates: utf8 code in file"""
     with chdir(__file__):
         t = SimpleTemplate(name='./views/stpl_unicode.tpl', lookup=['.'])
         self.assertRenders(t, 'start ñç äöü end\n', var=touni('äöü'))
コード例 #22
0
ファイル: test_stpl.py プロジェクト: sydneybrokeit/dotfiles
 def test_name(self):
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_simple', lookup=['./views/'])
         self.assertRenders(t, 'start var end\n', var='var')
コード例 #23
0
ファイル: test_jinja2.py プロジェクト: zxypetre/bottle
 def test_inherit(self):
     """ Templates: Jinja2 lookup and inherience """
     with chdir(__file__):
         t = Jinja2Template(name='jinja2_inherit',
                            lookup=['./views/']).render()
         self.assertEqual('begin abc end', ''.join(t))
コード例 #24
0
ファイル: test_stpl.py プロジェクト: sydneybrokeit/dotfiles
 def test_rebase(self):
     """ Templates: %rebase and method passing """
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_t2main', lookup=['./views/'])
         result = '+base+\n+main+\n!1234!\n+include+\n-main-\n+include+\n-base-\n'
         self.assertRenders(t, result, content='1234')
コード例 #25
0
ファイル: test_stpl.py プロジェクト: sydneybrokeit/dotfiles
 def test_include(self):
     """ Templates: Include statements"""
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_include', lookup=['./views/'])
         self.assertRenders(t, 'before\nstart var end\nafter\n', var='var')
コード例 #26
0
ファイル: test_stpl.py プロジェクト: myzhan/bottle
 def test_name(self):
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_simple', lookup=['./views/'])
         self.assertRenders(t, 'start var end\n', var='var')
コード例 #27
0
ファイル: __init__.py プロジェクト: rsedlr/galsrecipes
from glob import glob
from tools import chdir
import unittest
import sys, os

try:
    import coverage
    coverage.process_startup()
except ImportError:
    pass

if 'fast' in sys.argv:
    sys.stderr.write("Warning: The 'fast' keyword skipps server tests.\n")
    os.environ["TEST_FAST"] = "true"

suite = None
if sys.version_info[:2] in ((2, 5), (2, 6), (3, 1)):
    with chdir(__file__):
        suite = unittest.defaultTestLoader.loadTestsFromNames(
            [n[:-3] for n in glob('test_*.py')])
else:
    suite = unittest.defaultTestLoader.discover(__name__)


def main():
    import bottle
    bottle.debug(True)
    vlevel = 2 if 'verbose' in sys.argv else 0
    result = unittest.TextTestRunner(verbosity=vlevel).run(suite)
    sys.exit((result.errors or result.failures) and 1 or 0)
コード例 #28
0
ファイル: stats.py プロジェクト: poliorcetics/ffn-downloader
    def _get_path(path: str, display=True) -> (dict, dict, tuple):
        """
        Returns the components of the stats for a given directory (*path*)

        Args:
            path (str): The path in which the stats will be taken.
            display[True] (bool): Indicates if messages are printed on stdout.

        Returns:
            In the following order:
            - url_ifs (dict): Associate the infos of stories to their url.
                              The keys are (for each url):
                              - c_count: Chapters count.
                              - status: 'Complete' or 'In Progress'.
                              - path_infos: Path to the informations.
                              - smry: Summary.
                              - title: Title.
                              - uni: Universe.
                              - url: Url.
                              - w_count: Words count.
                              - ratio: Ration (Words count // Chapters count).
                              - auth: Author.
                              - tk: Tokens.
            universes (dict): Associates the number of stories for a universe
                              to this universe.
            counts (tuple): contains the numbers of (in the following order):
                            - stories (int)
                            - chapters (int)
                            - words (int)
                            - universes (int)
                            All these numbers are the totals for the directory,
                            not those of a particular story.
        """
        tls.chdir(path, display)

        urls = tls.get_urls_from_folder(path)
        s_count = len(urls)

        urls_ifs = dict()
        universes = dict()

        for i in range(s_count):

            url = urls[i]
            text_id = url.split('/')[6]
            num_id = url.split('/')[4]
            raw_infos_file = f'{text_id}_{num_id}{os.sep}.{num_id}'

            with open(raw_infos_file, 'r', encoding='utf-8') as f:
                lines = [l.rstrip('\n') for l in f.readlines()]

            urls_ifs[url] = {
                'c_count': int(lines[0]),
                'status': lines[1],
                'path_infos': lines[2],
                'smry': lines[3],
                'title': lines[4],
                'uni': lines[5],
                'url': lines[6],
                'w_count': int(lines[7]),
                'ratio': int(lines[7]) // int(lines[0]),
                'auth': lines[8],
                'tk': lines[9]
            }

            try:
                universes[lines[5]] += 1
            except KeyError:
                universes[lines[5]] = 1

            if display:
                print(f'REGISTERED -- {lines[4]:70}'
                      f'{str(i + 1).zfill(len(str(s_count)))} / {s_count}')

        counts = (s_count,
                  sum(int(urls_ifs[url]['c_count']) for url in urls_ifs),
                  sum(int(urls_ifs[url]['w_count']) for url in urls_ifs),
                  len(universes))

        return urls_ifs, universes, counts
コード例 #29
0
 def test_file(self):
     with chdir(__file__):
         t = SimpleTemplate(name='./views/stpl_simple.tpl')
         self.assertRenders(t, 'start var end\n', var='var')
コード例 #30
0
ファイル: __init__.py プロジェクト: 326029212/bottle
from glob import glob
from tools import chdir
import unittest
import sys, os

try:
    import coverage
    coverage.process_startup()
except ImportError:
    pass


if 'fast' in sys.argv:
    sys.stderr.write("Warning: The 'fast' keyword skipps server tests.\n")
    os.environ["TEST_FAST"] = "true"

suite = None
if sys.version_info[:2] in ((2,5), (2,6), (3,1)):
    with chdir(__file__):
        suite = unittest.defaultTestLoader.loadTestsFromNames([n[:-3] for n in glob('test_*.py')])
else:
    suite = unittest.defaultTestLoader.discover(__name__)

def main():
    import bottle
    bottle.debug(True)
    vlevel = 2 if 'verbose' in sys.argv else 0
    result = unittest.TextTestRunner(verbosity=vlevel).run(suite)
    sys.exit((result.errors or result.failures) and 1 or 0)

コード例 #31
0
ファイル: test_jinja2.py プロジェクト: sideffect0/bottle
 def test_name(self):
     """ Templates: Jinja2 lookup by name """
     with chdir(__file__):
         t = Jinja2Template(name='jinja2_simple', lookup=['./views/']).render(var='var')
         self.assertEqual('start var end', ''.join(t))