Esempio n. 1
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.central_widget = QtWidgets.QWidget(self)
        self.setCentralWidget(self.central_widget)

        self.setWindowTitle('tkl-merger')
        try:
            scriptDir = os.path.dirname(os.path.realpath(__file__))
            self.setWindowIcon(QtGui.QIcon(os.path.join(scriptDir,
                                                        'icon.png')))
        except:
            pass

        self.cfg = config_util.read_config("config.ini")
        # self.cfg["dir_models"] = "C:/Program Files (x86)/Universal Interactive/Blue Tongue Software/Jurassic Park Operation Genesis/JPOG/Data/Models"
        # self.cfg["dir_out"] = "C:\\"
        # self.dinos = []
        self.tmd_names = []
        # self.cfg["boss_tkl"] = ""
        self.names_to_full_paths = {}
        self.tmd_to_tkl = {}

        self.b_add = QtWidgets.QPushButton('Load TMDs')
        self.b_add.setToolTip("Load TMD files you want to merge.")
        self.b_add.clicked.connect(self.add_tmds)

        self.b_remove = QtWidgets.QPushButton('Remove TMDs')
        self.b_remove.setToolTip("Remove TMD files you do not want to merge.")
        self.b_remove.clicked.connect(self.remove_tmds)

        self.b_merge = QtWidgets.QPushButton('Merge')
        self.b_merge.setToolTip(
            "Merge these files according to the current settings.")
        self.b_merge.clicked.connect(self.run)

        self.c_tkl = QtWidgets.QComboBox(self)
        self.c_tkl.setToolTip(
            "Select the master TKL. This determines how many keys you may use."
        )
        self.c_tkl.currentIndexChanged.connect(self.set_boss_tkl)

        self.tmd_widget = QtWidgets.QListWidget()
        self.tmd_widget.setSelectionMode(
            QtWidgets.QAbstractItemView.ExtendedSelection)

        self.qgrid = QtWidgets.QGridLayout()
        self.qgrid.setHorizontalSpacing(0)
        self.qgrid.setVerticalSpacing(0)
        self.qgrid.addWidget(self.b_add, 0, 0)
        self.qgrid.addWidget(self.b_remove, 0, 1)
        self.qgrid.addWidget(self.b_merge, 0, 2)
        self.qgrid.addWidget(self.c_tkl, 0, 3)
        self.qgrid.addWidget(self.tmd_widget, 1, 0, 1, 4)

        self.central_widget.setLayout(self.qgrid)
Esempio n. 2
0
def get(json_object):

	if(config_util.read_config("forecast_retriever.cfg")==True):
		try:
			obj=json.loads("["+json_object+"]")
		except:
			obj=json.loads("[]")

		request=db_util.retrieve_forecast(obj,"localhost",config_util.user,config_util.password,config_util.database)

		if(request[0]==True):
			return request[1]
		else:
			return '{"error":"'+request[1]+'"}'
	else:
		return '{"error":"Bad password."}'
