예제 #1
0
 def ischanged(self, filepath, update=True):
     # Get local references
     cache = self._cache
     self._last = last = os_path_abspath(filepath)
     checksum = self._hash(last, self.BLOCK_SIZE)
     # If file didn't change
     if cache.get(last, -1.0) == checksum:
         return False
     # If file changed
     try:
         self._lcache[last] = checksum
     except AttributeError:
         self._cache[last] = checksum
     return True
예제 #2
0
파일: check.py 프로젝트: matt-hayden/cutils
 def ischanged(self, filepath, update=True):
     # Get local references
     cache = self._cache
     self._last = last = os_path_abspath(filepath)
     checksum = self._hash(last, self.BLOCK_SIZE)
     # If file didn't change
     if cache.get(last, -1.0) == checksum:
         return False
     # If file changed
     try:
         self._lcache[last] = checksum
     except AttributeError:
         self._cache[last] = checksum
     return True
예제 #3
0
def init_directory(bad_urls_dir, tei_logger):
    """Initialise bad_urls_dir:
       1. Resolve path (absolute or relative to the working directory)
       2. Check if not exists and create it (warn if exists)
       3. Check if bad_urls_dir is a directory (fail gracefully if it is other than directory)
       4. Check if bad_urls_dir empty (warn if not)
    """
    if not os_path_isabs(bad_urls_dir):
        bad_urls_dir = os_path_join(os_path_abspath(getcwd()), bad_urls_dir)
    if os_path_exists(bad_urls_dir):
        tei_logger.log('WARNING', f'{bad_urls_dir} exists!')
    else:
        makedirs(bad_urls_dir, exist_ok=True)
    if not os_path_isdir(bad_urls_dir):
        tei_logger.log('CRITICAL', f'{bad_urls_dir} is not a directory!')
        exit(1)
    if len(listdir(bad_urls_dir)) > 0:
        tei_logger.log('WARNING', f'{bad_urls_dir} is not empty!')
    return bad_urls_dir
예제 #4
0

def decompose_spec(article_dec):
    decompose_listed_subtrees_and_mark_media_descendants(article_dec, DECOMP, MEDIA_LIST)
    for c in article_dec.children:
        if isinstance(c, Tag) and c.name == 'h2':
            c.decompose()
    publi = article_dec.find('div', class_='head')
    if publi is not None and publi.find('h3') is not None:
        publi.decompose()
    return article_dec


LINK_FILTER_SUBSTRINGS_SPEC = re.compile('|'.join(['LINK_FILTER_DUMMY_STRING']))

BLACKLIST_SPEC = [url.strip() for url in
                  open(os_path_join(os_path_dirname(os_path_abspath(__file__)), 'valasz_BLACKLIST.txt')).readlines()]

MULTIPAGE_URL_END = re.compile(r'.*?page=.')


def next_page_of_article_spec(curr_html):
    bs = BeautifulSoup(curr_html, 'lxml')
    if bs.find('article', class_='percro-percre-lista') is not None:
        next_tag = bs.find('a', rel='next')
        if next_tag is not None and 'href' in next_tag.attrs.keys():
            next_link = next_tag.attrs['href']
            link = f'http://valasz.hu{next_link}'
            return link
    return None
예제 #5
0
from typing import List, TextIO, Tuple
from unittest import TestCase, main as unittest_main
from os import (pardir as os_pardir, mkdir as os_mkdir, remove as os_remove)
from os.path import (join as os_path_join, dirname as os_path_dirname, abspath
                     as os_path_abspath, exists as os_path_exists)
from sys import path as sys_path
from shutil import rmtree as shutil_rmtree

sys_path.append(
    os_path_join(os_path_dirname(os_path_abspath(__file__)), os_pardir))

from cvs.changes_codec import (ChangesCodec, ProgramDataFormatError,
                               CodecException)


