Merge lp:~cyphermox/pastebinit/dev-arbitrary-dest into lp:pastebinit

Proposed by Mathieu Trudel-Lapierre
Status: Superseded
Proposed branch: lp:~cyphermox/pastebinit/dev-arbitrary-dest
Merge into: lp:pastebinit
Diff against target: None lines
To merge this branch: bzr merge lp:~cyphermox/pastebinit/dev-arbitrary-dest
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre (community) Needs Resubmitting
Stéphane Graber Needs Fixing
Review via email: mp+10081@code.launchpad.net

This proposal has been superseded by a proposal from 2009-10-22.

To post a comment you must log in.
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Fixes bug #369795 by proposing a format for configuration files that define new personal/public pastebins.

Most pastebins already supported in the script have been factored out to config files in this branch, and commented out in the main script. The only ones kept in the main script (but also available as config files), are pastebin.com and pastebin.ca.

Revision history for this message
Stéphane Graber (stgraber) wrote :

Hi,

Thanks a lot for your patch.
Before merging it, may I suggest you improve the README file a bit ?
I found it quite confusing (though then reading the actual configuration of a pastebin, makes it a lot easier to understand) and contains a few typos (psatebin instead of pastebin for example).

Also, in the code, I'd suggest getting rid of the old code instead of commenting it as soon as it's converted to the new format. We have bzr if we need to retrieve older revisions.

Again, thanks for all the work, it's really appreciated.

review: Needs Fixing
71. By Matt Trudel <mtrudel@mtrudel-laptop>

- Cleanup useless comments.
- Rework wording for the README file.

72. By Matt Trudel <mtrudel@mtrudel-laptop>

- Spellchecking pass on README.

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Fixed the spelling and removed the commented stuff.

I've also reworked the README file and hopefully made it much clearer. If not, please let me know where things are messy or confusing, so that I can fix it :)

Thanks,

/ Matt

