⌈⌋ branch:  freshcode


Check-in [aa105661b8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:freecode-submit with minor adaptions for freshcode.club
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:aa105661b897e7edc01ef418cda27319ed668cae
User & Date: mario 2014-07-29 23:53:30
Context
2014-07-29
23:54
URL updating verified for function, also updates separate homepage and download fields now check-in: cf7b3c257a user: mario tags: trunk
23:53
freecode-submit with minor adaptions for freshcode.club check-in: aa105661b8 user: mario tags: trunk
23:52
freecode-submit 2.9 check-in: a7a69e19c8 user: mario tags: trunk
Changes

Changes to doc/fc-submit.

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199


200
201
202
203
204
205
206
    "Carry exception state when a session blows up."
    def __init__(self, msg):
        Exception.__init__(self)
        self.msg = msg

class FreecodeSession:
    "Encapsulate the state of a Freecode API session."
    server = "https://freecode.com/"

    def __init__(self, auth=None, verbose=0, emit_enable=True):
        "Initialize Freecode session credentials."
        self.auth = auth
        self.verbose = verbose
        self.emit_enable = emit_enable
        self.project = None
................................................................................
                credentials = netrc.netrc()
            except netrc.NetrcParseError, e:
                raise FreecodeSessionException("ill-formed .netrc: %s:%s %s" \
                                               % (e.filename, e.lineno, e.msg))
            except IOError, e:
                raise FreecodeSessionException(("missing .netrc file %s" % \
                                                 str(e).split()[-1]))
            ret = credentials.authenticators("freecode")
            if not ret:
                raise FreecodeSessionException("no credentials for Freecode")
            _login, self.auth, _password = ret

    def on_project(self, name):
        "Select project by Freecode shortname."
        if self.verbose:
            print "Selecting project: %s" % name
        self.project = name
................................................................................
        if self.verbose:
            print "URL list update for %s is: %s" % (self.project, urlassoc)
        # First, get permalinks for all existing URLs
        uquery = FreecodeSession.server + "projects/%s/urls.json?auth_code=%s" \
                % (self.permalink, self.auth)
        handle = urllib2.urlopen(uquery)
        content = json.loads(handle.read())
        permadict = {}
        for item in content:
            inner = item['url']
            permadict[inner['label']] = inner['permalink']
        # OK, now run through the update list...
        for (label, url) in urlassoc:
            if label in permadict:
                # updating where we need to
                self.edit_request("projects/%s/urls/%s.json"
                                  % (self.permalink, permadict[label]),
                                  "PUT",
                                  {"url" : {"label": label, "location" : url}})
            else:
                # and adding where we don't.
                self.edit_request("projects/%s/urls.json"
                                  % (self.permalink,),
                                  "POST",
                                  {"url" : {"label": label, "location" : url}})
        # Delete URLs that weren't in the update list
        remove = set(permadict.keys()) - set(map(lambda x: x[0], urlassoc))
        for label in remove:
            self.edit_request("projects/%s/urls/%s.json?auth_code=%s"
                                  % (self.permalink, permadict[label], self.auth),
                                  "DELETE", {})


class FreecodeMetadataFactory:
    "Factory class for producing Freecode records in JSON."
    freecode_field_map = (
        ("Project",          "P", "name"),                   # Project
        ("Summary",          "S", "oneliner"),               # Project
        ("Description",      "D", "description"),            # Project
        ("License-List",     "L", "license_list"),           # Project







|







 







|

|







 







|
|
<
<
<
<
<
<
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
>
>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
169
170
171
172
173
174
175
176
177






178

179













180
181
182
183
184
185
186
187
188
    "Carry exception state when a session blows up."
    def __init__(self, msg):
        Exception.__init__(self)
        self.msg = msg

class FreecodeSession:
    "Encapsulate the state of a Freecode API session."
    server = "https://%s.freshcode.club/" % "api"

    def __init__(self, auth=None, verbose=0, emit_enable=True):
        "Initialize Freecode session credentials."
        self.auth = auth
        self.verbose = verbose
        self.emit_enable = emit_enable
        self.project = None
................................................................................
                credentials = netrc.netrc()
            except netrc.NetrcParseError, e:
                raise FreecodeSessionException("ill-formed .netrc: %s:%s %s" \
                                               % (e.filename, e.lineno, e.msg))
            except IOError, e:
                raise FreecodeSessionException(("missing .netrc file %s" % \
                                                 str(e).split()[-1]))
            ret = credentials.authenticators("freshcode")
            if not ret:
                raise FreecodeSessionException("no credentials for Freshcode")
            _login, self.auth, _password = ret

    def on_project(self, name):
        "Select project by Freecode shortname."
        if self.verbose:
            print "Selecting project: %s" % name
        self.project = name
................................................................................
        if self.verbose:
            print "URL list update for %s is: %s" % (self.project, urlassoc)
        # First, get permalinks for all existing URLs
        uquery = FreecodeSession.server + "projects/%s/urls.json?auth_code=%s" \
                % (self.permalink, self.auth)
        handle = urllib2.urlopen(uquery)
        content = json.loads(handle.read())
        permadict = content['urls']
        # Just send the new dict over






        self.edit_request("projects/%s/urls.json" % (self.permalink),

                          "PUSH",













                          {"urls" : dict(urlassoc)})

class FreecodeMetadataFactory:
    "Factory class for producing Freecode records in JSON."
    freecode_field_map = (
        ("Project",          "P", "name"),                   # Project
        ("Summary",          "S", "oneliner"),               # Project
        ("Description",      "D", "description"),            # Project
        ("License-List",     "L", "license_list"),           # Project