Example #1
0
    def __init__(self, filename=None, data_path=None):
        # Based in Django's approach -> http://code.djangoproject.com/svn/django/trunk/django/__init__.py
        self.version = __import__('pytrainer').get_version()
        #Process command line options
        self.startup_options = self.get_options()
        #Setup logging
        self.environment = Environment(platform.get_platform(),
                                       self.startup_options.conf_dir)
        self.environment.create_directories()
        self.set_logging(self.startup_options.log_level,
                         self.startup_options.log_type)
        logging.debug('>>')
        logging.debug("pytrainer version %s" % (self.version))
        self.data_path = data_path
        self.date = Date()
        self.ddbb = None
        # Checking profile
        logging.debug('Checking configuration and profile...')
        self.profile = Profile(self.environment, self.data_path, self)
        self.uc = UC()
        self.windowmain = None
        self.ddbb = DDBB(self.profile, self)
        logging.debug('connecting to DDBB')
        self.ddbb.connect()

        initialize_data(self.ddbb, self.environment.conf_dir)

        self._sport_service = SportService(self.ddbb)
        self.record = Record(self._sport_service, data_path, self)
        self.athlete = Athlete(data_path, self)
        self.stats = Stats(self._sport_service, self)
        pool_size = self.profile.getIntValue("pytraining",
                                             "activitypool_size",
                                             default=1)
        self.activitypool = ActivityPool(self, size=pool_size)
        #preparamos la ventana principal
        self.windowmain = Main(self._sport_service,
                               data_path,
                               self,
                               self.version,
                               gpxDir=self.profile.gpxdir)
        self.date = Date(self.windowmain.calendar)
        self.waypoint = Waypoint(data_path, self)
        self.extension = Extension(data_path, self)
        self.plugins = Plugins(data_path, self)
        self.importdata = Importdata(self._sport_service, data_path, self,
                                     self.profile)
        self.loadPlugins()
        self.loadExtensions()
        self.windowmain.setup()
        self.windowmain.on_calendar_selected(None)
        self.refreshMainSportList()
        self.windowmain.run()
        logging.debug('<<')
Example #2
0
    def index_packages(self):
        extensions = [
            Extension(str(Path(self.start_dir) / package))
            for package in os.listdir(self.start_dir)
        ]

        for extension in extensions:
            try:
                self.index_package(extension)
            except Exception as e:
                LOGGER.warning(
                    f"Failed to index {extension.filename}: {e}")
Example #3
0
def index_new_extension(update: Update):
    """Force Indexing new extension"""
    ext = Extension(Path(update.path) / update.filename)
    if "IN_CLOSE_WRITE" in update.type_names:
        INDEXER.index_package(ext)

    if "IN_DELETE" in update.type_names:
        if ext not in INDEXER.filename_to_extension_pack:
            return {"status": "OK"}

        INDEXER.remove_package(ext)  # get actual copy

    return {"status": "OK"}
Example #4
0
                    id = file[:-5]
                    id_to_path[id] = full_path

        extension_class_dict = {}
        num_invalid_extensions = 0
        total_num_extensions = len(id_to_path.items())
        counter = 0

        for k, v in id_to_path.items(
        ):  # build metadata class for each manifest
            if counter % (total_num_extensions // 10) == 0:
                print(f"completed {counter}/{total_num_extensions} extensions")

            with open(v) as fid:
                data = json.load(fid)
                extension = Extension(data, k)
                # print(extension.__dict__.items())
                if extension.is_valid:
                    extension_class_dict[k] = extension
                else:
                    num_invalid_extensions += 1
            counter += 1

        print(
            f"finished with  {num_invalid_extensions} failures out of {total_num_extensions} total extensions"
        )

        #Note checkpoint the extensions after their names have been queried
        with open(checkpoint_path, "wb") as checkpoint_file:
            pickle.dump(extension_class_dict, checkpoint_file)
    else:
Example #5
0
    def __init__(self, filename=None, data_path=None):
        # Based on Django's approach -> http://code.djangoproject.com/svn/django/trunk/django/__init__.py
        self.version = __import__('pytrainer').get_version()
        #Process command line options
        self.startup_options = self.get_options()
        #Setup logging
        self.environment = Environment(self.startup_options.conf_dir,
                                       data_path)
        self.environment.create_directories()
        self.environment.clear_temp_dir()
        self.set_logging(self.startup_options.log_level,
                         self.startup_options.log_type)
        logging.debug('>>')
        logging.info("pytrainer version %s" % (self.version))
        self.data_path = data_path

        # Checking profile
        logging.debug('Checking configuration and profile...')
        self.profile = Profile()
        # Write the default config to disk
        self.profile.saveProfile()
        self.uc = UC()
        self.profilewindow = None
        self.ddbb = DDBB(self.profile.sqlalchemy_url)
        logging.debug('connecting to DDBB')
        self.ddbb.connect()

        logging.info('Checking if some upgrade action is needed...')
        initialize_data(self.ddbb, self.environment.conf_dir)

        # Loading shared services
        logging.debug('Loading sport service...')
        self._sport_service = SportService(self.ddbb)
        logging.debug('Loading record service...')
        self.record = Record(self._sport_service, data_path, self)
        logging.debug('Loading athlete service...')
        self.athlete = Athlete(data_path, self)
        logging.debug('Loading stats service...')
        self.stats = Stats(self)
        logging.debug('Initializing activity pool...')
        pool_size = self.profile.getIntValue("pytraining",
                                             "activitypool_size",
                                             default=1)
        self.activitypool = ActivityService(self, size=pool_size)

        #Loading main window
        self.windowmain = None
        logging.debug('Loading main window...')
        self.windowmain = Main(self._sport_service,
                               data_path,
                               self,
                               self.version,
                               gpxDir=self.profile.gpxdir)

        # Select initial date depending on user's preference
        self.selectInitialDate()

        logging.debug('Loading waypoint service...')
        self.waypoint = WaypointService(data_path, self)
        logging.debug('Loading extension service...')
        self.extension = Extension(data_path, self)
        logging.debug('Loading plugins service...')
        self.plugins = Plugins(data_path, self)
        self.importdata = Importdata(self._sport_service, data_path, self,
                                     self.profile)
        logging.debug('Loading plugins...')
        self.loadPlugins()
        logging.debug('Loading extensions...')
        self.loadExtensions()
        logging.debug('Setting values for graphs, maps and waypoint editor...')
        self.windowmain.setup()
        self.windowmain.on_calendar_selected(None)
        logging.debug('Refreshing sport list... is this needed?')
        self.refreshMainSportList()
        logging.debug('Launching main window...')
        self.windowmain.run()
        logging.debug('<<')
Example #6
0
def findDomains(filename):
    urls = findLinks(filename)
    domains = [urlparse(url)[1].split('/') for url in urls]
    return (domains)


if __name__ == '__main__':
    if os.name == "posix":
        path = os.path.expanduser(
            "~/.config/google-chrome/Default/Extensions/*")
    elif os.name == "nt":
        path = os.path.expanduser(
            r"~/AppData/Local/Google/Chrome/User Data/Default/Extensions/*")
    # result=os.listdir(path)
    extensions = []

    extensionPaths = glob.glob(path)

    for extensionPath in extensionPaths:
        try:
            extensions.append(Extension(extensionPath))
        except ValueError:
            pass

    for extension in extensions:
        print(extension.manifest["name"])
        for path in filter(lambda x: x.endswith('.js'), extension.filelist):
            # print(path)
            print(findLinks(path))