Exemplo n.º 1
0
def open_dir(path):
	config = load_config()

	if path in config['paths']:
		launch(config['paths'][path])
	else:
		print 'Error: "{}" is not a valid path variable'.format(path)
Exemplo n.º 2
0
def unset_path(var_name):
	var_name = var_name.lower()

	config = load_config()

	try:
		path = config['paths'].pop(var_name)
		save_config(config)

		print '"{}" has been unset'.format(var_name)
	except KeyError:
		print 'Error: path variable "{}" does not exist'.format(var_name)
Exemplo n.º 3
0
def set_path(var_name, path):
	var_name = var_name.lower()

	if os.path.isdir(path):
		config = load_config()
		path = os.path.abspath(path)
		
		config['paths'][var_name] = path
		save_config(config)

		print '"{}" saved as "{}"'.format(path, var_name)
	else:
		print '"{}" does not seem to be a directory'.format(path)
Exemplo n.º 4
0
        "help": "Data to be used by the application internally.",
        "data": {
            "timezone": {
                "default": "UTC",
                "help": "Timezone of where you live."
            },
            "hours": {
                "default": [
                    "08:10 08:50", "09:00 09:40", "09:50 10:30", "10:40 11:20",
                    "11:30 12:10", "12:55 13:35", "13:45 14:25", "14:35 15:15",
                    "00:00 23:59"
                ],
                "help":
                "Starting and finishing times of classes."
            }
        }
    }
}

config_manager.create_folders(FOLDERS)
config_manager.create_files(FILES)
config = config_manager.load_config(CONFIG_PATH)
res = config_manager.check_config(config, CONFIG_TEMPLATE)
config_manager.save_config(CONFIG_PATH, config)

if res:
    print(f"Please fill in null values in {CONFIG_PATH}")
    sys.exit(1)

tz = pytz.timezone(config["settings"]['timezone'])
Exemplo n.º 5
0
def do_search(search_root, search_pattern, search_for_directory):
	root = ''
	results = []
	compare.pattern = search_pattern.lower() # make case insensitive comparision

	config = load_config()
	
	if search_root is None:
		if 'default_root' in config['paths'] and config['paths']['default_root']:
			root = config['paths']['default_root']
		else:
			root = os.getcwd()
	else:
		if search_root in config['paths']:	
			# The given root is stored as path variable
			root = config['paths'][search_root]
		elif os.path.isdir(search_root):
			# The given root is a real path
			root = search_root
		else:
			print 'Error: <root> must be a path variable or a real path'

			sys.exit()

	# get all file names in the tree directory
	for dir_entries in os.walk(root):
		dir_path, directories, files = dir_entries

		if search_for_directory:
			entries = directories
		else:
			entries = files

		for entrie in entries:
			full_path = os.path.join(dir_path, entrie)

			compare.word = full_path.replace(root, '').lower() # use relative path for comparision
			
			initialize_memory()

			results.append({'path': full_path, 'factor': compare()})

	if len(results) > 0:
		results = sorted(results, reverse=True, key=lambda res: (res['factor'], len(res['path']) * -1))
		
		best_result = results[0]

		if list_results:
			count = 1
			for res in results:
				print '({})\n"{}" -> {}'.format(count, res['path'], res['factor'])
				
				if count % 5 == 0:
					raw_input(':')

				count += 1
		
		print 'Best match in: '
		print '"{}"'.format(best_result['path'])

		launch(best_result['path'])
Exemplo n.º 6
0
def show_paths():
	config = load_config()

	for var, path in config['paths'].iteritems():
		print '{}="{}"'.format(var, path)
Exemplo n.º 7
0
                    counter.add('resolved')
                    results['ok'][doc['PID']] = sysno

                counter.add('total')

        counter.report()
        return results


def write_outfile(results):
    """Write output."""
    with open('./data/856_kramerius_export.txt', 'a') as outfile:
        # from dict with uuid keys and sysno values, generate file with lines
        for key, val in results['ok'].items():
            line1 = str(val) + ' 85640 L $$uhttps://kramerius.techlib.cz/search/handle/' + key + '$$yDigitalizovany dokument\n'
            line2 = str(val) + ' BAS   L di\n'
            outfile.write(line1)
            outfile.write(line2)
        for key, val in results['unresolved'].items():
            line1 = 'SYSNO' + ' 85640 L $$uhttps://kramerius.techlib.cz/search/handle/' + key + '$$yDigitalizovany dokument\n'
            line2 = 'SYSNO' + ' BAS   L di\n'
            outfile.write(line1)
            outfile.write(line2)


if __name__ == '__main__':
    configuration = config.load_config("./configuration/config.json")
    missing_counter = reports.Counter()
    results = process_data(configuration, missing_counter)
    write_outfile(results)