Example #1
0
def main(source, dest):
    """Rename a Git repository and update its remote accordingly."""
    basicConfig(level=DEBUG)
    try:
        repo = Repo(source)
    except OSError as error:
        logger.exception('Error:')
        exit(1)
    else:
        dest = Path(dest)
        try:
            dest = dest.with_suffix('.git')
        except ValueError:
            logger.exception('Error:')
            exit(1)
        logger.info('Using dest: %s', dest)

        remote = repo.remote()
        logger.debug('Old URL: %s', remote.url)
        origin = Path(remote.url)
        logger.debug('Parent: %s', origin.parent)

        new = origin.parent / dest
        logger.info('Using URL: %s', new)

        conf = remote.config_writer
        conf.set('url', str(new))
        conf.release()

        Path(source).rename(dest)
        exit(0)
Example #2
0
File: gmv.py Project: nhudson/unish
def main(source, dest):
    """Rename a Git repository and update its remote accordingly."""
    basicConfig(level=DEBUG)
    try:
        repo = Repo(source)
    except OSError as error:
        logger.exception('Error:')
        exit(1)
    else:
        dest = Path(dest)
        try:
            dest = dest.with_suffix('.git')
        except ValueError:
            logger.exception('Error:')
            exit(1)
        logger.info('Using dest: %s', dest)

        remote = repo.remote()
        logger.debug('Old URL: %s', remote.url)
        origin = Path(remote.url)
        logger.debug('Parent: %s', origin.parent)

        new = origin.parent / dest
        logger.info('Using URL: %s', new)

        conf = remote.config_writer
        conf.set('url', str(new))
        conf.release()

        Path(source).rename(dest)
        exit(0)
Example #3
0
def main(command, args):
    """Intentional command-not-found handler."""
    basicConfig(level=DEBUG)
    # logger.debug('argv: %s', argv)
    # args = ' '.join(argv[1:])
    logger.debug('command: %s', command)
    logger.debug('args: %s', args)
    handle_args(command + ' ' + ' '.join(args))
Example #4
0
def main(command, args):
    """Intentional command-not-found handler."""
    basicConfig(level=DEBUG)
    # logger.debug('argv: %s', argv)
    # args = ' '.join(argv[1:])
    logger.debug('command: %s', command)
    logger.debug('args: %s', args)
    handle_args(command + ' ' + ' '.join(args))
Example #5
0
 def __init__(self, gene_type, N=100, mutation_rate=0.05, elitism_ratio=0.5):
     self.N = N
     self.mutation_rate = mutation_rate
     self.elitism_ratio = elitism_ratio
     root.debug('Creating population')
     self.population = []
     for i in range(self.N):
         root.debug(f"Creating {i}th individual")
         self.population += [gene_type()]
Example #6
0
def main(args):
    """Database manager for Intentional command-not-found handler."""
    path = resource_filename(__name__, 'aliases.db')
    logger.debug('path: %s', path)
    with connect(path) as database:
        cursor = database.cursor()
        sql = 'create table if not exists ' \
              'aliases (name text unique, link text)'
        cursor.execute(sql)
        handle(cursor, args, parse_comment)
Example #7
0
def main(args):
    """Database manager for Intentional command-not-found handler."""
    path = resource_filename(__name__, 'aliases.db')
    logger.debug('path: %s', path)
    with connect(path) as database:
        cursor = database.cursor()
        sql = 'create table if not exists ' \
              'aliases (name text unique, link text)'
        cursor.execute(sql)
        handle(cursor, args, parse_comment)
Example #8
0
def handle_args(args):
    parts = args.split()
    start = parts[0]
    if start[0] == '@':
        operator = start[1:] if start[1:] else 'google'
        args = ' '.join(parts[1:])
        logger.debug('operator: %s', operator)
        logger.debug('args: %s', args)
        handle_operator(operator, args)
    else:
        raise RuntimeError('undefined!')
Example #9
0
def handle_args(args):
    parts = args.split()
    start = parts[0]
    if start[0] == '@':
        operator = start[1:] if start[1:] else 'google'
        args = ' '.join(parts[1:])
        logger.debug('operator: %s', operator)
        logger.debug('args: %s', args)
        handle_operator(operator, args)
    else:
        raise RuntimeError('undefined!')
