Exemple #1
0
    def _make(name, tags, project, show_error):
        Name.set_name(name)
        Name.set_tags(tags)
        Path.set_project_path(project_path=project, show_error=show_error)

        DataFile.compute_command_path(force=True)
        return MergeSettings(args)
Exemple #2
0
def _make(name, tags, project, show_error, args):
  Name.set_name(name)
  Name.set_tags(tags)
  Path.set_project_path(project_path=project, show_error=show_error)

  CommandFile.compute_command_path()
  return MergeConfig.MergeConfig(args)
Exemple #3
0
def transfer(_, **data):
    backup_directory = os.path.join(Path.data_path(), '.echomesh-xfer')

    try:
        shutil.rmtree(backup_directory)
    except OSError:
        pass

    directories = data.get('directories', [])
    if '' in directories:
        directories = os.listdir(Path.data_path())

    for directory in directories:
        parent = os.path.dirname(os.path.join(backup_directory, directory))
        MakeDirs.parent_makedirs(parent)
        shutil.move(os.path.join(Path.data_path(), directory), parent)

    for f, value in six.iteritems(data.get('files')):
        fname = os.path.join(Path.data_path(), f)
        MakeDirs.parent_makedirs(fname)
        with open(fname, 'w') as o:
            o.write(value['contents'])
        os.utime(fname, (value['atime'], value['mtime']))

    if Settings.get('execution', 'delete_backups_after_transfer'):
        try:
            shutil.rmtree(backup_directory)
        except:
            pass
Exemple #4
0
def _command_file(*path):
    path = clean(*path)
    if path[0] == 'default':
        return os.path.join(
            Path.python_path(), 'echomesh', 'settings', *path[1:])
    else:
        return os.path.join(Path.project_path(), 'data', *path)
Exemple #5
0
def main():
  import sys

  times = []

  def p(msg=''):
    """Print progress messages while echomesh loads."""
    print(msg, end='\n' if msg else '')
    global COUNT
    dot = str(COUNT % 10) if USE_DIGITS_FOR_PROGRESS_BAR else '.'
    print(dot, end='')
    COUNT += 1

    sys.stdout.flush()

    import time
    times.append(time.time())

  p('Loading echomesh ')

  from echomesh.base import Path
  p()

  Path.fix_sys_path()
  p()

  from echomesh.base import Args
  p()

  Args.set_arguments(sys.argv)
  p()

  from echomesh.base import Config
  p()

  Config.recalculate()
  p()

  if Config.get('autostart') and not Config.get('permission', 'autostart'):
    print()
    from echomesh.util import Log
    Log.logger(__name__).info("Not autostarting because autostart=False")
    exit(0)
  p()

  from echomesh import Instance
  print()

  if Config.get('diagnostics', 'startup_times'):
    print()
    for i in range(len(times) - 1):
      print(i, ':', int(1000 * (times[i + 1] - times[i])))
    print()

  Instance.main()

  if Config.get('diagnostics', 'unused_configs'):
    import yaml
    print(yaml.safe_dump(Config.get_unvisited()))
Exemple #6
0
def _set_project_path():
  # First, find out if we're autostarting.
  autostart = False
  for address, value in Args.ARGS:
    if len(address) == 1 and 'autostart'.startswith(address[0]):
      autostart = True
      break

  # Get the project field out of the command line if it exists,
  # before we get any file past the default configuration.
  for address, value in Args.ARGS:
    if len(address) == 1 and 'project'.startswith(address[0]):
      Path.set_project_path(value, show_error=True, prompt=not autostart)
      CommandFile.compute_command_path()
      break
  else:
    Path.set_project_path(show_error=True)
Exemple #7
0
 def settings_update(self, get):
     if get('aliases', 'save_with_project'):
         filename = os.path.join(Path.project_path(), ALIAS_FILE_NAME)
     else:
         filename = os.path.join(os.path.expanduser('~'), ALIAS_DOTFILE_NAME)
     if Aliases.DICT:
         Aliases.DICT.set_filename(filename)
     else:
         Aliases.DICT = PersistentDict(filename)
def _update(echomesh_instance):
    LOGGER.info('Pulling latest codebase from github.')
    directory = os.getcwd()

    try:
        os.chdir(Path.echomesh_path())
        Git.run_git_commands(GIT_UPDATE)
        _initialize(echomesh_instance)
        if not INITIALIZE_ENABLED:
            LOGGER.info('Please restart echomesh to see the updated changes.')
    finally:
        os.chdir(directory)
