Created
February 10, 2016 19:32
-
-
Save takuya/52c71a07b84cb64cc7f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding:utf-8 -*= | |
import os | |
import subprocess | |
from datetime import datetime | |
from glob import glob | |
import argparse | |
target = os.path.expanduser("~/.Desktops") | |
parser = argparse.ArgumentParser(description=u'デスクトップのフォルダを作成して切り替える') | |
parser.add_argument("-n", "--new", action=u"append", help=u"デスクトップフォルダ作成して移動" ,nargs="*") | |
parser.add_argument("-c", "--change", action=u"append", help=u"デスクトップを移動" ,nargs="*") | |
parser.add_argument("-l", "--list", action=u"store_true", help=u"現在の保存済デスクトップ一覧") | |
parser.add_argument("-i", "--init", action=u"store_true", help=u"初期化:現在のデスクトップをリンク化して管理下に置く") | |
args = parser.parse_args() | |
if vars(args)["new"] : | |
if vars(args)["new"][0][0] == None : | |
name = datetime.now().strftime("%Y-%m-%d_%H_%M_%S") | |
else: | |
name = vars(args)["new"][0][0] | |
new_dir_name = target + "/" + name | |
if os.path.exists(new_dir_name): | |
print (" ディレクトリ <%s> この名前はすでに存在しますね" % name) | |
exit(1); | |
current = target + "/" + "current" | |
os.mkdir( new_dir_name ) | |
if os.path.lexists( current ) : | |
os.unlink(current) | |
os.symlink( new_dir_name, current) | |
subprocess.call("killall Finder", shell=True) | |
elif vars(args)["list"] : | |
os.chdir(target) | |
list = glob("*") | |
list.remove("current") | |
for x in list : | |
print(x) | |
elif vars(args)["change"] : | |
if len(vars(args)["change"][0]) == 0 : | |
os.chdir(target) | |
list = glob("*") | |
list.remove("current") | |
for x in list : | |
print(x) | |
exit(0) | |
name = vars(args)["change"][0][0] | |
change_dir = target + "/" + name | |
if os.path.exists(change_dir) == False: | |
print (" ターゲットが存在しない:ディレクトリ <%s> " % name) | |
exit(1); | |
current = target + "/" + "current" | |
if os.path.lexists( current ) : | |
os.unlink(current) | |
os.symlink( change_dir, current) | |
subprocess.call("killall Finder", shell=True) | |
elif vars(args)["init"]: | |
if os.path.exists(target) == False : | |
os.mkdir(target) | |
if os.path.islink(os.path.expanduser("~/Desktop")) == True : | |
print("~/Desktop はリンクです") | |
exit(0) | |
else: | |
os.rename( os.path.expanduser("~/Desktop"), target +"/Desktop" ) | |
current = target + "/current" | |
if os.path.exists(current) : | |
os.unlink(current) | |
os.symlink(current, os.path.expanduser("~/Desktop")) | |
os.symlink(target+"/Desktop", current) | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment