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.3"
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 @type klass: C{SmugMug} class
53 @param klass: class to instantiate
54 @param proxy: address of proxy server if one is required (http[s]://localhost[:8080])
55 @raise ValueError: if no configuration file is found
56 """
57
58 import os
59 if not conf:
60 home = os.environ.get("HOME", None)
61 if not home:
62 raise ValueError("unknown home directory")
63 conf = os.path.join(home, ".pysmugrc")
64 if not os.path.exists(conf):
65 raise ValueError("'%s' not found" % (conf))
66 config = eval(open(conf).read())
67 m = klass(proxy=proxy)
68 keys = set(x.lower() for x in config.keys())
69 if "passwordhash" in keys:
70 return m.login_withHash(**config)
71 elif "password" in keys:
72 return m.login_withPassword(**config)
73 return m.login_anonymously(**config)
74