Exemple #9
0
def _get_files_to_transfer(path):
    files = set()
    directories = set()

    for p in path:
        f = os.path.join(Path.data_path(), p)
        if not os.path.exists(f):
            raise Exception("Command file %s doesn't exist.", f)
        walk = os.walk(f)
        if walk:
            directories.add(p)
            for root, _, fs in walk:
                if not root.startswith('.'):
                    for ffs in fs:
                        if (_TRANSFER_ALL_FILES or
                            DataFileName.has_extension(ffs)):
                            files.add(os.path.join(Path.data_path(), root, ffs))
            LOGGER.vdebug('Transferring directory %s', p)
        else:
            LOGGER.vdebug('Transferring file %s', p)
            files.add(f)

    return _get_files_table(files), directories
Exemple #10
0
def _scores(path, resolve=False, context='all', recursive=False,
            indent='', printed=False, top_level=True):
    if context == 'all':
        for c in Context.CONTEXTS:
            printed = _scores(path, resolve, c, recursive, indent) or printed
    else:
        context = Context.resolve(context)
        pathdir = os.path.join(Path.data_path(), context, 'score', path)
        if os.path.isdir(pathdir):
            printed_this_time = False
            for f in sorted(os.listdir(pathdir)):
                joined_f = os.path.join(pathdir, f)
                is_dir = os.path.isdir(joined_f)
                if not (is_dir or DataFileName.has_extension(f)):
                    continue
                if not printed_this_time:
                    printed_this_time = True
                    if not printed:
                        LOGGER.info(indent + ELEMENT_FORMAT, 'File name',
                                    ' Bytes', 'Accessed', 'Modified', 'Created')
                        printed = True
                    elif top_level:
                        LOGGER.info('\n')
                    if top_level:
                        LOGGER.info('    %s/%s:', context, path)
                if is_dir:
                    if recursive:
                        LOGGER.info('')
                    LOGGER.info('      %s/', f)
                    if recursive:
                        _scores(os.path.join(path, f), resolve, context,
                                recursive, indent + INDENT, printed=True,
                                top_level=False)
                        LOGGER.info('')

                else:
                    stat = os.stat(joined_f)
                    LOGGER.info(indent + ELEMENT_FORMAT,
                                 '    ' + f, SizeName.size_name(stat.st_size),
                                 _time(stat.st_atime),
                                 _time(stat.st_mtime),
                                 _time(stat.st_ctime))
    return printed
Exemple #11
0
def _main():
    import sys

    times = []

    def p(msg=''):
        """Print progress messages while echomesh loads."""
        print(msg, end='\n' if msg else '')
        global COUNT
        dot = str(COUNT % 10) if USE_DIGITS_FOR_PROGRESS_BAR else '.'
        print(dot, end='')
        COUNT += 1

        sys.stdout.flush()

        import time
        times.append(time.time())

    p('Loading echomesh ')

    from echomesh.base import Version
    if Version.TOO_NEW:
        print(Version.ERROR)

    from echomesh.base import Path
    if not Path.project_path():
        return
    p()

    Path.fix_home_directory_environment_variable()
    p()

    Path.fix_sys_path()
    p()

    from echomesh.base import Settings
    p()

    Settings.read_settings(sys.argv[1:])
    p()

    if Settings.get('execution', 'autostart') and not Settings.get(
            'permission', 'autostart'):
        print()
        from echomesh.util import Log
        Log.logger(__name__).info('No permission to autostart')
        return
    p()

    from echomesh.base import Quit
    p()

    Quit.register_atexit(Settings.save)
    p()

    from echomesh.Instance import Instance
    p()

    instance = Instance()
    print()
    p()

    if Settings.get('diagnostics', 'startup_times'):
        print()
        for i in range(len(times) - 1):
            print(i, ':', int(1000 * (times[i + 1] - times[i])))
        print()

    instance.main()
Exemple #12
0
from __future__ import absolute_import, division, print_function, unicode_literals

from echomesh.base import Path

Path.fix_sys_path()

import unittest

class TestCase(unittest.TestCase):
    EPSILON = 0.000001

    def assertNear(self, x, y, msg=None):
        try:
            lx, ly = len(x), len(y)
        except:
            self.assertTrue(abs(x - y) < self.EPSILON,
                            msg or ('%s != %s' % (x, y)))
        else:
            self.assertEquals(lx, ly)
            for xi, yi in zip(x, y):
                self.assertNear(xi, yi, msg)

main = unittest.main
Exemple #13
0
def directories(_):
    _info(Path.info())
Exemple #14
0
from __future__ import absolute_import, division, print_function, unicode_literals

from echomesh.base import Path

Path.fix_sys_path(show_error=False, prompt=False)

import unittest

class TestCase(unittest.TestCase):
    EPSILON = 0.000001

    def assertNear(self, x, y, msg=None):
        try:
            lx, ly = len(x), len(y)
        except:
            self.assertTrue(abs(x - y) < self.EPSILON,
                            msg or ('%s != %s' % (x, y)))
        else:
            self.assertEquals(lx, ly)
            for xi, yi in zip(x, y):
                self.assertNear(xi, yi, msg)

main = unittest.main