Esempio n. 3
0
        # Open up and parse the distribution config file:
        try:        
            dist_config_dict = configobj.ConfigObj(f, file_error=True)
        except IOError, e:
            sys.exit(str(e))
        except SyntaxError, e:
            sys.exit("Syntax error in distribution configuration file '%s': %s" % 
                     (f, e))
        
        # The path where the weewx.conf configuration file will be installed
        install_path = os.path.join(install_dir, os.path.basename(f))
        
        # Do we have an old config file?
        if os.path.isfile(install_path):
            # Yes. Read it
            config_path, config_dict = config_util.read_config(install_path, None)
            if DEBUG:
                print "Old configuration file found at", config_path

            # Update the old configuration file to the current version:
            config_util.update_config(config_dict)
            
            # Then merge it into the distribution file
            config_util.merge_config(config_dict, dist_config_dict)
        else:
            # No old config file. Use the distribution file, then, if we can,
            # prompt the user for station specific info
            config_dict = dist_config_dict
            if not self.no_prompt:
                # Prompt the user for the station information:
                stn_info = config_util.prompt_for_info()
		print("Forecast Retreiver usage:")
		print("\t--help\t\t\t\tShow this dialog.")
		print("\t-n, --now\t\t\tSpecify now cast retrieval.")
		print("\t-h, --1-hour\t\t\tSpecify 1 hour cast retrieval.")
		print("\t-d, --3-day\t\t\tSpecify 3 day cast retrieval.")
		print("\t-m, --28-day\t\t\tSpecify 28 day cast retrieval.")
		print("\t-c, --carrington\t\tSpecify carrington rotation retrieval.")
		exit(0)

	#Start Server
	print("Forecast Retriever")

	#Read Configuration File (On failure, write a default configuration file.)
	error_message_start("\tLoading Configuration File\t")

	if(config_util.read_config("forecast_retriever.cfg")==False):
		error_message_end(False)
		exit(0)
	else:
		error_message_end(True)

	#Get Forecasts
	if(retrieve_now_cast==True):
		error_message_start("\tRetrieving Now Cast\t\t")
		error_message_end(get_forecast(config_util.now_forecast_link,"now","now")[0])
	if(retrieve_h1_cast==True):
		error_message_start("\tRetrieving 1 Hour Cast\t\t")
		error_message_end(get_forecast(config_util.h1_forecast_link,"h1","1 hour")[0])
	if(retrieve_d3_cast==True):
		error_message_start("\tRetrieving 3 Day Cast\t\t")
		error_message_end(get_forecast(config_util.d3_forecast_link,"d3","3 day")[0])
def main():
    global config
    config = config_util.read_config()

    if config.get('logging','level') == "debug":
        logging.getLogger().setLevel(logging.DEBUG)
    elif config.get('logging','level') == "info":
        logging.getLogger().setLevel(logging.INFO)

    url = config.get('source','url')

    html_filename = config['source'].get('html')
    if not html_filename:
        # download resource from URL and parse HTML
        raw_html = download_resource(config.get('source','url'))

    else:
        if os.path.isfile(html_filename):
            with open(html_filename, 'r') as f:
                raw_html = f.read()
        else:
            logger.error("Could not read HTML file: %s", html_filename)
            sys.exit(1)

    if raw_html:
        # prepare folders
        create_folders()

        # Clean up trask
        raw_html = raw_html.replace('#{{', '{{')

        # find all resources in javascript

        logger.info('FILENAMES')

        for expr in [ r'filename:"(.*?)"',
                      r'xlink:href="(.*?)"',
                      r'src=\\"(.*?)\\"',
                      r'(/assets/.*?\.js)' ]:
            matches = re.finditer(expr,raw_html)
            if matches:
                for m in matches:
                    f = m.group(1)
                    logger.info('Found %s in %s',f,m.group(0))

                    # save resource
                    resource_path = save_resource(f)
                    if resource_path:
                        # set new path to web resource
                        resource_path = add_webfiles_tags_to_resource_path(resource_path)
                        print(resource_path)
                        raw_html = raw_html.replace(f,resource_path)

        root = html.fromstring(raw_html)

        # find all web resources in link tags that are not a stylesheet
        for elm in root.xpath("//link[@rel!='stylesheet' and @type!='text/css' and @href]"):
            if elm.get('href'):
                # save resource
                resource_path = save_resource(elm.get('href'))
                if resource_path:
                    # set new path to web resource
                    resource_path = add_webfiles_tags_to_resource_path(resource_path)
                    elm.set('href', resource_path)

        # find all external stylesheets
        # xpath expression returns directly the value of href
        for elm in root.xpath("//link[@rel='stylesheet' and @href or @type='text/css' and @href]"):
            if elm.get('href'):
                href = elm.get('href')
                # save resource
                resource_path = save_resource(href)
                if resource_path:

                    # set new path to web resource
                    resource_path = add_webfiles_tags_to_resource_path(resource_path)
                    elm.set('href', resource_path)

        # find all web resources from elements with src attribute (<script> and <img> elements)
        # xpath expression returns directly the value of src
        for elm in root.xpath('//*[@src]'):
            if elm.get('src') and not elm.get('src').startswith('data:'):
                # save resource
                resource_path = save_resource(elm.get('src'))
                if resource_path:

                    # set new path to web resource
                    resource_path = add_webfiles_tags_to_resource_path(resource_path)
                    elm.set('src', resource_path)

        # find all web resources from elements with srcset attribute (html5)
        for elm in root.xpath('//*[@srcset]'):
            images = elm.get('srcset')
            new_images = []
            for i in re.split(r'\s*,\s*',images):
                fields = re.split(r'\s+',i,1)
                img = fields[0]
                size=''
                if len(fields) == 2:
                    size = fields[1]
                # save resource
                resource_path = save_resource(img)
                if resource_path:
                    # set new path to web resource
                    resource_path = add_webfiles_tags_to_resource_path(resource_path)
                    new_images.append(resource_path+' '+size)
                else:
                    # Keep as is
                    new_images.append(img+' '+size)
            elm.set('srcset', ',\n'.join(new_images))


        # find all web resources from elements with data-src attribute (HTML5)
        # xpath expression returns directly the value of data-src
        for elm in root.xpath('//*[@data-src]'):
            if elm.get('data-src'):
                # save resource
                resource_path = save_resource(elm.get('data-src'))
                if resource_path:
                    # set new path to web resource
                    resource_path = add_webfiles_tags_to_resource_path(resource_path)
                    elm.set('data-src', resource_path)

        # find web resources in inline stylesheets
        for elm in root.xpath('//style'):
            new_css = save_resources_from_css(config.get('source','url'),elm.text, False)
            if new_css:
                # set new text for element, with updated URLs
                elm.text = new_css

        # find web resources in inline styles
        # xpath expression returns directly the value of style
        for elm in root.xpath('//*[@style]'):
            new_css = save_resources_from_css(config.get('source','url'),elm.get('style'), False)
            if new_css:
                # set style with new path
                elm.set('style', new_css)

        # save ftl/html
        html_file_contents = html.tostring(root).decode('utf-8')
        file_name = os.path.join(config.get('dest','site_dir'),config.get('dest','template'))
        if not config.get('dest','type') == 'html':
            # add webfiles import tag for importing tag libraries
            html_file_contents = config.get('ftl','import_tag') + '\n'+ html_file_contents

        # replace placeholders for webfiles tags
        html_file_contents = html_file_contents.replace(WEBFILES_START_TAG_SEARCHREPLACE, WEBFILES_START_TAG)
        html_file_contents = html_file_contents.replace(WEBFILES_END_TAG_SEARCHREPLACE, WEBFILES_END_TAG)

        # save to file
        print('Writing',file_name)
        with open(file_name, 'w') as f:
            f.write(html_file_contents)
        print("Downloaded resources from {} successfully".format(url))
