예제 #1
0
 def bead(self, timestamp):
     tmp = self.new_temp_dir()
     ws = Workspace(tmp / 'ws')
     ws.create('bead-uuid')
     bead_archive = tmp / 'bead.zip'
     ws.pack(bead_archive, timestamp, comment='bead for a shared box')
     return bead_archive
예제 #2
0
 def make_bead(timestamp):
     with TempDir() as tempdir_obj:
         workspace_dir = os.path.join(tempdir_obj.path, bead_name)
         ws = Workspace(workspace_dir)
         ws.create(bead_uuid)
         sentinel_file = ws.directory / 'sentinel-{}'.format(timestamp)
         tech.fs.write_file(sentinel_file, timestamp)
         box.store(ws, timestamp)
         tech.fs.rmtree(workspace_dir)
예제 #3
0
 def make_bead(timestamp):
     with TempDir() as tempdir_obj:
         workspace_dir = os.path.join(tempdir_obj.path, bead_name)
         ws = Workspace(workspace_dir)
         ws.create(bead_kind)
         sentinel_file = ws.directory / f'sentinel-{timestamp}'
         tech.fs.write_file(sentinel_file, timestamp)
         tech.fs.write_file(ws.directory / 'output/README', timestamp)
         box.store(ws, timestamp)
         tech.fs.rmtree(workspace_dir)
예제 #4
0
 def make_bead(freeze_time):
     with TempDir() as tempdir_obj:
         workspace_dir = os.path.join(tempdir_obj.path, bead_name)
         ws = Workspace(workspace_dir)
         ws.create(bead_kind)
         sentinel_file = ws.directory / f'sentinel-{freeze_time}'
         tech.fs.write_file(sentinel_file, freeze_time)
         tech.fs.write_file(ws.directory / 'output/README', freeze_time)
         box.store(ws, freeze_time)
         tech.fs.rmtree(workspace_dir)
예제 #5
0
 def make_bead(timestamp):
     with TempDir() as tempdir_obj:
         workspace_dir = os.path.join(tempdir_obj.path, bead_name)
         ws = Workspace(workspace_dir)
         ws.create(bead_kind)
         sentinel_file = ws.directory / 'sentinel-{}'.format(timestamp)
         tech.fs.write_file(sentinel_file, timestamp)
         tech.fs.write_file(ws.directory / 'output/README', timestamp)
         box.store(ws, timestamp)
         tech.fs.rmtree(workspace_dir)
예제 #6
0
 def test_load_only_one_input(self, robot, bead_with_inputs, bead_a):
     robot.cli('develop', bead_with_inputs)
     robot.cd(bead_with_inputs)
     robot.cli('input', 'load', 'input_a')
     self.assert_loaded(robot, 'input_a', bead_a)
     with robot.environment:
         self.assertFalse(Workspace('.').is_loaded('input_b'))
예제 #7
0
    def run(self, args):
        extract_output = args.extract_output
        env = args.get_env()
        try:
            bead = resolve_bead(env, args.bead_ref_base, args.bead_time)
        except LookupError:
            die('Bead not found!')
        try:
            verify_with_feedback(bead)
        except InvalidArchive:
            die('Bead is damaged')
        if args.workspace is DERIVE_FROM_BEAD_NAME:
            workspace = Workspace(bead.name)
        else:
            workspace = args.workspace

        if os.path.exists(workspace.directory):
            die(f'Workspace "{workspace.name}" directory already exists'
                ' - do you have an old checkout?')
        bead.unpack_to(workspace)
        assert workspace.is_valid

        if extract_output:
            output_directory = workspace.directory / layouts.Workspace.OUTPUT
            bead.unpack_data_to(output_directory)

        print(f'Extracted source into {workspace.directory}')
        # XXX: try to load smaller inputs?
        if workspace.inputs:
            print('Input data not loaded, update if needed and load manually')
예제 #8
0
 def hacked_bead(self, robot, beads):
     hacked_bead_path = self.new_temp_dir() / 'hacked_bead.zip'
     workspace_dir = self.new_temp_dir() / 'hacked_bead'
     ws = Workspace(workspace_dir)
     ws.create('hacked-kind')
     tech.fs.write_file(ws.directory / 'code', 'code')
     tech.fs.write_file(ws.directory / 'output/README', 'README')
     ws.pack(hacked_bead_path, TS1, comment='hacked bead')
     with zipfile.ZipFile(hacked_bead_path, 'a') as z:
         with warnings.catch_warnings():
             warnings.simplefilter('ignore')
             # this would cause a warning from zipfile for duplicate
             # name in zip file (which is perfectly valid, though hacky)
             z.writestr(layouts.Archive.CODE / 'code', 'HACKED')
             z.writestr(layouts.Archive.DATA / 'README', 'HACKED')
     return hacked_bead_path
예제 #9
0
파일: workspace.py 프로젝트: judit-b/bead
    def run(self, args):
        extract_output = args.extract_output
        env = args.get_env()
        try:
            bead = resolve_bead(env, args.bead_ref_base, args.bead_time)
        except LookupError:
            die('Bead not found!')
        if not bead.is_valid:
            die('Bead is found but damaged')
        if args.workspace is DERIVE_FROM_BEAD_NAME:
            workspace = Workspace(bead.name)
        else:
            workspace = args.workspace

        bead.unpack_to(workspace)
        assert workspace.is_valid

        if extract_output:
            output_directory = workspace.directory / layouts.Workspace.OUTPUT
            bead.unpack_data_to(output_directory)

        print('Extracted source into {}'.format(workspace.directory))
        # XXX: try to load smaller inputs?
        if workspace.inputs:
            print('Input data not loaded, update if needed and load manually')
