Package magma :: Package magma :: Module create_phex_release_magmas
[hide private]
[frames] | no frames]

Source Code for Module magma.magma.create_phex_release_magmas

  1  #!/usr/bin/env python 
  2  # encoding: utf-8 
  3   
  4  # MAGnet MAnifest Management - Readout and create lists of magnets in yaml format.  
  5  #  
  6  # Copyright © 2008 Arne Babenhauserheide 
  7  #  
  8  # This program is free software: you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation, either version 3 of the License, or 
 11  # (at your option) any later version. 
 12  #  
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/> 
 20   
 21  """Create the magma lists for a Phex release via the commandline.  
 22   
 23  Usage: create_phex_release_magmas.py <windows-release-path> <osx-release-path> <gnu/linux-file-release-path>  
 24   
 25  Examples:  
 26      - create_phex_release_magmas.py phex_3.2.2.104.exe phex_3.2.2.104_osx.zip phex_3.2.2.104.zip 
 27   
 28  Plans:  
 29      - Use MAGMAv0.4 
 30      - Do it less hackish: Use the magma module.  
 31   
 32  Ideas:  
 33      - Get list of Sourceforge servers autmatically.  
 34  """ 
 35   
 36  ### Constants ### 
 37   
 38  SOURCEFORGE_MIRRORS = ["http://heanet.dl.sourceforge.net/sourceforge/", "http://internap.dl.sourceforge.net/sourceforge/", "http://mesh.dl.sourceforge.net/sourceforge/", "http://puzzle.dl.sourceforge.net/sourceforge/", "http://easynews.dl.sourceforge.net/sourceforge/", "http://osdn.dl.sourceforge.net/sourceforge/", "http://keihanna.dl.sourceforge.net/sourceforge/", "http://optusnet.dl.sourceforge.net/sourceforge/", "http://switch.dl.sourceforge.net/sourceforge/", "http://ovh.dl.sourceforge.net/sourceforge/", "http://kent.dl.sourceforge.net/sourceforge/", "http://osdn.dl.sourceforge.net/sourceforge/", "http://jaist.dl.sourceforge.net/sourceforge/", "http://ufpr.dl.sourceforge.net/sourceforge/", "http://umn.dl.sourceforge.net/sourceforge/", "http://nchc.dl.sourceforge.net/sourceforge/", "http://jaist.dl.sourceforge.net/sourceforge/"] #: A list of SF.net servers. The name of the project and the name of the file get appended at the end (MIRROR + project/ + filename).  
 39   
 40  #: The footer line for the phex update magma list.  
 41  PHEX_MAGMA_FOOTER = ''' 
 42   
 43  # Phex: Copyright 2006 The Phex Team - GPL-2 or later. 
 44  # Link: http://phex.org 
 45  # Developer-link: http://sf.net/projects/phex 
 46   
 47  ''' 
 48   
 49   
50 -def create_phex_magmas(files):
51 """Create the magma files for all release types. """ 52 53 #: The different target platforms / release types in the same order as the filepath parameters. 54 RELEASE_TYPES = ["win", "osx", "other"] 55 56 # Create a magma file for each release. 57 for i in range(len(RELEASE_TYPES)): 58 create_phex_magma(files[i], release_type = RELEASE_TYPES[i])
59 60
61 -def create_phex_magma(path, release_type="win"):
62 """Create a magma list for a single release_type""" 63 # We need to create the sha1 hash in Gnutella style. 64 from magma.sha1_gnutella import sha1_gnutella 65 sha1 = sha1_gnutella(path) 66 67 # Also we need to strip the dirname. 68 from magma.create_simple_magma_list import strip_dirname 69 filename = strip_dirname(path) 70 71 # Now, after we got all necessary data, we simply write the respective magma file. 72 write_magma(sha1, filename, release_type)
73 74 # Done :) 75 76 77
78 -def write_magma(sha1, filename, release_type="other"):
79 """Create the magma file for a specific release type. 80 81 @param release_type: The target platform: win, osx or other 82 @type release_type: String """ 83 84 # First get the data to write. 85 86 # First the header line. This won't change but it is different for each release type. 87 88 if release_type == "osx": 89 magma_data = """#MAGMAv0.2 magnet:?mt=.&as=http://dateien.draketo.de/phex_osx.magma&dn=phex_osx.magma""" 90 elif release_type == "win": 91 magma_data = """#MAGMAv0.2 magnet:?mt=.&as=http://dateien.draketo.de/phex_win.magma&dn=phex_win.magma""" 92 elif release_type == "other": 93 magma_data = """#MAGMAv0.2 magnet:?mt=.&as=http://dateien.draketo.de/phex_win.magma&dn=phex_win.magma""" 94 else: 95 raise Exception("Unsupported release type. Supported types are osx, win, other") 96 97 # Now the middle part between the magma header and the phex magnet. 98 99 magma_data += """ 100 101 #This list contains the update URLs for Phex. 102 103 list: 104 105 - """ 106 107 # Now the magnet. We need the SHA1 and the filename. 108 109 SHA1 = sha1 110 111 112 # The first line isn't completely generic. 113 magma_data += '''"magnet:?xt=urn:sha1:''' + SHA1 + ''' 114 &dn=''' + filename 115 116 # The next sources are plain Phex clients with stable IPs or dyndns hostnames. 117 118 GNET_CLIENT_SOURCES = ["http://edrikor.dyndns.org:9846/uri-res/N2R?urn:sha1:"] 119 for i in GNET_CLIENT_SOURCES: 120 magma_data += "&xs=" + i + SHA1 121 122 # Now add the freebase cache. 123 124 magma_data += "&as=http://www.freebase.be/g2/dlcount.php?sha1=" + SHA1 125 126 # Finally add Sourceforge mirrors. 127 128 for i in SOURCEFORGE_MIRRORS: 129 magma_data += "&as=" + i + "phex/" + filename 130 131 # Now close the magnet link 132 133 magma_data += '''"''' 134 135 # And add filename information. 136 magma_data += ''' 137 file-name: ''' + filename 138 139 # Now finish the file. 140 magma_data += PHEX_MAGMA_FOOTER 141 142 # Now write the file. 143 if release_type == "osx": 144 write_to_file("phex_osx.magma", magma_data) 145 elif release_type == "win": 146 write_to_file("phex_win.magma", magma_data) 147 elif release_type == "other": 148 write_to_file("phex_other.magma", magma_data) 149 else: 150 raise Exception("Unsupported release type. Supported types are osx, win, other")
151 152 153
154 -def write_to_file(path, data):
155 """Write the data to a file at the path.""" 156 f = open(path, "w") 157 f.write(data) 158 f.close() 159 log("wrote " + path)
160 161
162 -def log(data, log_type = "console"):
163 """Log some data.""" 164 if log_type == "console": 165 print data
166 167 168
169 -def usage():
170 """Usage instructions. 171 172 @return: Usage instructions (String).""" 173 # Just use the docstring. 174 usage = __doc__.split("\n\n")[1:] 175 usage_string = "\n\n".join(usage) 176 return usage_string 177 178 #### Self-Test #### 179
180 -def _test():
181 """Do all doctests. 182 183 @return: None""" 184 from doctest import testmod 185 testmod() 186 187 # If this gets called automatically, load the magma list and print the magnets, or create a magma list. 188 if __name__ == "__main__": 189 _test() 190 from sys import argv 191 if argv[1] in ["--help", "-h", "?", "--usage"]: 192 print usage() 193 else: 194 create_phex_magmas(argv[1:]) 195