Esempio n. 6
0
def main():
    global config
    config = config_util.read_config()

    if config.get('logging', 'level') == "debug":
        logging.getLogger().setLevel(logging.DEBUG)
    elif config.get('logging', 'level') == "info":
        logging.getLogger().setLevel(logging.INFO)

    # prepare folders
    create_folders()

    url = config.get('source', 'url')

    html_filename = config.get_filename('source', 'html')
    if html_filename:
        root = html.parse(html_filename)
    else:
        # download resource from URL and parse HTML
        raw_html = download_resource(url)
        root = html.fromstring(raw_html)

    # find all web resources in link tags that are not a stylesheet
    for elm in root.xpath(
            "//link[@rel!='stylesheet' and @type!='text/css' and @href]"):
        if elm.get('href'):
            # save resource
            resource_path = save_resource(elm.get('href'))
            if resource_path:
                # set new path to web resource
                resource_path = add_webfiles_tags_to_resource_path(
                    resource_path)
                elm.set('href', resource_path)

    # find all external stylesheets
    # xpath expression returns directly the value of href
    for elm in root.xpath(
            "//link[@rel='stylesheet' and @href or @type='text/css' and @href]"
    ):
        if elm.get('href'):
            href = elm.get('href')
            # save resource
            resource_path = save_resource(href)
            if resource_path:

                # set new path to web resource
                resource_path = add_webfiles_tags_to_resource_path(
                    resource_path)
                elm.set('href', resource_path)

    # find all web resources from elements with src attribute (<script> and <img> elements)
    # xpath expression returns directly the value of src
    for elm in root.xpath('//*[@src]'):
        if elm.get('src') and not elm.get('src').startswith('data:'):
            # save resource
            resource_path = save_resource(elm.get('src'))
            if resource_path:

                # set new path to web resource
                resource_path = add_webfiles_tags_to_resource_path(
                    resource_path)
                elm.set('src', resource_path)

    # find all web resources from elements with srcset attribute (html5)
    for elm in root.xpath('//*[@srcset]'):
        images = elm.get('srcset')
        new_images = []
        for i in re.split(r'\s*,\s*', images):
            fields = re.split(r'\s+', i, 1)
            img = fields[0]
            size = ''
            if len(fields) == 2:
                size = fields[1]
            # save resource
            resource_path = save_resource(img)
            if resource_path:
                # set new path to web resource
                resource_path = add_webfiles_tags_to_resource_path(
                    resource_path)
                new_images.append(resource_path + ' ' + size)
            else:
                # Keep as is
                new_images.append(img + ' ' + size)
        elm.set('srcset', ',\n'.join(new_images))

    # find all web resources from elements with data-src attribute (HTML5)
    # xpath expression returns directly the value of data-src
    for elm in root.xpath('//*[@data-src]'):
        if elm.get('data-src'):
            # save resource
            resource_path = save_resource(elm.get('data-src'))
            if resource_path:
                # set new path to web resource
                resource_path = add_webfiles_tags_to_resource_path(
                    resource_path)
                elm.set('data-src', resource_path)

    # find web resources in inline stylesheets
    for elm in root.xpath('//style'):
        new_css = save_resources_from_css(config.get('source', 'url'),
                                          elm.text, False)
        if new_css:
            # set new text for element, with updated URLs
            elm.text = new_css

    # find web resources in inline styles
    # xpath expression returns directly the value of style
    for elm in root.xpath('//*[@style]'):
        new_css = save_resources_from_css(config.get('source', 'url'),
                                          elm.get('style'), False)
        if new_css:
            # set style with new path
            elm.set('style', new_css)

    html_contents = html.tostring(root).decode('utf-8')

    html_contents = process_additional_text(html_contents)

    filename = os.path.join(config.get_filename('dest', 'site_dir'),
                            config.get('dest', 'template'))
    if not config.get('dest', 'type') == 'html':
        # add webfiles import tag for importing tag libraries
        html_contents = config.get('ftl', 'import_tag') + '\n' + html_contents

    # replace placeholders for webfiles tags
    html_contents = html_contents.replace(WEBFILES_START_TAG_SEARCHREPLACE,
                                          WEBFILES_START_TAG)
    html_contents = html_contents.replace(WEBFILES_END_TAG_SEARCHREPLACE,
                                          WEBFILES_END_TAG)

    # save to file
    print('Writing', filename)
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    with open(filename, 'w') as f:
        f.write(html_contents)
    print("COMPLETED\nDownloaded from", url, "\nto", filename)