예제 #10
0
    def test_extract_output(self, robot, bead_a):
        robot.cli('develop', '-x', bead_a)
        ws = robot.cwd / bead_a

        assert Workspace(ws).is_valid

        # output must be unpacked as well!
        self.assert_file_contains(ws / layouts.Workspace.OUTPUT / 'README',
                                  bead_a)
예제 #11
0
def OPTIONAL_WORKSPACE(parser):
    '''
    Define `workspace` as option, defaulting to current directory
    '''
    parser.arg('--workspace',
               '-w',
               metavar=arg_metavar.WORKSPACE,
               type=Workspace,
               default=Workspace.for_current_working_directory(),
               help=arg_help.WORKSPACE)
예제 #12
0
 def test_save_stores_bead_in_specified_box(self, robot, box1, box2):
     robot.cli('new', 'bead')
     robot.cli('save', box1.name, '--workspace=bead')
     with robot.environment:
         kind = Workspace('bead').kind
     assert 1 == bead_count(box1, kind)
     assert 0 == bead_count(box2, kind)
     robot.cli('save', box2.name, '-w', 'bead')
     assert 1 == bead_count(box1, kind)
     assert 1 == bead_count(box2, kind)
예제 #13
0
    def test_extract_output(self, robot, bead_a):
        robot.cli('develop', '-x', bead_a)
        ws = robot.cwd / bead_a

        self.assertTrue(Workspace(ws).is_valid)

        # output must be unpacked as well!
        self.assertThat(
            ws / layouts.Workspace.OUTPUT / 'README',
            FileContains(bead_a))
예제 #14
0
 def test_save_stores_bead_in_specified_box(self, robot, box1, box2):
     robot.cli('new', 'bead')
     robot.cli('save', box1.name, '--workspace=bead')
     with robot.environment:
         kind = Workspace('bead').kind
     self.assertEquals(1, bead_count(robot, box1, kind))
     self.assertEquals(0, bead_count(robot, box2, kind))
     robot.cli('save', box2.name, '-w', 'bead')
     self.assertEquals(1, bead_count(robot, box1, kind))
     self.assertEquals(1, bead_count(robot, box2, kind))
예제 #15
0
 def bead(self, timestamp):
     tmp = self.new_temp_dir()
     ws = Workspace(tmp / 'ws')
     ws.create('a bead kind')
     bead_archive = tmp / 'bead.zip'
     ws.pack(bead_archive, timestamp, comment='bead for a shared box')
     return bead_archive
예제 #16
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
예제 #17
0
    def test_update_unloaded_input_w_another_bead(self, robot,
                                                  bead_with_inputs, bead_a,
                                                  bead_b):
        robot.cli('develop', bead_with_inputs)
        robot.cd(bead_with_inputs)

        assert not Workspace(robot.cwd).is_loaded('input_b')

        robot.cli('input', 'update', 'input_b', bead_a)
        self.assert_loaded(robot, 'input_b', bead_a)

        robot.cli('status')
        self.assertThat(robot.stdout, Not(Contains(bead_b)))
예제 #18
0
def _check_load_with_feedback(workspace: Workspace, input_nick, bead):
    try:
        verify_with_feedback(bead)
    except InvalidArchive:
        warning(f'Bead for {input_nick} is found but damaged - not loading.')
    else:
        workspace.set_input_bead_name(input_nick, bead.name)
        if workspace.is_loaded(input_nick):
            print(f'Removing current data from {input_nick}')
            workspace.unload(input_nick)
        print(f'Loading new data to {input_nick} ...', end='', flush=True)
        workspace.load(input_nick, bead)
        print(' Done')
예제 #19
0
 def hacked_bead(self, robot, beads):
     hacked_bead_path = self.new_temp_dir() / 'hacked_bead.zip'
     workspace_dir = self.new_temp_dir() / 'hacked_bead'
     ws = Workspace(workspace_dir)
     ws.create('hacked-kind')
     tech.fs.write_file(ws.directory / 'code', 'code')
     tech.fs.write_file(ws.directory / 'output/README', 'README')
     ws.pack(hacked_bead_path, TS1, comment='hacked bead')
     with zipfile.ZipFile(hacked_bead_path, 'a') as z:
         with warnings.catch_warnings():
             warnings.simplefilter('ignore')
             # this would cause a warning from zipfile for duplicate
             # name in zip file (which is perfectly valid, though hacky)
             z.writestr(layouts.Archive.CODE / 'code', 'HACKED')
             z.writestr(layouts.Archive.DATA / 'README', 'HACKED')
     return hacked_bead_path
예제 #20
0
 def declare(self, arg):
     arg(WORKSPACE_defaulting_to(Workspace.for_current_working_directory()))
예제 #21
0
 def test_add_with_hacked_bead_is_refused(self, robot, hacked_bead, bead_a):
     robot.cli('develop', bead_a)
     robot.cd(bead_a)
     robot.cli('input', 'add', 'hack', hacked_bead)
     self.assertFalse(Workspace(robot.cwd).has_input('hack'))
     self.assertThat(robot.stderr, Contains('WARNING'))
예제 #22
0
 def declare(self, arg):
     arg(WORKSPACE_defaulting_to(Workspace.for_current_working_directory()))
예제 #23
0
    def test_by_name(self, robot, bead_a):
        robot.cli('develop', bead_a)

        self.assertTrue(Workspace(robot.cwd / bead_a).is_valid)
        self.assertThat(robot.cwd / bead_a / 'README', FileContains(bead_a))
예제 #24
0
    def test_by_name(self, robot, bead_a):
        robot.cli('develop', bead_a)

        assert Workspace(robot.cwd / bead_a).is_valid
        self.assert_file_contains(robot.cwd / bead_a / 'README', bead_a)