forked from GustavePate/lycheesync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
132 lines (110 loc) · 4.81 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/python
# -*- coding: utf-8 -*-
from lycheesyncer import LycheeSyncer
from update_scripts import inf_to_lychee_2_6_2
import argparse
import os
import sys
import json
import pwd
import grp
def main(conf):
""" just call to LycheeSyncer """
# DELEGATE WORK TO LYCHEESYNCER
s = LycheeSyncer(conf)
s.sync()
def show_args():
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "Program Launched with args:"
print "* dropDB:" + str(args.dropdb)
print "* replace:" + str(args.replace)
print "* verbose:" + str(args.verbose)
print "* srcdir:" + args.srcdir
print "* lycheepath:" + args.lycheepath
print "* conf:" + args.conf
print "* sort_by_name:" + str(conf_data['sort'])
print "* link:" + str(conf_data['link'])
print "Program Launched with conf:"
print "* dbHost:" + conf_data['dbHost']
print "* db:" + conf_data['db']
print "* dbUser:" + conf_data['dbUser']
print "* dbPassword:" + conf_data['dbPassword']
print "* thumbQuality:" + str(conf_data['thumbQuality'])
print "* publicAlbum:" + str(conf_data['publicAlbum'])
print "Other conf elements:"
print "* user:" + str(conf_data["user"])
print "* group:" + str(conf_data["group"])
print "* uid:" + str(conf_data["uid"])
print "* gid:" + str(conf_data["gid"])
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if __name__ == '__main__':
# ARGUMENTS PARSING
# AND CONFIGURATION FILE READING
parser = argparse.ArgumentParser(description=("Add all files in a directory to lychee. " +
"sub directories are albums and files are photos"))
parser.add_argument('srcdir', help='directory to enslave lychee with', type=str)
parser.add_argument('lycheepath', help='lychee installation directory', type=str)
parser.add_argument('conf', help='lychee db configuration file', type=str)
parser.add_argument('-d', '--dropdb', help=("drop lychee db " +
"and populate it with directory content"), action='store_true')
parser.add_argument('-r', '--replace', help=("drop albums corresponding to srcdir structure " +
"but don t drop the entire db"), action='store_true')
parser.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true')
parser.add_argument('-s', '--sort_album_by_name', help='sort album display by name', action='store_true')
parser.add_argument('-l', '--link', help='do not copy photos to lychee uploads directory, just create a symlink', action='store_true')
parser.add_argument('-u', '--updatedb26', action='store_const', dest='updatedb_to_version_2_6_2', const='2.6.2', help='Update lycheesync added data in lychee db to the lychee 2.6.2 required values')
args = parser.parse_args()
shouldquit = False
if (args.replace and args.dropdb):
shouldquit = True
print "you have to choose between replace and dropdb behaviour"
if not os.path.exists(os.path.join(args.lycheepath, 'uploads')):
shouldquit = True
print "lychee install path may be wrong:" + args.lycheepath
if not os.path.exists(args.conf):
shouldquit = True
print "configuration file does not exist:" + args.conf
else:
conf_file = open(args.conf, 'r')
conf_data = json.load(conf_file)
conf_file.close()
if args.updatedb_to_version_2_6_2:
print "updatedb"
elif not os.path.exists(args.srcdir):
shouldquit = True
print "photo directory does not exist:" + args.srcdir
if shouldquit:
sys.exit(1)
conf_data["srcdir"] = args.srcdir
conf_data["lycheepath"] = args.lycheepath
conf_data["dropdb"] = args.dropdb
conf_data["replace"] = args.replace
conf_data["verbose"] = args.verbose
conf_data["updatedb"] = args.updatedb_to_version_2_6_2
conf_data["user"] = None
conf_data["group"] = None
conf_data["uid"] = None
conf_data["gid"] = None
conf_data["sort"] = args.sort_album_by_name
conf_data["link"] = args.link
if conf_data["dropdb"]:
conf_data["sort"] = True
if conf_data["updatedb"] == "2.6.2":
if args.verbose:
show_args()
inf_to_lychee_2_6_2.updatedb(conf_data)
else:
# read permission of the lycheepath directory to apply it to the uploade photos
img_path = os.path.join(conf_data["lycheepath"], "uploads")
stat_info = os.stat(img_path)
uid = stat_info.st_uid
gid = stat_info.st_gid
user = pwd.getpwuid(uid)[0]
group = grp.getgrgid(gid)[0]
conf_data["user"] = user
conf_data["group"] = group
conf_data["uid"] = uid
conf_data["gid"] = gid
if args.verbose:
show_args()
main(conf_data)