Exemplo n.º 1
0
    def cli(self, *args):
        '''
        Imitate calling the command line tool with the given args
        '''
        TRACELOG(*args)
        if len(args) == 1 and ' ' in args[0]:
            return self.cli(*args[0].split())

        with self.environment:
            with CaptureStdout() as stdout, CaptureStderr() as stderr:
                try:
                    self.retval = run(''.__class__(self.config_dir), args)
                    assert self.retval == 0
                except BaseException as e:
                    TRACELOG(EXCEPTION=e)
                    raise
                finally:
                    # invalidate zip file cache
                    # it would prevent deleting opened files on windows
                    # and would keep zip files open, even after they are removed on unix
                    bead.zipopener.close_all()

                    self.stdout = stdout.text
                    self.stderr = stderr.text
                    #
                    if self.stdout:
                        TRACELOG(STDOUT=self.stdout)
                    if self.stderr:
                        TRACELOG(STDERR=self.stderr)
Exemplo n.º 2
0
 def cd(self, dir):
     '''
     Change to directory
     '''
     self.cwd = self._path(dir)
     TRACELOG(dir, realdir=self.cwd)
     assert os.path.isdir(self.cwd)
Exemplo n.º 3
0
    def reset(self):
        '''
        Forget all boxes by removing the user's config.

        All other files, workspaces remain available.
        '''
        TRACELOG('rmtree', self.config_dir)
        tech.fs.rmtree(self.config_dir)
Exemplo n.º 4
0
 def load_cache(self):
     try:
         try:
             self.cache = persistence.loads(self.cache_path.read_text())
         except persistence.ReadError:
             TRACELOG(
                 f"Ignoring existing, malformed bead meta cache {self.cache_path}"
             )
     except FileNotFoundError:
         pass
Exemplo n.º 5
0
    def least_recently_used_filename(self):
        def access_time(filename_access_time: Tuple[FileName, LogicalTime]):
            _, access_time = filename_access_time
            return access_time

        least_recently_used_filename, _ = sorted(self.access_times.items(),
                                                 key=access_time)[0]
        TRACELOG(
            f'{least_recently_used_filename}: {self.access_times[least_recently_used_filename]}'
        )
        return least_recently_used_filename
Exemplo n.º 6
0
 def store(self, workspace, timestamp):
     # -> Bead
     zipfilename = (
         self.directory / (
             '{bead_name}_{timestamp}.zip'
             .format(
                 bead_name=workspace.bead_name,
                 timestamp=timestamp)))
     workspace.pack(zipfilename, timestamp=timestamp, comment=ARCHIVE_COMMENT)
     TRACELOG('store as archive', zipfilename)
     return Archive(zipfilename)
Exemplo n.º 7
0
 def cli(self, *args):
     '''
     Imitate calling the command line tool with the given args
     '''
     TRACELOG(*args)
     with self.environment:
         with CaptureStdout() as stdout, CaptureStderr() as stderr:
             try:
                 self.retval = run(''.__class__(self.config_dir), args)
             except BaseException as e:
                 TRACELOG(EXCEPTION=e)
                 raise
             finally:
                 self.stdout = stdout.text
                 self.stderr = stderr.text
                 #
                 if self.stdout:
                     TRACELOG(STDOUT=self.stdout)
                 if self.stderr:
                     TRACELOG(STDERR=self.stderr)
Exemplo n.º 8
0
 def _new_bead(self, robot, beads, bead_name, inputs=None):
     robot.cli('new', bead_name)
     robot.cd(bead_name)
     robot.write_file('README', bead_name)
     robot.write_file('output/README', bead_name)
     self._add_inputs(robot, inputs)
     box = self.box(robot)
     with robot.environment:
         TRACELOG('store', robot.cwd, TS1, 'to', box.location)
         beads[bead_name] = Archive(box.store(Workspace('.'), TS1))
     robot.cd('..')
     robot.cli('zap', bead_name)
     return bead_name
Exemplo n.º 9
0
def order_and_limit_beads(beads, order=bead_spec.NEWEST_FIRST, limit=None):
    '''
    Order beads by timestamps and keep only the closest ones.
    '''
    TRACELOG(beads, order, limit)

    # wrap beads so that they can be compared by timestamps
    compare_wrap = {
        bead_spec.NEWEST_FIRST: _ReverseCompare,
        bead_spec.OLDEST_FIRST: _Compare,
    }[order]
    comparable_beads = (compare_wrap(bead) for bead in beads)

    if limit:
        # assume we have lots of beads, so do it with memory limited
        wrapped_results = heapq.nsmallest(limit, comparable_beads)
        TRACELOG([_.bead.timestamp_str for _ in wrapped_results])
    else:
        wrapped_results = sorted(comparable_beads)

    # unwrap wrapped_results
    return [_.bead for _ in wrapped_results]
Exemplo n.º 10
0
 def setUp(self):
     super(Robot, self).setUp()
     self.base_dir = self.useFixture(TempDir()).path
     TRACELOG('makedirs', self.home)
     os.makedirs(self.home)
     self.cd(self.home)
Exemplo n.º 11
0
 def write_file(self, path, content):
     assert not os.path.isabs(path)
     TRACELOG(path, content, realpath=self.cwd / path)
     tech.fs.write_file(self.cwd / path, content)
Exemplo n.º 12
0
def _cleanup():
    TRACELOG(vars(_cache))
    close_all()
Exemplo n.º 13
0
 def close(self, filename):
     TRACELOG(f'{filename}')
     self.open_zip_files[filename].close()
     del self.open_zip_files[filename]
     del self.access_times[filename]
Exemplo n.º 14
0
 def access(self, filename):
     TRACELOG(f'{filename}: {self.access_count}')
     self.access_times[filename] = self.access_count
     self.access_count += 1
Exemplo n.º 15
0
 def tearDown(self, *args, **kwargs):
     super(TestCase, self).tearDown(*args, **kwargs)
     TRACELOG(self.__class__.__module__, self.__class__.__name__)
Exemplo n.º 16
0
 def setUp(self, *args, **kwargs):
     super(TestCase, self).setUp(*args, **kwargs)
     TRACELOG(self.__class__.__module__, self.__class__.__name__)