00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 import gtk
00026
00027 gtk.gdk.threads_init()
00028
00029 from time import strftime, gmtime, time, sleep
00030
00031 from optparse import OptionParser
00032
00033 import traceback
00034 import os
00035 import sys
00036
00037 import shutil
00038
00039
00040
00041 def printbox(txt):
00042 sign = "#"
00043 box_width = 60
00044
00045 txt = txt.split("\n")
00046 for line in txt:
00047 line = line.strip()
00048 spaces = ((box_width - len(line)) //2)-2
00049 while (spaces * 2) + len(line) + 2 < box_width:
00050 line = line+ " "
00051 if line.strip() != "---":
00052 print (sign + " "*spaces + line + " "*spaces + sign)
00053 else:
00054 print (sign*box_width)
00055
00056 if os.name == "posix" or "mac":
00057 sys.path.append("/usr/share/apps/pyjama")
00058 else:
00059 sys.path.append(os.path.join(os.getenv('PROGRAMFILES'), "pyjama"))
00060
00061
00062
00063 try:
00064 from modules import functions
00065 if "check-modules" in sys.argv:
00066 functions.check_modules()
00067 sys.exit(0)
00068 from modules import clSettings
00069 from modules import clWindow
00070 except ImportError, err:
00071 print (traceback.format_exc())
00072 txt = """---
00073
00074 Pyjama could not find or load some of its modules
00075 This sometimes happens when you have copied
00076 pyjama.py to another path than the other pyjama
00077 files.
00078 Use a softlink instead or edit line 41 in pyjama.py
00079 and add sys.path.append("/usr/share/apps/pyjama")
00080
00081 ---
00082
00083 !Please also check, if you meet all dependencies!
00084 Especially the module 'simplejson' needs to be
00085 installed.
00086
00087 ---"""
00088 printbox(txt)
00089 sys.exit(1)
00090
00091
00092
00093 functions.translation_gettext()
00094
00095
00096
00097 home = functions.preparedirs()
00098
00099 settings = clSettings.settings(None)
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 try:
00161 theme = settings.get_value("PYJAMA", "STANDARD_THEME", "None")
00162 counter = settings.get_value("PYJAMA", "counter", 0)
00163 if counter < 4 and theme != "None":
00164 settings.set_value("PYJAMA", "STANDARD_THEME", "None")
00165 settings.set_value("PYJAMA", "counter", "4")
00166 print ("Unset default theme")
00167 except:
00168 pass
00169
00170
00171 try:
00172 theme = settings.get_value("JAMENDO", "TAGs", -1)
00173 counter = settings.get_value("JAMENDO", "counter", 0)
00174 if counter < 5 and theme != -1:
00175 settings.set_value("PYJAMA", "counter", "5")
00176 if "all " in theme:
00177 theme = theme.replace("all", "")
00178 settings.set_value("JAMENDO", "TAGs", theme)
00179 print ("removed 'all' from taglist")
00180 except:
00181 pass
00182
00183
00184
00185 try:
00186 format = settings.get_value("JAMENDO", "format_stream", -1)
00187 counter = settings.get_value("PYJAMA", "counter", 0)
00188 if counter < 6 and format != -1:
00189 settings.set_value("PYJAMA", "counter", "6")
00190 settings.set_value("JAMENDO", "format_stream", "mp31")
00191 "set stream format to mp3 since this will support seeking"
00192 except:
00193 pass
00194
00195
00196
00197 try:
00198 bl = settings.get_value("PLUGINS", "BLACKLIST")
00199 counter = settings.get_value("PYJAMA", "counter", 0)
00200 if counter < 7 and "downloadGUI" in bl:
00201 settings.set_value("PYJAMA", "counter", "7")
00202 if "downloadGUI" in bl:
00203 bl = bl.replace("downloadGUI", "")
00204 settings.set_value("PLUGINS", "BLACKLIST", bl)
00205 print ("Removed downloadGUI from blacklist.")
00206 except:
00207 pass
00208
00209
00210
00211 try:
00212 bl = settings.get_value("PLUGINS", "BLACKLIST")
00213 counter = settings.get_value("PYJAMA", "counter", 0)
00214 if counter < 8 and not "configtool" in bl:
00215 settings.set_value("PYJAMA", "counter", "8")
00216 if not "configtool" in bl:
00217 bl = "%s %s" % (bl, "configtool")
00218 settings.set_value("PLUGINS", "BLACKLIST", bl)
00219 print ("Added configtool to blacklist.")
00220 except:
00221 pass
00222
00223
00224
00225 try:
00226 tb = settings.get_value("PYJAMA", "SHOW_TOOLBAR_TEXT", True)
00227 counter = settings.get_value("PYJAMA", "counter", 0)
00228 if counter < 9 and tb == False:
00229 settings.set_value("PYJAMA", "counter", "9")
00230 settings.set_value("PYJAMA", "SHOW_TOOLBAR_TEXT", True)
00231 print ("Showing toolbar texts enabled. ")
00232 except:
00233 pass
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 def run(options):
00280 if options.version:
00281 print (functions.VERSION)
00282 return None
00283 home = functions.preparedirs(set_privilegs=True)
00284 if "check-modules" in sys.argv:
00285 return None
00286 if options.cache_long:
00287 directory = os.path.join(home, "cache", "long")
00288 files = os.listdir(directory)
00289 for f in files:
00290 os.remove(os.path.join(directory, f))
00291 print ("Deleted all cache-entries for long-time-cache")
00292 if options.cache_short:
00293 directory = os.path.join(home, "cache", "short")
00294 files = os.listdir(directory)
00295 for f in files:
00296 os.remove(os.path.join(directory, f))
00297 print ("Deleted all cache-entries for short-time-cache")
00298
00299
00300 if options.downloadthemes:
00301
00302 from modules import get_themepack
00303 ret = get_themepack.download_pack()
00304 if ret == 0:
00305
00306 options.listhemes = True
00307 else:
00308 return None
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 if not os.path.exists(os.path.join(home, "pyjama.db")):
00320 print ("forcing update - no database found")
00321 options.update = True
00322 if options.listhemes:
00323 dirs = functions.sorteddirlist()
00324 counter = 1
00325 if len(dirs) == 0:
00326 print ("No themes installed")
00327 print ("You can get some by running 'pyjama -p'")
00328 else:
00329 print ("Following Themes were found:")
00330 for directory in dirs:
00331 print ("%i) %s" % (counter, directory))
00332 counter += 1
00333 return None
00334 val = settings.get_value("PYJAMA", "standard_theme")
00335 if val == "None" or val == None or val[0] == "#":
00336 if not options.theme or options.theme=="None": options.nocolor=True
00337 if not options.nocolor and not options.theme:
00338 options.theme = val
00339 if options.theme and not options.nocolor:
00340 ret, theme = functions.showtheme(options.theme)
00341 if ret == None:
00342 print ("Loaded theme '%s'") % theme
00343 else:
00344 print (ret)
00345 return None
00346 win = clWindow.winGTK(options)
00347 try:
00348 gtk.main()
00349 except KeyboardInterrupt:
00350 win.main.quit()
00351 print (".... bye!")
00352 sys.exit(0)
00353
00354 if __name__ == "__main__":
00355
00356 parser = OptionParser()
00357
00358 parser.add_option("-t", "--theme", dest="theme", help=_("A gtk theme for pyjama. The theme as to be copied to '~/.pyjama/themes'. Example: pyjama --theme Aero-ion3.1. pyjama -t 1 would run the first theme found in your theme- directory."), metavar="theme")
00359
00360 parser.add_option("-l", "--list", action="store_true", dest="listhemes", default=False, help=_("List all themes found"))
00361
00362 parser.add_option("-p", "--download-themes", action="store_true", dest="downloadthemes", default=False, help=_("Download Themepack for Pyjama"))
00363
00364
00365
00366 parser.add_option("-n", "--notheme", action="store_true", dest="nocolor", default=False, help=_("Don't do any color- modifications. Pyjama will exactly look like any of your applications"))
00367
00368 parser.add_option("-u", "--update", action="store_true", dest="update", default=False, help=_("Get Jamendo's latest database dump"))
00369
00370 parser.add_option("", "--update-jamendo", action="store_true", dest="update_jamendo", default=False, help=_("Get Jamendo's latest database dump directly from the slow Jamendo server[not recommended]"))
00371
00372 parser.add_option("", "--clear-short", action="store_true", dest="cache_short", default=False, help="Delete local cache data (short)")
00373
00374 parser.add_option("", "--clear-long", action="store_true", dest="cache_long", default=False, help="Delete local cache data (long)")
00375
00376 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help=_("Print some informations"))
00377
00378 parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help=_("Print a lot informations"))
00379
00380 parser.add_option("-e", "--debug-extreme", action="store_true", dest="debug_extreme", default=False, help=_("Print much to much information"))
00381
00382 parser.add_option("", "--version", action="store_true", dest="version", default=False, help=_("Return Pyjama's version"))
00383
00384
00385
00386
00387
00388 (options, args) = parser.parse_args()
00389 run(options)
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409