<commit_before>#!/usr/bin/env python
import os
import os.path
import collections
import plistlib
import zipfile
import tempfile
import shutil
import subprocess
import glob
import hashlib
import binascii

DEVNULL = os.open(os.devnull, os.O_RDWR)

# Returns the path to the filter script corresponding to a keyword
def filter_path(keyword):
	k = keyword[4:] + 's'

	return 'filters/filter-{}.applescript'.format(k)

# Returns the path to the action script based on a list keywords
# for which the filter scripts are connected with the action script
def action_path(connected_keywords):
	if len(connected_keywords) > 1:
		connected_keywords = list(reversed(sorted(connected_keywords)))

	keyword = connected_keywords[0]
	k = keyword[4:]

	return 'actions/play-{}.applescript'.format(k)

# Given a config dictionary and a file path updates the config with the file contents
# Returns wether the file was updated
def update_script(config, path):
	with open(path, 'r') as f:
		contents = f.read()
		if config['script'] != contents:
			config['script'] = contents
			print 'Updated {}'.format(path)

			return True
		else:
			return False

# Returns the path to the installed workflow or None if it can't be found
def get_installation_dir(bundle_id):
	ALFRED_PLIST = os.path.expanduser('~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences.plist')
	DEFAULT_ALFRED_PREFERENCE_DIR = os.path.expanduser('~/Library/Application Support/Alfred 2')
	WORKFLOW_INFOS_GLOB = 'Alfred.alfredpreferences/workflows/user.workflow.*/info.plist'

	try:
		# We need to read the plist with defaults
		# as plistlib can't handle binary plists before Python 3.4
		preference_dir = subprocess.check_output(['defaults', 'read', ALFRED_PLIST, 'syncfolder'], stderr=DEVNULL)

		# Ensure ~ is expanded to full home folder path
		# Also remove leading and trailing whitespace
		preference_dir = os.path.expanduser(preference_dir.strip())
<commit_msg>Improve action_path detection<commit_after>#!/usr/bin/env python
import os
import os.path
import collections
import plistlib
import zipfile
import tempfile
import shutil
import subprocess
import glob
import hashlib
import binascii

DEVNULL = os.open(os.devnull, os.O_RDWR)

# Returns the path to the filter script corresponding to a keyword
def filter_path(keyword):
	k = keyword[4:] + 's'

	return 'filters/filter-{}.applescript'.format(k)

# Returns the path to the action script based on a list keywords
# for which the filter scripts are connected with the action script
def action_path(connected_keywords):
	for keyword in connected_keywords:
		k = keyword[4:]

		f = 'actions/play-{}.applescript'.format(k)
		if os.path.exists(f):
		return f

	raise IOError('Action script not found for keywords: {}'.format(connected_keywords))

# Given a config dictionary and a file path updates the config with the file contents
# Returns wether the file was updated
def update_script(config, path):
	with open(path, 'r') as f:
		contents = f.read()
		if config['script'] != contents:
			config['script'] = contents
			print 'Updated {}'.format(path)

			return True
		else:
			return False

# Returns the path to the installed workflow or None if it can't be found
def get_installation_dir(bundle_id):
	ALFRED_PLIST = os.path.expanduser('~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences.plist')
	DEFAULT_ALFRED_PREFERENCE_DIR = os.path.expanduser('~/Library/Application Support/Alfred 2')
	WORKFLOW_INFOS_GLOB = 'Alfred.alfredpreferences/workflows/user.workflow.*/info.plist'

	try:
		# We need to read the plist with defaults
		# as plistlib can't handle binary plists before Python 3.4
		preference_dir = subprocess.check_output(['defaults', 'read', ALFRED_PLIST, 'syncfolder'], stderr=DEVNULL)

		# Ensure ~ is expanded to full home folder path
		# Also remove leading and trailing whitespace
		preference_dir = os.path.expanduser(preference_dir.strip())

{'fraction_non_alphanumeric': 0.09373394966615306, 'fraction_numerical': 0.0030816640986132513, 'mean_word_length': 5.076443057722309, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6060699', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1171, 'n_words': 389}