class GetLastCommitNumber(TestCase):
    _changes_codec: ChangesCodec = ChangesCodec()

    def setUp(self) -> None:
        os_mkdir(self._changes_codec._CVS_DIR_PATH)
        os_mkdir(self._changes_codec._COMMITTED_PATH)

    def tearDown(self) -> None:
        if os_path_exists(self._changes_codec._CVS_DIR_PATH):
            shutil_rmtree(self._changes_codec._CVS_DIR_PATH)

    def test_no_commits(self):
        self.assertEqual(self._changes_codec._get_last_commit_number(), 0)

    def test_only_commit_files(self):
        self._create_files_in_committed_dir(['3', '5', '7'])
# -*- coding: utf-8 -*-
import os
from datetime import timedelta
from os.path import abspath as os_path_abspath
from os.path import dirname as os_path_dirname
from os.path import join as os_path_join

current_dir = os_path_abspath(os_path_dirname(__file__))

# BASIC
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os_path_join(current_dir, '../',
                                                      'data.sqlite')
USE_TOKEN_AUTH = True

# EMAIL
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 465
MAIL_USE_TLS = False
MAIL_USE_SSL = True
MAIL_USERNAME = os.getenv('GMAIL_USERNAME')
MAIL_PASSWORD = os.getenv('GMAIL_PASSWORD')

# SECURITY
SECRET_KEY = os.getenv('SECRET_KEY') or 'secret_secret_secret'
SECURITY_REGISTERABLE = True
SECURITY_REGISTER_URL = '/auth/register'
SECURITY_PASSWORD_HASH = os.getenv('SECURITY_PASSWORD_HASH') or 'sha512_crypt'
SECURITY_PASSWORD_SALT = os.getenv(
    'SECURITY_PASSWORD_SALT') or 'salt_salt_salt'
JWT_EXPIRATION_DELTA = timedelta(days=10)
예제 #7
0
from unittest import TestCase, main as unittest_main
from os import pardir as os_pardir, remove as os_remove
from os.path import (join as os_path_join, dirname as os_path_dirname, abspath
                     as os_path_abspath, exists as os_path_exists)
from typing import List
from sys import path as sys_path
from urllib.request import urlopen
from shutil import copyfileobj as shutil_copyfileobj

sys_path.append(
    os_path_join(os_path_dirname(os_path_abspath(__file__)), os_pardir))

from vorbis.decoders import (DataReader, SetupHeaderDecoder,
                             EndOfPacketException)
from vorbis.helper_funcs import float32_unpack

TEST_FILE_1_PATH = os_path_join(os_path_dirname(os_path_abspath(__file__)),
                                'test_audiofiles', 'test_1.ogg')

TEST_FILE_1_URL: str = (
    r'https://raw.githubusercontent.com/susimus/ogg_vorbis/master/'
    r'tests/test_audiofiles/test_1.ogg')

test_file_1_was_downloaded: bool = False


# noinspection PyPep8Naming
def setUpModule():
    global TEST_FILE_1_PATH

    if not os_path_exists(TEST_FILE_1_PATH):
예제 #8
0
from unittest import TestCase, main as unittest_main
from os import pardir as os_pardir, remove as os_remove
from os.path import (join as os_path_join, dirname as os_path_dirname, abspath
                     as os_path_abspath, exists as os_path_exists)
from sys import path as sys_path
from urllib.request import urlopen
from shutil import copyfileobj as shutil_copyfileobj

sys_path.append(
    os_path_join(os_path_dirname(os_path_abspath(__file__)), os_pardir))

from vorbis.vorbis_main import PacketsProcessor, CorruptedFileDataError

TEST_FILE_1_PATH = os_path_join(os_path_dirname(os_path_abspath(__file__)),
                                'test_audiofiles', 'test_1.ogg')

TEST_FILE_NOT_OGG_PATH = os_path_join(
    os_path_dirname(os_path_abspath(__file__)), 'test_audiofiles',
    'test_wrong_ogg_file.ogg')

TEST_FILE_NOT_VORBIS_PATH = os_path_join(
    os_path_dirname(os_path_abspath(__file__)), 'test_audiofiles',
    'test_wrong_vorbis_file.ogg')

