19
19
NS_FOAF = Namespace ("http://xmlns.com/foaf/0.1/" )
20
20
21
21
MONEY = {
22
- 'at' : 'euro' ,
23
- 'be' : 'euro' ,
24
- 'fi' : 'euro' ,
25
- 'de' : 'euro' ,
26
- 'es' : 'euro' ,
27
- 'fr' : 'euro' ,
28
- 'gr' : 'euro' ,
29
- 'ie' : 'euro' ,
30
- 'it' : 'euro' ,
31
- 'lu' : 'euro' ,
32
- 'nl' : 'euro' ,
33
- 'pt' : 'euro' }
22
+ "at" : "euro" ,
23
+ "be" : "euro" ,
24
+ "fi" : "euro" ,
25
+ "de" : "euro" ,
26
+ "es" : "euro" ,
27
+ "fr" : "euro" ,
28
+ "gr" : "euro" ,
29
+ "ie" : "euro" ,
30
+ "it" : "euro" ,
31
+ "lu" : "euro" ,
32
+ "nl" : "euro" ,
33
+ "pt" : "euro" ,
34
+ }
34
35
35
36
36
37
def checkout_base ():
37
38
"""Return the base destination path. Note that this assumes you're
38
39
running the tool from a Subversion checkout (or that your filesystem
39
40
layout is the same as our repository)."""
40
41
41
-
42
42
return os .path .abspath (
43
- os .path .join (os .path .dirname (__file__ ), '..' , '..' , '..' )
44
- )
43
+ os .path .join (os .path .dirname (__file__ ), ".." , ".." , ".." )
44
+ )
45
+
45
46
46
47
def load_graph (filename ):
47
48
"""Load the specified filename; return a graph."""
48
49
49
50
store = Graph ()
50
51
store .bind ("cc" , "http://creativecommons.org/ns#" )
51
52
store .bind ("dc" , "http://purl.org/dc/elements/1.1/" )
52
- store .bind ("dcq" ,"http://purl.org/dc/terms/" )
53
- store .bind ("rdf" ,"http://www.w3.org/1999/02/22-rdf-syntax-ns#" )
53
+ store .bind ("dcq" , "http://purl.org/dc/terms/" )
54
+ store .bind ("rdf" , "http://www.w3.org/1999/02/22-rdf-syntax-ns#" )
54
55
55
56
store .load (filename )
56
57
57
58
return store
58
59
60
+
59
61
def copyto (source , dest , code , size , jurisdiction , money = MONEY ):
60
62
# Make the destination directory, if necessary
61
63
dest_dir = os .path .dirname (dest )
62
- if ( not os .access (dest_dir , os .F_OK ) ):
64
+ if not os .access (dest_dir , os .F_OK ):
63
65
os .makedirs (dest_dir )
64
66
65
67
# If NC (and not the 80x15 icon), use the appropriate currency icon.
66
- if ((string .find (code , 'nc' ) != - 1
67
- and money .has_key (jurisdiction )
68
- and size != '80x15'
69
- and not 'somerights1' in source )):
70
- source += '_' + money [jurisdiction ]
68
+ if (
69
+ string .find (code , "nc" ) != - 1
70
+ and jurisdiction in money
71
+ and size != "80x15"
72
+ and "somerights1" not in source
73
+ ):
74
+ source += "_" + money [jurisdiction ]
71
75
72
- source += ' .png'
76
+ source += " .png"
73
77
74
78
try :
75
79
shutil .copy2 (source , dest )
76
- except :
77
- print 'Failed to copy ' + source + ' to ' + dest
80
+ except : # noqa: E722 (FIXME)
81
+ # Flake8 lint runs via Python 3 so skip following E999
82
+ print "Failed to copy" , source , "to" , dest # noqa: E999
78
83
79
84
80
85
def splat (license_graph ):
@@ -84,34 +89,34 @@ def splat(license_graph):
84
89
for s , p , logo in license_graph .triples ((uri , NS_FOAF .logo , None )):
85
90
# Get the dest_path, which is base-images and
86
91
# everything after 'http://i.creativecommons.org/'
87
- dest_path = os .path .join (
88
- checkout_base (), 'www' , str (logo )[29 :])
92
+ dest_path = os .path .join (checkout_base (), "www" , str (logo )[29 :])
89
93
90
94
m = re .search (
91
- '^http://i.creativecommons.org/'
92
- '(?P<group>l|p)/'
93
- '(?P<code>.*?)/'
94
- '((?P<version>.*?)/'
95
- '((?P<jurisdiction>.*?)/)?)?'
96
- '(?P<size>.*)\.png$' , str (logo ))
97
-
98
- code = m .group ('code' )
99
- jurisdiction = m .group ('jurisdiction' )
100
- size = m .group ('size' )
95
+ "^http://i.creativecommons.org/"
96
+ "(?P<group>l|p)/"
97
+ "(?P<code>.*?)/"
98
+ "((?P<version>.*?)/"
99
+ "((?P<jurisdiction>.*?)/)?)?"
100
+ r"(?P<size>.*)\.png$" ,
101
+ str (logo ),
102
+ )
103
+
104
+ code = m .group ("code" )
105
+ jurisdiction = m .group ("jurisdiction" )
106
+ size = m .group ("size" )
101
107
102
108
code2 = code
103
- if ( code == ' by-nd-nc' ) :
104
- code2 = ' by-nc-nd'
105
- elif code in ('nc' , 'nd' , 'sa' , ' nd-nc' , ' nc-sa' ):
106
- code2 = ' somerights1'
109
+ if code == " by-nd-nc" :
110
+ code2 = " by-nc-nd"
111
+ elif code in ("nc" , "nd" , "sa" , " nd-nc" , " nc-sa" ):
112
+ code2 = " somerights1"
107
113
108
- source = os .path .join (
109
- checkout_base (), 'base-images' , size , code2 )
114
+ source = os .path .join (checkout_base (), "base-images" , size , code2 )
110
115
111
116
copyto (source , dest_path , code , size , jurisdiction )
112
117
113
118
114
119
def cli ():
115
120
"""imgsplat command line interface."""
116
121
117
- splat (load_graph (' http://creativecommons.org/licenses/index.rdf' ))
122
+ splat (load_graph (" http://creativecommons.org/licenses/index.rdf" ))
0 commit comments