Mercurial > hg > Members > kent > dotfiles
annotate symlink.py @ 1:c8c579f62d99
add rc files that have relation with mailer.
and symlink.py was modified as adding subroutin that make
hardlink for fetchmailrc.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 15 Nov 2008 00:57:04 +0900 |
parents | 6d5c73fe5744 |
children | 0f43fb312bd6 |
rev | line source |
---|---|
0
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 # vim:fileencoding=utf-8 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 import re |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 import os |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 import sys |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 import ConfigParser |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 home = os.environ['HOME'] |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 etcdir = os.getcwd() |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 dir = re.match( home+"/(.*)", etcdir).group(1) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 force = False |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 def main(): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 # read configuration file |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 config = ConfigParser.ConfigParser() |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 config.read( 'install.cfg') |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 opts = config.items('InstallFiles', 0) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 # loop all options |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 for opt in opts: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 value = opt[1].split(':') |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 if value[0] == "SYM": |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 if len(value) > 1: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 makeSymlink(opt[0], value[1]) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 else: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 makeSymlink(opt[0]) |
1
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
28 elif value[0] == "LNK": |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
29 if len(value) > 1: |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
30 makeHardlink(opt[0], value[1]) |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
31 else: |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
32 makeHardlink(opt[0]) |
0
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 ### make symbolic link dst0 relating with src0 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 def makeSymlink(src0, dst0=None): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 # correct filename of source and destination |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 if dst0==None: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 dst0 = "."+src0 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 src = dir+"/"+src0 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 dst = home+"/"+dst0 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 # check destination file |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 if os.path.exists(dst): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 if force: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 os.remove(dst) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 else: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 print "file "+dst+" already existed!" |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 return |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 # make symbolic link |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 print dst+" => "+src |
1
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
53 os.symlink(src, dst) |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
54 |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
55 ### make hardlink dst0 relating with src0 |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
56 def makeHardlink(src0, dst0=None): |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
57 # correct filename of source and destination |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
58 if dst0==None: |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
59 dst0 = "."+src0 |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
60 src = src0 |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
61 dst = home+"/"+dst0 |
0
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 |
1
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
63 # check destination file |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
64 if os.path.exists(dst): |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
65 if force: |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
66 os.remove(dst) |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
67 else: |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
68 print "file "+dst+" already existed!" |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
69 return |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
70 |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
71 # make symbolic link |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
72 print dst+" => "+src |
c8c579f62d99
add rc files that have relation with mailer.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
73 os.link(src, dst) |
0
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 main() |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 ### てすとるーちん ### |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 def listingFromArgs(): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 del sys.argv[0] |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 for file in sys.argv: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 makeSymlink(file) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 def listingFromDir(): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 files = os.listdir(".") |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 for file in files: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 correctFilename(file) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 def correctFilename(filename): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 result = re.match( "DoT-(.*)", filename); |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 if result!=None: |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 dst = result.group(1) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 print filename+" => "+dst |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 os.rename(filename, dst) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 #listingFromDir() |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 #listingFromArgs() |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 # test |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 #master = [10, 20, 30] |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 #listing( master, 20 ) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 #listing( master, 20 ) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 def listing(a, b): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 i=0; |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 print "b = "+str(b) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 print "len(a) = "+str(len(a)) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 while i<len(a): |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 print "a["+str(i)+"] = "+str(a[i]) |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 a[i] = a[i] + 5 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 i = i+1 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 |
6d5c73fe5744
Go over to mercurial from CVS.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 |