Esempio n. 1
0
    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
Esempio n. 2
0
    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}')
Esempio n. 3
0
    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)
Esempio n. 4
0
    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
Esempio n. 5
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)
Esempio n. 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')
Esempio n. 7
0
 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())
Esempio n. 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)
Esempio n. 9
0
    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())
Esempio n. 10
0
    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)
Esempio n. 11
0
 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')
Esempio n. 12
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)
Esempio n. 13
0
 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))
Esempio n. 14
0
 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')
Esempio n. 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)
Esempio n. 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)
Esempio n. 17
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)
Esempio n. 18
0
 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))
Esempio n. 19
0
 def test_file(self):
     with chdir(__file__):
         t = SimpleTemplate(name='./views/stpl_simple.tpl')
         self.assertRenders(t, 'start var end\n', var='var')
Esempio n. 20
0
 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('äöü'))
Esempio n. 21
0
 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('äöü'))
Esempio n. 22
0
 def test_name(self):
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_simple', lookup=['./views/'])
         self.assertRenders(t, 'start var end\n', var='var')
Esempio n. 23
0
 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))
Esempio n. 24
0
 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')
Esempio n. 25
0
 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')
Esempio n. 26
0
 def test_name(self):
     with chdir(__file__):
         t = SimpleTemplate(name='stpl_simple', lookup=['./views/'])
         self.assertRenders(t, 'start var end\n', var='var')
Esempio n. 27
0
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)
Esempio n. 28
0
    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
Esempio n. 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')
Esempio n. 30
0
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)

Esempio n. 31
0
 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))