"""How to create a custom mappable container (dictionary-like) type in Python."""
from UserDict import DictMixin
class MyDict(DictMixin):
# MyDict only needs to implement getitem, setitem, delitem and keys (at a
# minimum) and UserDict will provide the rest of the standard dictionary
# methods based on these four.
#
# getitem and delitem should raise KeyError if no item exists for the given
# key. getitem, setitem and delitem should raise TypeError if the given key
# is of the wrong type.
def __getitem__(self, key):
....
def __setitem__(self, key, item):
....
def __delitem__(self, key):
....
def keys(self):
....
# You can now use your class as if it was a dict, using the standard container
# operators and dictionary methods.
d = MyDict()
d[key] = value
d.get(key)
d.clear()
etc.
homedir = os.path.expanduser('~')
# ...works on at least windows and linux.
# In windows it points to the user's folder
# (the one directly under Documents and Settings, not My Documents)
# In windows, you can choose to care about local versus roaming profiles.
# You can fetch the current user's through PyWin32.
#
# For example, to ask for the roaming 'Application Data' directory:
# (CSIDL_APPDATA asks for the roaming, CSIDL_LOCAL_APPDATA for the local one)
# (See microsoft references for further CSIDL constants)
try:
from win32com.shell import shellcon, shell
homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
except ImportError: # quick semi-nasty fallback for non-windows/win32com case
homedir = os.path.expanduser("~")
def containsDir (dirPath):
contents=os.listdir(dirPath)
dirList=[item for item in contents if os.path.isdir(os.path.join(dirPath,item))]
return not dirList==list()
def containsArchive (dirPath):
contents=os.listdir(dirPath)
archiveExts=['.zip','.rar','.gz','.bz2','.tar','.r01','.r001']
archiveList=[item for item in contents if os.path.splitext(item)[-1].lower() in archiveExts]
return not archiveList==list()
import os
from Foundation import NSMutableDictionary
version = os.popen4("git rev-parse --short HEAD")[1].read()
info = os.environ['INFOPLIST_PATH']
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info)
plist['CFBundleVersion'] = version
plist.writeToFile_atomically_(info, 1)
#!/usr/bin/env python
#
# best.py
#
# Copyright 2008 hemanth <hemanth.hm@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import commands
import os
import pickle
def readDir():
directory = raw_input('In which folder would you like to save the songs??\n')
if(os.path.exists(directory)):
print 'Error!! Please give an other name '
directory = raw_input('In which folder would you like to save the songs??\n')
os.mkdir(directory)
os.chdir(directory)
else:
os.mkdir(directory)
os.chdir(directory)
readDir()
url = raw_input('Which url are you aiming at ?\n')
tmp = open('tempo.txt','w');
tmp.writelines(url)
tmp.close()
tmp = open('tempo.txt','r');
link = tmp.read()
os.system(" curl " + link +"| egrep -o 'http:.*All\.ram' > final.txt ")
infile =open('final.txt', 'r')
outfile = open('tmp.txt', 'w')
for line in infile:
outfile = open('tmp.txt', 'w')
key = line
list = key.split("/")
dir = list[6]
outfile.writelines(key)
outfile.close()
open('tmp.txt','r')
os.system("cat tmp.txt | xargs -n1 -i curl {} > links")
os.system("wget -P %s -i links" %dir)
infile.close()
outfile.close()
os.remove(outfile.name)
os.remove('links')
os.remove(tmp.name)