Esempio n. 7
0
                                        thresh=1e-04,
                                        iter=2,
                                        check_finite=False)

    save_tkl(boss_tkl_in_path, dir_out, boss_tkl, final_locs_lut,
             final_rots_lut)

    #now find closest matching keys for each of our TMDs
    #and finally replace all indices with the new indices
    for tmd_path, keyframes in tmd_to_keys.items():
        print("\nReassigning", os.path.basename(tmd_path))
        loc_keys, rot_keys = keyframes

        loc_indices_new, distance = vq(loc_keys, final_locs_lut)
        rot_indices_new, distance = vq(rot_keys, final_rots_lut)

        tmd_name = os.path.basename(tmd_path)
        save_new_keys(tmd_path, os.path.join(dir_out, tmd_name), boss_tkl,
                      loc_indices_new, rot_indices_new)


if __name__ == '__main__':
    cfg = config_util.read_config("config.ini")
    tmd_paths = []
    for file in os.listdir(cfg["dir_models"]):
        f_l = file.lower()
        for dino in cfg["dinos"]:
            if dino.lower() in f_l and f_l.endswith(".tmd"):
                tmd_paths.append(os.path.join(cfg["dir_models"], file))
                break
    work(tmd_paths, cfg["dir_out"], cfg["boss_tkl"])