简单小练习_切换工作空间

#make space -> choose space -> switch space
# how we start OOP ? -->space

'''
folder
choose = input()

if choose == workspace.name:
    workspace.switch()
'''
from sconfig import CONFIGS
from subprocess import call
import os

class Workspace:
    
    def __init__(self, c):
        self.folders = c['folders']
        self.name = c['name']
        self.target = c['target']
    def switch(self):
        for link in os.listdir(self.target):
            if f.endswith('.wspc'):
                path = self.target + f
                os.remove(path)
        #mklink
        for source in self.folders:
            real_target = self.target + source.split('/')[-1] + '.wspc'
            commands = ['ln','-s',source,real_target]
            call(commands)

w = Workspace([1,2,3])

w2 = Workspace([4,5,6])

workspace = [Workspace(c) for c in CONFIGS]

print('pleace choice u workspace')
choice = input()
for w in workspace:
    if w.name ==choice:
        w.switch()

print(w.folders)
print(w2.folders)

 

sconfig.py

CONFIGS = [
    {
        'name':'WORK',
        'folders':[
            '/User/zhangfulong/Desktop/Pdf',
            '/User/zhangfulong/Desktop/Bookmarks',
        ],
        'target':'/User/zhangfulong/Desktop/'
    },

    {
        'name':'PLAY',
        'folders':[
            '/User/zhangfulong/Desktop/Video',
            '/User/zhangfulong/Desktop/Codes',
        ],
        'target':'/User/zhangfulong/Desktop/'
    },


]

 

posted @ 2018-06-25 13:35  Erick-LONG  阅读(113)  评论(0编辑  收藏  举报