예제 #1
0
    def test_add_existing(self):

        here = os.path.abspath(os.path.join(__file__, '..', '..'))

        src1 = os.path.join(here, 'doesnotexist1')
        src2 = os.path.join(here, 'doesnotexist2')
        dst = os.path.join(here, 'dirmap')

        map_ = DirMap()
        map_.add_existing((src1, dst, src2))

        self.assertEqual(map_(src1), dst)
        self.assertEqual(map_(src2), dst)

        self.assertRaises(ValueError, map_.add_existing, [src1])  # Just one.
        self.assertRaises(ValueError, map_.add_existing, [src1],
                          dst)  # Wrong API use.
        self.assertRaises(ValueError, map_.add_existing,
                          [src1, src2])  # Nothing exists.
        self.assertRaises(ValueError, map_.add_existing,
                          [src1, dst + '/..'])  # Unclean.
예제 #2
0
    def run(self):

        self.dirmap = DirMap(self._dirmap) if self._dirmap else None

        for root in self.roots:

            root = os.path.abspath(root)
            if self.recurse:
                for path, _, _ in os.walk(root):
                    self.repair_path(path)
            else:
                self.repair_path(root)
예제 #3
0
    def test_deep_apply(self):

        map_ = DirMap({'/src': '/dst'})

        # Basics
        x = map_.deep_apply({
            '/src/key': ['/src/listitem'],
            'tuple': ('/src/tupleitem', ),
            'set': set(['/src/setitem']),
        })
        self.assertEqual(
            x, {
                '/src/key': ['/dst/listitem'],
                'tuple': ('/dst/tupleitem', ),
                'set': set(['/dst/setitem']),
            })

        # Include dict keys.
        x = map_.deep_apply({'/src': '/src'}, dict_keys=True)
        self.assertEqual(x, {'/dst': '/dst'})

        # Dict recursion
        a = {}
        a['/src'] = a
        b = map_.deep_apply(a, dict_keys=True)
        self.assertEqual(b.keys(), ['/dst'])
        self.assertIs(b['/dst'], b)

        # List recursion
        a = ['/src']
        a.append(a)
        b = map_.deep_apply(a)
        self.assertEqual(b[0], '/dst')
        self.assertIs(b[1], b)
예제 #4
0
    def test_basics(self):

        map_ = DirMap([
            ('/src', '/dst'),
            ('/src/inner', '/dst2/inner'),
            ('/src3', '/dst3'),
        ])

        self.assertEqual(map_('/path/to/thing'), '/path/to/thing')

        self.assertEqual(map_('/src'), '/dst')
        self.assertEqual(map_('/src/inner'), '/dst2/inner')
        self.assertEqual(map_('/src3'), '/dst3')
        self.assertEqual(map_('/src/another'), '/dst/another')
예제 #5
0
파일: session.py 프로젝트: vfxetc/sgsession
 def dir_map(self):
     return DirMap(self._dir_map or os.environ.get('SGSESSION_DIR_MAP'))
예제 #6
0
 def test_empty(self):
     map_ = DirMap()
     self.assertEqual(len(map_), 0)
     self.assertEqual(map_('/path/to/thing'), '/path/to/thing')
예제 #7
0
파일: remote.py 프로젝트: loftysky/mmmaya
    # Pick which style of offline we're using.
    offline_boot = '/Volumes/{}.offline'.format(name)
    offline_disk = '/Volumes/offline/{}'.format(name)
    if os.path.exists(offline_disk):
        offline = offline_disk
    else:
        offline = offline_boot

    to_online[bare] = online
    to_online[offline_boot] = online
    to_online[offline_disk] = online

    to_offline[bare] = offline
    to_offline[online] = offline

to_online = DirMap(to_online)
to_offline = DirMap(to_offline)


def make_offline_copies():

    for node_type, attr_name, getter, setter in file_node_attributes:

        nodes = cmds.ls(type=node_type) if node_type else [None]
        if not nodes:
            print 'No {} nodes.'.format(node_type)
            continue

        for node in nodes:

            raw_path = getter(node) if getter else cmds.getAttr(node + '.' +