review: Needs Resubmitting

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'README'
--- README 1970-01-01 00:00:00 +0000
+++ README 2009-08-13 02:56:14 +0000
@@ -0,0 +1,113 @@
1
2USING PASTEBIN.D FILES
3
4To enable support for private pastebins, first you will need to know the
5fields that are in use by the pastebin when posting data.
6
7Add a file in the /etc/pastebin.d directory with the following format:
8
9[psatebin]
10basename = (the domain name of the pastebin site, without subdomains)
11regexp = (a regular expression that identifies the base site, and any
12 subdomains that may be used)
13
14[format]
15pastebinit_field0 = site_field0
16pastebinit_fieldN = site_fieldN
17custom_field0 = site_fieldN
18custom_fieldN = site_fieldN
19
20[defaults]
21custom_field0 = value
22custom_fieldN = value
23
24
25THE PASTEBIN SECTION
26
27Under "[pastebin]", you will want to keep the very basic information to
28identify the pastebin. Only two fields are used in that section:
29
30 basename - the generic domain name for the pastebin.
31 this domain name should not contain
32 possible subdomains in use.
33
34 regexp - a regular expression that matches the
35 basename, as well as any subdomains that
36 may be in use.
37
38
39THE FORMAT SECTION
40
41Under "[format]", identify the various fields in use in the pastebin you
42are trying to add support for. Identify any fields used to publish data
43on the pastebin, and add them to the configuration file.
44
45The [format] section expects keywords from the pastebinit utility, for
46which the values will be the actual name of the field in which to put the
47data for that pastebin.
48
49A number of reserved keywords can be used, but are optional:
50
51 user - contains the username for the user
52 calling the pastebinit utility.
53
54 content - contains the data that will be posted.
55
56 title - contains the title if set at the command
57 line.
58
59 version - contains the version as set at the
60 command line.
61
62 format - contains the format setting:
63 usually used for syntax highlighting.
64
65 parentpid - contains the parent post ID for
66 pastebins that use it.
67
68 permatag - contains permatag as set at the command
69 line.
70
71 username - contains the pastebin username if
72 required.
73
74 password - contains the pastebin user's password
75 if required.
76
77 jabberid - contains the jabberid for the poster
78 as set at the command line.
79
80Two additional special parameters are available for use:
81
82 page - used to specify a page from which to
83 post data. It is the actual URL of
84 the pastebin's form.
85
86 regexp - used to specify a regexp to execute
87 on the resulting page after posting.
88 This is useful to deal with special
89 pastebins that don't redirect you
90 to the new post's URL.
91
92Any other fields in use for the specific pastebin you are trying to enable
93may be added to the section using a similar syntax. An easy way to deal with
94such a requirement is to repeat the same keyword, such as:
95
96[format]
97expire = expire
98
99Where 'page' can then be reused as the keyword to retrieve a static value,
100as set in the '[defaults]' section.
101
102
103THE DEFAULTS SECTION
104
105The '[defaults]' section is used to set static values for custom fields to
106retrieve. Some pastebins require setting fields such as expiry time for
107posts, or whether to use cookies. Such values would be set using a custom
108field if they are deemed necessary. In the above example, to statically
109set a page to be used in the 'page' field:
110
111[defaults]
112expire = 3600
113
0114
=== added directory 'pastebin.d'
=== added file 'pastebin.d/fpaste.org.conf'
--- pastebin.d/fpaste.org.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/fpaste.org.conf 2009-08-11 02:26:03 +0000
@@ -0,0 +1,17 @@
1# Another website that doesn't work due to unusual changes.
2# this is the Fedora Pastebin, sadly.
3
4[pastebin]
5basename = fpaste.org
6regexp = "http://fpaste.org"
7
8[format]
9user = author
10content = content
11format = lang
12submit = submit
13expire_options = expire_options
14
15[defaults]
16submit = "paste it!"
17expire_options = 3600
018
=== added file 'pastebin.d/gist.github.com.conf'
--- pastebin.d/gist.github.com.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/gist.github.com.conf 2009-08-13 02:16:18 +0000
@@ -0,0 +1,13 @@
1[pastebin]
2basename = gist.github.com
3regexp = "http://gist.github.com"
4
5[format]
6page = page
7user = poster
8format = file_ext[gistfile1]
9content = file_contents[gistfile1]
10title = file_name[gistfile1]
11
12[defaults]
13page = '/gists'
014
=== added file 'pastebin.d/paste.debian.net.conf'
--- pastebin.d/paste.debian.net.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/paste.debian.net.conf 2009-08-13 02:16:18 +0000
@@ -0,0 +1,16 @@
1[pastebin]
2basename = paste.debian.net
3regexp = "http://paste.debian.net"
4
5[format]
6user = poster
7content = code
8format = syntax
9lang = lang
10remember = remember
11expire = expire
12
13[defaults]
14lang = -1
15remember = 0
16expire = 259200
017
=== added file 'pastebin.d/paste.ubuntu.com.conf'
--- pastebin.d/paste.ubuntu.com.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/paste.ubuntu.com.conf 2009-05-03 15:06:09 +0000
@@ -0,0 +1,10 @@
1[pastebin]
2basename = paste.ubuntu.com
3regexp = "http://paste.ubuntu.com"
4
5[format]
6user = poster
7content = content
8format = syntax
9
10[defaults]
011
=== added file 'pastebin.d/paste2.org.conf'
--- pastebin.d/paste2.org.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/paste2.org.conf 2009-08-13 02:16:18 +0000
@@ -0,0 +1,14 @@
1[pastebin]
2basename = paste2.org
3regexp = "http://paste2.org"
4
5[format]
6title = description
7content = code
8format = lang
9page = page
10parent = parent
11
12[defaults]
13page = '/new-paste'
14parent = 0
015
=== added file 'pastebin.d/pastebin.ca.conf'
--- pastebin.d/pastebin.ca.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/pastebin.ca.conf 2009-05-03 15:06:09 +0000
@@ -0,0 +1,17 @@
1[pastebin]
2basename = pastebin.ca
3regexp = "http://((([a-zA-Z0-9\-_\.]*)(pastebin\.ca)))"
4
5[format]
6user = name
7content = content
8type = type
9save = save
10submit = submit
11regexp = regexp
12
13[defaults]
14type = 1
15save = 0
16submit = s
17regexp = '">http://.*pastebin.ca/(.*)</a></p><p>'
018
=== added file 'pastebin.d/pastebin.com.conf'
--- pastebin.d/pastebin.com.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/pastebin.com.conf 2009-05-03 15:06:09 +0000
@@ -0,0 +1,19 @@
1[pastebin]
2basename = pastebin.com
3regexp = "http://((([a-zA-Z0-9\-_\.]*)(pastebin\.com)))"
4#FIXME: not website == "http://www.pastebin.com") or website == "http://pastebin.mozilla.org":
5
6[format]
7user = poster
8content = code2
9version = version
10parentpid = parent_pid
11format = format
12submit = paste
13remember = remember
14expiry = expiry
15
16[defaults]
17remember = f
18expiry = 1
19paste = Send
020
=== added file 'pastebin.d/pastey.net.conf'
--- pastebin.d/pastey.net.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/pastey.net.conf 2009-05-08 01:40:02 +0000
@@ -0,0 +1,18 @@
1[pastebin]
2basename = pastey.net
3regexp = "http://((([a-zA-Z0-9\-_\.]*)(pastey\.net)))"
4
5[format]
6user = author
7title = subject
8parentpid = parent
9content = text
10format = language
11paste = paste
12page = page
13regexp = regexp
14
15[defaults]
16paste = "Paste"
17page = '/submit.php'
18regexp = '">http://(?:(?:[a-zA-Z0-9\-_\.]*)(?:pastey\.net))/(.*)</a>'
019
=== added file 'pastebin.d/rafb.net.conf'
--- pastebin.d/rafb.net.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/rafb.net.conf 2009-08-11 02:26:03 +0000
@@ -0,0 +1,15 @@
1[pastebin]
2basename = rafb.net
3regexp = "http://rafb.net"
4
5[format]
6user = nick
7content = text
8page = page
9lang = lang
10cvt_tabs = cvt_tabs
11
12[defaults]
13page = "/paste/paste.php"
14lang = "Plain Text"
15cvt_tabs = "No"
016
=== added file 'pastebin.d/slexy.org.conf'
--- pastebin.d/slexy.org.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/slexy.org.conf 2009-08-11 02:26:03 +0000
@@ -0,0 +1,24 @@
1[pastebin]
2basename = slexy.org
3regexp = "http://slexy.org"
4
5[format]
6user = author
7content = raw_paste
8title = desc
9page = page
10language = language
11permissions = permissions
12linenumbers = linenumbers
13comment = comment
14submit = submit
15expire = expire
16
17[defaults]
18submit = "Submit Paste"
19page = "/index.php/submit"
20language = "text"
21permissions = 0
22comment = ""
23linenumbers = 0
24expire = 0
025
=== added file 'pastebin.d/stikked.com.conf'
--- pastebin.d/stikked.com.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/stikked.com.conf 2009-08-13 02:16:18 +0000
@@ -0,0 +1,18 @@
1[pastebin]
2basename = stikked.com
3regexp = "http://stikked.com"
4
5[format]
6user = name
7content = code
8title = title
9email = email
10lang = lang
11website = website
12submit = submit
13
14[defaults]
15email = ""
16lang = "text"
17website = ""
18submit = "submit"
019
=== added file 'pastebin.d/yourpaste.net.conf'
--- pastebin.d/yourpaste.net.conf 1970-01-01 00:00:00 +0000
+++ pastebin.d/yourpaste.net.conf 2009-08-13 02:16:18 +0000
@@ -0,0 +1,21 @@
1[pastebin]
2basename = yourpaste.net
3regexp = "http://yourpaste.net"
4
5[format]
6format = syntax
7user = name
8title = desc
9expire = expire
10content = code
11private = private
12remember = remember
13page = page
14regexp = regexp
15
16[defaults]
17expire = 0
18private = 0
19remember = 0
20page = '/paste'
21regexp = '">http://yourpaste.net(.*)</a>'
022
=== modified file 'pastebinit'
--- pastebinit 2009-03-10 05:23:09 +0000
+++ pastebinit 2009-08-13 02:11:21 +0000
@@ -20,6 +20,7 @@
20try:20try:
21 import urllib, os, sys, re, getopt, select, xml.dom.minidom, gettext21 import urllib, os, sys, re, getopt, select, xml.dom.minidom, gettext
22 from gettext import gettext as _22 from gettext import gettext as _
23 from configobj import ConfigObj
2324
24 gettext.textdomain("pastebinit")25 gettext.textdomain("pastebinit")
2526
@@ -32,16 +33,26 @@
32 def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):33 def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
33 return None34 return None
3435
36 def preloadPastebins():
37 confdir = '/etc/pastebin.d/'
38 confdirlist = os.listdir(confdir)
39 pastebind = {}
40 for fileitem in confdirlist:
41 bininstance = ConfigObj(confdir + fileitem)
42 basename = bininstance['pastebin']['basename']
43 pastebind[basename] = bininstance
44 return pastebind
45
35 # pastey.net obfuscates parent ids for replies. Rather than taking the46 # pastey.net obfuscates parent ids for replies. Rather than taking the
36 # post ID given as the parent ID, we must handle this by going to that47 # post ID given as the parent ID, we must handle this by going to that
37 # post page and looking up what the invisible parent ID field will be48 # post page and looking up what the invisible parent ID field will be
38 # set to for children.49 # set to for children.
39 def pasteyParentFixup(website, parentid):50 def doParentFixup(website, paramname, parentid):
40 if parentid == "":51 if parentid == "":
41 return ""52 return ""
42 url_opener = pasteURLopener()53 url_opener = pasteURLopener()
43 page = url_opener.open(website + '/' + parentid, None)54 page = url_opener.open(website + '/' + parentid, None)
44 matches = re.split('<input.*?name="parent".*?value="(.*?)"', page.read())55 matches = re.split('<input.*?name="' + paramname + '".*?value="(.*?)"', page.read())
45 if len(matches) <= 1 or re.match(parentid, matches[1]) == None:56 if len(matches) <= 1 or re.match(parentid, matches[1]) == None:
46 # The obfuscated version didn't begin with the partial version,57 # The obfuscated version didn't begin with the partial version,
47 # or unable to find the obfuscated version for some reason!58 # or unable to find the obfuscated version for some reason!
@@ -50,7 +61,7 @@
50 return matches[1]61 return matches[1]
5162
52 #Return the parameters depending of the pastebin used63 #Return the parameters depending of the pastebin used
53 def getParameters(website, content, user, jabberid, version, format, parentpid, permatag, title, username, password):64 def getParameters(website, pastebind, content, user, jabberid, version, format, parentpid, permatag, title, username, password):
54 "Return the parameters array for the selected pastebin"65 "Return the parameters array for the selected pastebin"
55 params={}66 params={}
56 # pastebin.com v0.5067 # pastebin.com v0.50
@@ -84,81 +95,113 @@
84# params['username'] = username95# params['username'] = username
85# params['password'] = password96# params['password'] = password
86# params['version'] = version97# params['version'] = version
87 elif website == "http://rafb.net":98# elif website == "http://rafb.net":
88 params['page'] = "/paste/paste.php"99# if website == "http://rafb.net":
89 params['nick'] = user100# params['page'] = "/paste/paste.php"
90 params['text'] = content101# params['nick'] = user
91 params['lang'] = "Plain Text" #The format, for syntax hilighting102# params['text'] = content
92 params['cvt_tabs'] = "No"103# params['lang'] = "Plain Text" #The format, for syntax hilighting
93 elif website == "http://stikked.com":104# params['cvt_tabs'] = "No"
94 params['name'] = user105# elif website == "http://stikked.com":
95 params['title'] = title106# params['name'] = user
96 params['email'] = ""107# params['title'] = title
97 params['lang'] = "text" #The format, for syntax hilighting108# params['email'] = ""
98 params['code'] = content109# params['lang'] = "text" #The format, for syntax hilighting
99 params['website'] = ""110# params['code'] = content
100 params['submit'] = "submit"111# params['website'] = ""
101 elif website == "http://slexy.org":112# params['submit'] = "submit"
102 params['page'] = "/index.php/submit"113# elif website == "http://slexy.org":
103 params['raw_paste'] = content114# if website == "http://slexy.org":
104 params['comment'] = ""115# params['page'] = "/index.php/submit"
105 params['author'] = user116# params['raw_paste'] = content
106 params['language'] = "text" #The format, for syntax hilighting117# params['comment'] = ""
107 params['permissions'] = "0"118# params['author'] = user
108 params['desc'] = title119# params['language'] = "text" #The format, for syntax hilighting
109 params['linenumbers'] = "0"120# params['permissions'] = "0"
110 params['expire'] = "0"121# params['desc'] = title
111 params['submit'] = "Submit Paste"122# params['linenumbers'] = "0"
112 elif website == "http://fpaste.org":123# params['expire'] = "0"
113 params['lang'] = format #The format, for syntax hilighting124# params['submit'] = "Submit Paste"
114 params['page'] = "/paste/save"125# elif website == "http://fpaste.org":
115 params['content'] = content126# params['lang'] = format #The format, for syntax hilighting
116 params['submit'] = "pastebinit"127# params['page'] = "/paste/save"
117 elif website == "http://paste2.org":128# params['content'] = content
118 params['page'] = "/new-paste"129# params['submit'] = "pastebinit"
119 params['description'] = title130# elif website == "http://paste2.org":
120 params['lang'] = format131# params['page'] = "/new-paste"
121 params['code'] = content132# params['description'] = title
122 params['parent'] = "0"133# params['lang'] = format
123 elif re.search("http://((([a-zA-Z0-9\-_\.]*)(pastey\.net)))", website): 134# params['code'] = content
124 params['author'] = user135# params['parent'] = "0"
125 params['subject'] = title136# elif re.search("http://((([a-zA-Z0-9\-_\.]*)(pastey\.net)))", website):
126 params['parent'] = pasteyParentFixup(website, parentpid)137# params['author'] = user
127 params['text'] = content138# params['subject'] = title
128 params['language'] = format # File format, as a string like "cpp" or "lua"139# params['parent'] = pasteyParentFixup(website, parentpid)
129 params['paste'] = "Paste"140# params['text'] = content
130 params['page'] = '/submit.php'141# params['language'] = format # File format, as a string like "cpp" or "lua"
131 params['regexp'] = '">http://(?:(?:[a-zA-Z0-9\-_\.]*)(?:pastey\.net))(/.*)</a>'142# params['paste'] = "Paste"
132 elif website == "http://yourpaste.net":143# params['page'] = '/submit.php'
133 params['syntax'] = format144# params['regexp'] = '">http://(?:(?:[a-zA-Z0-9\-_\.]*)(?:pastey\.net))(/.*)</a>'
134 params['name'] = user145# elif website == "http://yourpaste.net":
135 params['desc'] = title146# params['syntax'] = format
136 params['expire'] = "0" # Forever147# params['name'] = user
137 params['code'] = content148# params['desc'] = title
138 params['private'] = "0" # It's not a private post149# params['expire'] = "0" # Forever
139 params['remember'] = "0" # Cookies? ;)150# params['code'] = content
140 params['page'] = "/paste"151# params['private'] = "0" # It's not a private post
141 params['regexp'] = '">http://yourpaste.net(.*)/</a>'152# params['remember'] = "0" # Cookies? ;)
142 elif website == "http://gist.github.com":153# params['page'] = "/paste"
143 params['page'] = "/gists"154# params['regexp'] = '">http://yourpaste.net(.*)/</a>'
144 params['poster'] = user155# elif website == "http://gist.github.com":
145 params['file_ext[gistfile1]'] = format #The format, for syntax hilighting156# params['page'] = "/gists"
146 params['file_contents[gistfile1]'] = content157# params['poster'] = user
147 params['file_name[gistfile1]'] = title158# params['file_ext[gistfile1]'] = format #The format, for syntax hilighting
148 elif website == "http://paste.ubuntu.com":159# params['file_contents[gistfile1]'] = content
149 params['poster'] = user160# params['file_name[gistfile1]'] = title
150 params['syntax'] = format #The format, for syntax hilighting161# elif website == "http://paste.ubuntu.com":
151 params['content'] = content162# params['poster'] = user
152 elif website == "http://paste.debian.net":163# params['syntax'] = format #The format, for syntax hilighting
153 params['poster'] = user164# params['content'] = content
154 params['lang'] = "-1" #The format, for syntax hilighting, default to plain text165# elif website == "http://paste.debian.net":
155 params['syntax'] = format #The format, for syntax hilighting166# params['poster'] = user
156 params['code'] = content167# params['lang'] = "-1" #The format, for syntax hilighting, default to plain text
157 params['remember'] = "0" #Do you want a cookie ?168# params['syntax'] = format #The format, for syntax hilighting
158 params['expire'] = "259200" # expire in 72h169# params['code'] = content
170# params['remember'] = "0" #Do you want a cookie ?
171# params['expire'] = "259200" # expire in 72h
159 else:172 else:
160 sys.exit(_("Unknown website, please post a bugreport to request this pastebin to be added (%s)") % website)173 for pastebin in pastebind:
161 return params174 if re.search( pastebind[pastebin]['pastebin']['regexp'], website ):
175 for param in pastebind[pastebin]['format'].keys():
176 paramname = pastebind[pastebin]['format'][param]
177 if param == 'user':
178 params[paramname] = user
179 elif param == 'content':
180 params[paramname] = content
181 elif param == 'title':
182 params[paramname] = title
183 elif param == 'version':
184 params[paramname] = version
185 elif param == 'format':
186 params[paramname] = format
187 elif param == 'parentpid':
188 #params[paramname] = parentpid
189 params[paramname] = doParentFixup(website, paramname, parentpid)
190 elif param == 'permatag':
191 params[paramname] = parmatag
192 elif param == 'username':
193 params[paramname] = username
194 elif param == 'password':
195 params[paramname] = password
196 elif param == 'jabberid':
197 params[paramname] = jabberid
198 else:
199 params[paramname] = pastebind[pastebin]['defaults'][paramname]
200 #print params
201 if params:
202 return params
203 else:
204 sys.exit(_("Unknown website, please post a bugreport to request this pastebin to be added (%s)") % website)
162205
163 #XML Handling methods206 #XML Handling methods
164 def getText(nodelist):207 def getText(nodelist):
@@ -297,7 +340,8 @@
297 sys.exit(_("Unable to read from: %s") % filename)340 sys.exit(_("Unable to read from: %s") % filename)
298 if not content:341 if not content:
299 sys.exit(_("You are trying to send an empty document, exiting.")) 342 sys.exit(_("You are trying to send an empty document, exiting."))
300 params = getParameters(website, content, user, jabberid, version, format, parentpid, permatag, title, username, password) #Get the parameters array343 pastebind = preloadPastebins() #get the config from /etc/pastebin.d/
344 params = getParameters(website, pastebind, content, user, jabberid, version, format, parentpid, permatag, title, username, password) #Get the parameters array
301345
302 if not re.search(".*/", website):346 if not re.search(".*/", website):
303 website += "/"347 website += "/"

Subscribers

People subscribed via source and target branches