1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 r"""A high-performance client to the SmugMug API.
22
23 This client supports the entire set of methods available through smugmug
24 both serially and in batch.
25
26 References:
27 - U{pysmug <http://code.google.com/p/pysmug>}
28 - U{SmugMug API <http://smugmug.jot.com/WikiHome/API/Versions/1.2.1>}
29 """
30
31 __version__ = "0.2"
32
33 from pysmug.smugmug import SmugMug, SmugBatch, SmugMugException, HTTPException
34
36 """Login to smugmug using the contents of the configuration file.
37
38 If no configuration file specified then a file named C{.pysmugrc} in
39 the user's home directory is used if it exists.
40
41 The following order determines the C{login} method used:
42
43 - B{In all cases C{APIKey} is required.}
44
45 1. If C{PasswordHash} is in configuration, then C{login_withHash} is used.
46 - C{UserID} is additionally required.
47 2. If C{Password} is in configuration, then C{login_withPassword} is used.
48 - C{EmailAddress} is additionally required.
49 3. Else C{login_anonymously} is used.
50
51 @param conf: path to a configuration file
52 @raise ValueError: if no configuration file is found
53 """
54
55 import os
56 if not conf:
57 home = os.environ.get("HOME", None)
58 if not home:
59 raise ValueError("unknown home directory")
60 conf = os.path.join(home, ".pysmugrc")
61 if not os.path.exists(conf):
62 raise ValueError("'%s' not found" % (conf))
63 config = eval(open(conf).read())
64 m = SmugMug()
65 if "PasswordHash" in config:
66 return m.login_withHash(**config)
67 elif "Password" in config:
68 return m.login_withPassword(**config)
69 return m.login_anonymously(**config)
70