Skip to content

Commit

Permalink
Change delimiter to multiplication sign
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jan 28, 2016
1 parent 1c81b56 commit 7130ca9
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 197 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/fakeum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from workflow import Workflow, ICON_WARNING, MATCH_ALL, MATCH_ALLCHARS
from faker import Factory

DELIMITER = ''
DELIMITER = '×'

HELP_URL = 'https://github.com/deanishe/alfred-fakeum'
UPDATE_SETTINGS = {'github_slug': 'deanishe/alfred-fakeum'}
Expand Down
2 changes: 1 addition & 1 deletion src/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1
1.2
72 changes: 36 additions & 36 deletions src/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,40 @@
)

__all__ = [
Workflow,
manager,
PasswordNotFound,
KeychainError,
ICON_ACCOUNT,
ICON_BURN,
ICON_CLOCK,
ICON_COLOR,
ICON_COLOUR,
ICON_EJECT,
ICON_ERROR,
ICON_FAVORITE,
ICON_FAVOURITE,
ICON_GROUP,
ICON_HELP,
ICON_HOME,
ICON_INFO,
ICON_NETWORK,
ICON_NOTE,
ICON_SETTINGS,
ICON_SWIRL,
ICON_SWITCH,
ICON_SYNC,
ICON_TRASH,
ICON_USER,
ICON_WARNING,
ICON_WEB,
MATCH_ALL,
MATCH_ALLCHARS,
MATCH_ATOM,
MATCH_CAPITALS,
MATCH_INITIALS,
MATCH_INITIALS_CONTAIN,
MATCH_INITIALS_STARTSWITH,
MATCH_STARTSWITH,
MATCH_SUBSTRING,
'Workflow',
'manager',
'PasswordNotFound',
'KeychainError',
'ICON_ACCOUNT',
'ICON_BURN',
'ICON_CLOCK',
'ICON_COLOR',
'ICON_COLOUR',
'ICON_EJECT',
'ICON_ERROR',
'ICON_FAVORITE',
'ICON_FAVOURITE',
'ICON_GROUP',
'ICON_HELP',
'ICON_HOME',
'ICON_INFO',
'ICON_NETWORK',
'ICON_NOTE',
'ICON_SETTINGS',
'ICON_SWIRL',
'ICON_SWITCH',
'ICON_SYNC',
'ICON_TRASH',
'ICON_USER',
'ICON_WARNING',
'ICON_WEB',
'MATCH_ALL',
'MATCH_ALLCHARS',
'MATCH_ATOM',
'MATCH_CAPITALS',
'MATCH_INITIALS',
'MATCH_INITIALS_CONTAIN',
'MATCH_INITIALS_STARTSWITH',
'MATCH_STARTSWITH',
'MATCH_SUBSTRING',
]
47 changes: 28 additions & 19 deletions src/workflow/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@

__all__ = ['is_running', 'run_in_background']

wf = Workflow()
log = wf.logger
_wf = None


def wf():
global _wf
if _wf is None:
_wf = Workflow()
return _wf


def _arg_cache(name):
Expand All @@ -37,7 +43,7 @@ def _arg_cache(name):
"""

return wf.cachefile('{}.argcache'.format(name))
return wf().cachefile('{0}.argcache'.format(name))


def _pid_file(name):
Expand All @@ -50,7 +56,7 @@ def _pid_file(name):
"""

return wf.cachefile('{}.pid'.format(name))
return wf().cachefile('{0}.pid'.format(name))


def _process_exists(pid):
Expand Down Expand Up @@ -114,10 +120,11 @@ def _background(stdin='/dev/null', stdout='/dev/null',
if pid > 0:
sys.exit(0) # Exit first parent.
except OSError as e:
log.critical("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror))
wf().logger.critical("fork #1 failed: ({0:d}) {1}".format(
e.errno, e.strerror))
sys.exit(1)
# Decouple from parent environment.
os.chdir(wf.workflowdir)
os.chdir(wf().workflowdir)
os.umask(0)
os.setsid()
# Do second fork.
Expand All @@ -126,7 +133,8 @@ def _background(stdin='/dev/null', stdout='/dev/null',
if pid > 0:
sys.exit(0) # Exit second parent.
except OSError as e:
log.critical("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror))
wf().logger.critical("fork #2 failed: ({0:d}) {1}".format(
e.errno, e.strerror))
sys.exit(1)
# Now I am a daemon!
# Redirect standard file descriptors.
Expand Down Expand Up @@ -169,24 +177,24 @@ def run_in_background(name, args, **kwargs):
"""

if is_running(name):
log.info('Task `{}` is already running'.format(name))
wf().logger.info('Task `{0}` is already running'.format(name))
return

argcache = _arg_cache(name)

# Cache arguments
with open(argcache, 'wb') as file_obj:
pickle.dump({'args': args, 'kwargs': kwargs}, file_obj)
log.debug('Command arguments cached to `{}`'.format(argcache))
wf().logger.debug('Command arguments cached to `{0}`'.format(argcache))

# Call this script
cmd = ['/usr/bin/python', __file__, name]
log.debug('Calling {!r} ...'.format(cmd))
wf().logger.debug('Calling {0!r} ...'.format(cmd))
retcode = subprocess.call(cmd)
if retcode: # pragma: no cover
log.error('Failed to call task in background')
wf().logger.error('Failed to call task in background')
else:
log.debug('Executing task `{}` in background...'.format(name))
wf().logger.debug('Executing task `{0}` in background...'.format(name))
return retcode


Expand All @@ -200,7 +208,7 @@ def main(wf): # pragma: no cover
name = wf.args[0]
argcache = _arg_cache(name)
if not os.path.exists(argcache):
log.critical('No arg cache found : {!r}'.format(argcache))
wf.logger.critical('No arg cache found : {0!r}'.format(argcache))
return 1

# Load cached arguments
Expand All @@ -221,23 +229,24 @@ def main(wf): # pragma: no cover

# Write PID to file
with open(pidfile, 'wb') as file_obj:
file_obj.write('{}'.format(os.getpid()))
file_obj.write('{0}'.format(os.getpid()))

# Run the command
try:
log.debug('Task `{}` running'.format(name))
log.debug('cmd : {!r}'.format(args))
wf.logger.debug('Task `{0}` running'.format(name))
wf.logger.debug('cmd : {0!r}'.format(args))

retcode = subprocess.call(args, **kwargs)

if retcode:
log.error('Command failed with [{}] : {!r}'.format(retcode, args))
wf.logger.error('Command failed with [{0}] : {1!r}'.format(
retcode, args))

finally:
if os.path.exists(pidfile):
os.unlink(pidfile)
log.debug('Task `{}` finished'.format(name))
wf.logger.debug('Task `{0}` finished'.format(name))


if __name__ == '__main__': # pragma: no cover
wf.run(main)
wf().run(main)
Loading

0 comments on commit 7130ca9

Please sign in to comment.