TEST_FILE_NOT_OGG_URL: str = (
    r'https://raw.githubusercontent.com/susimus/ogg_vorbis/master/tests'
    r'/test_audiofiles/test_wrong_ogg_file.ogg')

TEST_FILE_NOT_VORBIS_URL: str = (
    r'https://raw.githubusercontent.com/susimus/ogg_vorbis/master/tests'
    r'/test_audiofiles/test_wrong_vorbis_file.ogg')
예제 #9
0
from unittest import TestCase, main as unittest_main
from os import pardir as os_pardir
from os.path import (
    join as os_path_join,
    dirname as os_path_dirname,
    abspath as os_path_abspath)
from sys import path as sys_path

sys_path.append(os_path_join(
    os_path_dirname(os_path_abspath(__file__)),
    os_pardir))

from vorbis.helper_funcs import (
    ilog, float32_unpack, lookup1_values, bit_reverse)
from .test_decoders import hex_str_to_bin_str


# noinspection PyMethodMayBeStatic
class HelperFunctionsTests(TestCase):
    def test_ilog_zero(self):
        self.assertEqual(ilog(0), 0)

    def test_ilog_positive_number(self):
        self.assertEqual(ilog(1), 1)
        self.assertEqual(ilog(7), 3)

    def test_ilog_negative_number(self):
        self.assertEqual(ilog(-1111), 0)
        self.assertEqual(ilog(-112312), 0)

    def test_lookup1_values(self):
예제 #10
0
          (('div',), {'class': 'nm_supported__wrapper'}),
          ]
# <div class=miniapp socialbox id=@STYLE>
MEDIA_LIST = []


def decompose_spec(article_dec):
    decompose_listed_subtrees_and_mark_media_descendants(article_dec, DECOMP, MEDIA_LIST)
    # 'mindeközben' titles
    if article_dec.find('div', class_='mindenkozben_post_content content'):
        article_dec.find('h3', class_='title').decompose()
    return article_dec


BLACKLIST_SPEC = [url.strip() for url in
                  open(os_path_join(os_path_dirname(os_path_abspath(__file__)), 'index_koronavirus_BLACKLIST.txt')).readlines()] + \
                 [url.strip() for url in
                  open(os_path_join(os_path_dirname(os_path_abspath(__file__)), 'index_BLACKLIST.txt')).readlines()]

LINK_FILTER_SUBSTRINGS_SPEC = re.compile('|'.join(['LINK_FILTER_DUMMY_STRING']))

MULTIPAGE_URL_END = re.compile(r'^\b$')  # (r'.*/\?p=.*')
# https://index.hu/belfold/2020/02/29/eloben_kozvetitjuk_az_eddigi_legnagyobb_magyar_lottonyeremeny_kihuzasa/?p=1