Example #10
0
    def evolve(self):
        self.population.sort(key=self._get_el_fitness, reverse=True)
        first_dead = int(self.N * self.elitism_ratio)
        for i in range(first_dead, self.N):
            root.debug(f'Crossover {i}')

            i1 = randint(0, first_dead - 1)
            i2 = randint(0, first_dead - 1)

            newborn = self.population[i1].crossover(self.population[i2])
            if random.random() < self.mutation_rate:
                newborn.mutate()

            self.population[i] = newborn
Example #11
0
def handle_operator(operator, args):
    if args:
        try:
            url = globals()['handle_' + operator](args)
        except KeyError:
            raise
    else:
        path = resource_filename(__name__, 'aliases.db')
        logger.debug('path: %s', path)
        with connect(path) as database:
            cursor = database.cursor()
            sql = 'select link from aliases where name = ?'
            args = (operator, )
            logger.debug('sql: %s', sql)
            logger.debug('args: %s', args)
            try:
                cursor.execute(sql, args)
            except OperationalError:
                logger.exception('')
                return 1
            else:
                link = cursor.fetchone()
                if link:
                    url = link[0]
                else:
                    print('Sorry, you have not defined this alias!')
                    return 1
    popen_args = ['firefox', url]
    logger.debug('Popen args: %s', popen_args)
    Popen(popen_args)
    return 0
Example #12
0
def handle_operator(operator, args):
    if args:
        try:
            url = globals()['handle_' + operator](args)
        except KeyError:
            raise
    else:
        path = resource_filename(__name__, 'aliases.db')
        logger.debug('path: %s', path)
        with connect(path) as database:
            cursor = database.cursor()
            sql = 'select link from aliases where name = ?'
            args = (operator,)
            logger.debug('sql: %s', sql)
            logger.debug('args: %s', args)
            try:
                cursor.execute(sql, args)
            except OperationalError:
                logger.exception('')
                return 1
            else:
                link = cursor.fetchone()
                if link:
                    url = link[0]
                else:
                    print('Sorry, you have not defined this alias!')
                    return 1
    popen_args = ['firefox', url]
    logger.debug('Popen args: %s', popen_args)
    Popen(popen_args)
    return 0
Example #13
0
    def _wrapped(url: Url, *a, **kw):
        key = hashlib.sha256(url.encode("utf8")).hexdigest()
        path = CACHE / key
        if path.exists():
            logger.debug(
                "drytoml-cache: Using cached version of %s at %s",
                url,
                path,
            )
            with open(path) as fp:
                return fp.read()

        result = func(url, *a, **kw)
        logger.debug("Caching %s into %s", url, path)
        CACHE.mkdir(exist_ok=True, parents=True)
        with open(path, "w") as fp:
            fp.write(result)
        return result
Example #14
0
from logging import root

from utils import pickle_cached

root.debug('Importing map_model')
from dataclasses import dataclass
import random
from typing import List

from scipy.interpolate import interp1d, splrep
from scipy import interpolate

from base_classes import Place
from data_loaders import task
from abc import ABC, abstractmethod

root.debug('Importing map_model classes')


class MapModel(ABC):
    @abstractmethod
    def get_speed(self, p1, p2, start_time):
        pass

    @abstractmethod
    def get_dist(self, p1, p2, start_time):
        pass

    def get_time(self, p1: Place, p2: Place, start_time):
        return self.get_dist(p1, p2, start_time) / self.get_speed(
            p1, p2, start_time)
Example #15
0
import scipy
from logging import root

from icecream import ic
from numba import jit

root.debug('Importing base_classes')

from dataclasses import dataclass, field
from typing import List, Set, Collection, Tuple
from geopy.distance import distance, vincenty

# TODO: OSRM + пометить машины, которые не могу проехать.
from geopandas.tests.test_geocode import geopy

from utils import static_field


@dataclass(frozen=True)
class Position:
    """Место в пространстве"""
    x: float = None
    y: float = None

    # @jit
    def dist(self, point: "Position") -> float:
        # return mpu.haversine_distance((self.x, self.y), (point.x, point.y))
        # return vincenty((self.x, self.y), (point.x, point.y)).km
        # return distance((self.x, self.y), (point.x, point.y)).km
        return (self.x - point.x)**2 + (self.y - point.y)**2