def next_page_of_article_spec(curr_html):
    """    bs = BeautifulSoup(curr_html, 'lxml')
        pages = bs.find('div', class_='pagination clearfix')
        if pages is not None:
            for p in pages.find_all('a', class_='next'):
                if 'rel' not in p.attrs.keys():
예제 #11
0
from os.path import (split as os_path_split, abspath as os_path_abspath)
from sys import path as sys_path

ui_folder_path, _ = os_path_split(os_path_abspath(__file__))

ogg_vorbis_root, _ = os_path_split(ui_folder_path)

sys_path.append(ogg_vorbis_root)
예제 #12
0
                   ClickChoice)
from PyInstaller.__main__ import run as run_pyinstaller

# To get the correct separator for the OS
OS_NAME = platform_system()

if OS_NAME == 'Windows':
    SEPARATOR = ';'
elif OS_NAME == 'Linux':
    SEPARATOR = ':'

# To get the correct version number for each executable
VERSION = get_pkg_distribution('adonis_lifestyle_tracker').version

# To get all the correct paths for each required file
GUI_PATH = os_path_join(os_path_abspath('.'), 'adonis_lifestyle_tracker')
WORK_PATH = os_path_join(os_path_abspath('.'), 'build')
DIST_PATH = os_path_join(os_path_abspath('.'), 'dist')
SPEC_PATH = os_path_join(os_path_abspath('.'), 'spec')
LICENSE_PATH = os_path_join(os_path_abspath('.'), f'LICENSE.txt{SEPARATOR}.')
ICON_PATH = os_path_join(os_path_abspath('.'),
                         f'adonis_lifestyle_tracker_logo.ico')
DB_PATH = os_path_join(os_path_abspath('.'), 'adonis_lifestyle_tracker',
                       f'app.db{SEPARATOR}.')


@click_command()
def create_executable():
    run_pyinstaller([
        '--name=%s' % 'adonis_lifestyle_tracker',
        '--noconsole',
예제 #13
0
def run_launcher_logic():
    parser = ArgumentParser(
        description='Videogame-platformer where squares fight for the win!')

    parser.add_argument('--version',
                        help="print program's current version number and exit",
                        action='version',
                        version=get_current_version())

    parser.add_argument('-d',
                        '--debug',
                        help="turn on debug info printing",
                        action='store_true')

    arguments: Namespace = parser.parse_args()

    # Improvement: make GUI version of launcher. For now launcher just loads
    #  some map

    map_name: str = input(
        'Enter map name. Raw maps names have format: "raw <name>". Non raw '
        'maps will be loaded from "maps" folder.\n')

    game_map: Optional[GameMap] = None

    if map_name.startswith('raw '):
        try:
            game_map = getattr(RawMapsContainer,
                               'get_map_' + map_name.split(' ')[1])()

        except AttributeError:
            exit_with_exception(
                'Wrong raw map name',
                LauncherException('Wrong raw map name: ' + map_name),
                arguments.debug)
    else:
        try:
            map_path: str = os_path_join(
                os_path_dirname(os_path_abspath(__file__)), os_pardir, 'maps',
                map_name)

            with open(map_path, 'rb') as map_file_handle:
                game_map = pickle_load(map_file_handle)

        except OSError as occurred_err:
            exit_with_exception('Cannot open file: ' + map_name,
                                LauncherException(*occurred_err.args),
                                arguments.debug)

    if game_map is None:
        exit_with_exception("Something broke inside game",
                            ApplicationException('[game_map] is [None]'),
                            arguments.debug)

    game_engine: GameEngine = GameEngine(game_map)
    gui: GameGUI = GameGUI()

    try:
        gui.init(game_map, game_engine.get_event_listeners())

        def game_loop(game_engine_: GameEngine, gui_: GameGUI):
            def time_alignment():
                """Time alignment for CPU power saving

                Игра работает в режиме 60 итераций игрового цикла (обновление И
                рендер уровня в одной итерации) в секунду.

                По сути, секунда разбита на 60 частей. Выравнивание происходит
                таким образом, что в начале каждой 1\60 части секунды должна
                начинаться КАЖДАЯ итерация игрового цикла. НЕТ гарантии, что
                при таком подходе не будет потеряна одна из 1\60-ой частей
                секунды

                Таким образом, каждое обновление уровня происходит с рассчетом
                ТОЛЬКО на текущую 1/60 часть секунды. Это позволяет избавиться
                от дробных величин при модификации позиции движущихся объектов.
                """
                # All time below in milliseconds
                #
                # one_iteration_time = 1000 / 60 = 16.666666666666668
                # millis_in_current_second = (
                #     current_time_in_seconds() * 1000 % 1000)
                time_sleep((16.666666666666668 -
                            ((current_time_in_seconds() * 1000 % 1000) %
                             16.666666666666668)) / 1000)

            # Game loop locates in a daemon thread so it will proceed until
            # user interface thread is closed
            while True:
                game_engine_.update_map()

                gui_.render()

                time_alignment()

        Thread(target=game_loop, args=(game_engine, gui), daemon=True).start()
        # Right here several renderings CANNOT be lost
        gui.run_gui_loop()

    except ApplicationException as occurred_exc:
        # Improvement: Different messages for user. Switch only message!
        exit_with_exception("Some exception occurred", occurred_exc,
                            arguments.debug)