def get_default_state_dir(homedirpostfix='.Tribler'): """ Returns the factory default directory for storing session state on the current platform (Win32,Mac,Unix). @return An absolute path name. """ # Allow override statedirvar = '${TSTATEDIR}' statedir = os.path.expandvars(statedirvar) if statedir and statedir != statedirvar: return statedir # Boudewijn: retrieving the homedir fails with python 2.x on # windows when the username contains specific unicode # characters. using the get_home_dir() function patches this # problem. # homedir = get_home_dir() if sys.platform == "win32": # 5 = XP, 6 = Vista if sys.getwindowsversion()[0] == 6: appdir = os.path.join(homedir,u"AppData",u"Roaming") else: appdir = os.path.join(homedir,u"Application Data") else: appdir = homedir statedir = os.path.join(appdir, homedirpostfix) return statedir
def get_default_dest_dir(): """ Returns the default dir to save content to. * If Downloads/ exists: Downloads/TriblerDownloads else: Home/TriblerDownloads """ t_downloaddir = u"TriblerDownloads" # TODO(emilon): Is this here so the unit tests work? if os.path.isdir(t_downloaddir): return os.path.abspath(t_downloaddir) downloads_dir = os.path.join(get_home_dir(), u"Downloads") if os.path.isdir(downloads_dir): return os.path.join(downloads_dir, t_downloaddir) else: return os.path.join(get_home_dir(), t_downloaddir)
def __init__(self, parent, type): WizardPageSimple.__init__(self, parent) self.utility = parent.utility # 0. mainbox mainbox = wx.BoxSizer(wx.VERTICAL) # 1. topbox topbox = wx.BoxSizer(wx.VERTICAL) # Ask public name name = self.utility.session.get_nickname() name_box = wx.BoxSizer(wx.HORIZONTAL) self.myname = wx.TextCtrl(self, -1, name) name_box.Add(wx.StaticText(self, -1, self.utility.lang.get('myname')), 0, wx.ALIGN_CENTER_VERTICAL) name_box.Add(self.myname, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, 5) topbox.Add(name_box, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, 5) # Ask public user icon / avatar icon_box = wx.BoxSizer(wx.HORIZONTAL) icon_box.Add(wx.StaticText(self, -1, self.utility.lang.get('myicon')), 0, wx.ALIGN_CENTER_VERTICAL) ## TODO: integrate this code with makefriends.py, especially checking code self.iconbtn = None self.iconmime, self.icondata = self.utility.session.get_mugshot() if self.icondata: bm = data2wxBitmap(self.iconmime, self.icondata) else: im = IconsManager.getInstance() bm = im.get_default('PEER_THUMB') if sys.platform == 'darwin': path = get_home_dir() self.iconbtn = wx.FilePickerCtrl(self, -1, path) self.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnIconSelected, id=self.iconbtn.GetId()) icon_box.Add(self.iconbtn, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, 5) else: self.iconbtn = wx.BitmapButton(self, -1, bm) icon_box.Add(self.iconbtn, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, 5) #label = wx.StaticText(self, -1, self.utility.lang.get('obligiconformat')) #icon_box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.Bind(wx.EVT_BUTTON, self.OnIconButton, self.iconbtn) topbox.Add(icon_box, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, 5) mainbox.Add(topbox, 0, wx.EXPAND) self.SetSizerAndFit(mainbox)
def get_mimetype(self, file): (prefix, ext) = os.path.splitext(file) ext = ext.lower() mimetype = None if sys.platform == 'win32': # TODO: Use Python's mailcap facility on Linux to find player try: from Tribler.Video.utils import win32_retrieve_video_play_command [mimetype, playcmd] = win32_retrieve_video_play_command(ext, file) if DEBUG: print >>sys.stderr, "LibtorrentDownloadImpl: Win32 reg said MIME type is", mimetype except: if DEBUG: print_exc() pass else: try: import mimetypes # homedir = os.path.expandvars('${HOME}') from Tribler.Core.osutils import get_home_dir homedir = get_home_dir() homemapfile = os.path.join(homedir, '.mimetypes') mapfiles = [homemapfile] + mimetypes.knownfiles mimetypes.init(mapfiles) (mimetype, encoding) = mimetypes.guess_type(file) if DEBUG: print >> sys.stderr, "LibtorrentDownloadImpl: /etc/mimetypes+ said MIME type is", mimetype, file except: print_exc() # if auto detect fails if mimetype is None: if ext == '.avi': # Arno, 2010-01-08: Hmmm... video/avi is not official registered at IANA mimetype = 'video/avi' elif ext == '.mpegts' or ext == '.ts': mimetype = 'video/mp2t' elif ext == '.mkv': mimetype = 'video/x-matroska' elif ext in ('.ogg', '.ogv'): mimetype = 'video/ogg' elif ext in ('.oga'): mimetype = 'audio/ogg' elif ext == '.webm': mimetype = 'video/webm' else: mimetype = 'video/mpeg' return mimetype
def __init__(self,parent,type): WizardPageSimple.__init__(self,parent) self.utility = parent.utility # 0. mainbox mainbox = wx.BoxSizer(wx.VERTICAL) # 1. topbox topbox = wx.BoxSizer(wx.VERTICAL) # Ask public name name = self.utility.session.get_nickname() name_box = wx.BoxSizer(wx.HORIZONTAL) self.myname = wx.TextCtrl(self, -1, name) name_box.Add(wx.StaticText(self, -1, self.utility.lang.get('myname')), 0, wx.ALIGN_CENTER_VERTICAL) name_box.Add(self.myname, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) topbox.Add(name_box, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) # Ask public user icon / avatar icon_box = wx.BoxSizer(wx.HORIZONTAL) icon_box.Add(wx.StaticText(self, -1, self.utility.lang.get('myicon')), 0, wx.ALIGN_CENTER_VERTICAL) ## TODO: integrate this code with makefriends.py, especially checking code self.iconbtn = None self.iconmime, self.icondata = self.utility.session.get_mugshot() if self.icondata: bm = data2wxBitmap(self.iconmime, self.icondata) else: im = IconsManager.getInstance() bm = im.get_default('personsMode','DEFAULT_THUMB') if sys.platform == 'darwin': path = get_home_dir() self.iconbtn = wx.FilePickerCtrl(self, -1, path) self.Bind(wx.EVT_FILEPICKER_CHANGED,self.OnIconSelected,id=self.iconbtn.GetId()) icon_box.Add(self.iconbtn, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) else: self.iconbtn = wx.BitmapButton(self, -1, bm) icon_box.Add(self.iconbtn, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) #label = wx.StaticText(self, -1, self.utility.lang.get('obligiconformat')) #icon_box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.Bind(wx.EVT_BUTTON, self.OnIconButton, self.iconbtn) topbox.Add(icon_box, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) mainbox.Add(topbox, 0, wx.EXPAND) self.SetSizerAndFit(mainbox)
def get_default_dest_dir(): """ Returns the default dir to save content to. <pre> * For Win32/MacOS: Desktop\TriblerDownloads * For UNIX: If Desktop exists: Desktop\TriblerDownloads else: Home\TriblerDownloads </pre> """ uhome = get_home_dir() if sys.platform == 'win32': tempdir = os.path.join(uhome, 'Desktop', 'TriblerDownloads') elif sys.platform == 'darwin': tempdir = os.path.join(uhome, 'Desktop', 'TriblerDownloads') else: tempdir = os.path.join(uhome, 'Desktop') if not os.path.exists(tempdir): tempdir = os.path.join(uhome, 'Desktop', 'TriblerDownloads') else: tempdir = os.path.join(uhome, 'TriblerDownloads') return tempdir
def setupConfig(self): defaults = { # MiscPanel 'language_file': 'english.lang', 'confirmonclose': '1', 'associate' : '1', # DiskPanel 'removetorrent': '0', 'diskfullthreshold': '1', # RateLimitPanel #'maxupload': '5', 'maxuploadrate': '0', 'maxdownloadrate': '0', 'maxseeduploadrate': '0', # SeedingOptionsPanel 'uploadoption': '0', 'uploadtimeh': '0', 'uploadtimem': '30', 'uploadratio': '100', #AdvancedNetworkPanel #AdvancedDiskPanel #TriblerPanel 'torrentcollectsleep':'15', # for RSS Subscriptions # VideoPanel 'videoplaybackmode':'0', # Misc 'enableweb2search':'0', 'torrentassociationwarned':'0', # GUI 'window_width': '1024', 'window_height': '670', 'detailwindow_width': '800', 'detailwindow_height': '500', 'prefwindow_width': '1000', 'prefwindow_height': '480', 'prefwindow_split': '400', 't4t_option': 0, # Seeding items added by Boxun 't4t_hours': 0, 't4t_mins': 30, 'g2g_option': 1, 'g2g_ratio': 75, 'g2g_hours': 0, 'g2g_mins': 30, 'family_filter': 1, 'window_x': 0, 'window_y': 0, } if sys.platform == 'win32': defaults['mintray'] = '2' # Don't use double quotes here, those are lost when this string is stored in the # abc.conf file in INI-file format. The code that starts the player will add quotes # if there is a space in this string. progfilesdir = os.path.expandvars('${PROGRAMFILES}') #defaults['videoplayerpath'] = progfilesdir+'\\VideoLAN\\VLC\\vlc.exe' # Path also valid on MS Vista defaults['videoplayerpath'] = progfilesdir+'\\Windows Media Player\\wmplayer.exe' defaults['videoanalyserpath'] = self.getPath()+'\\ffmpeg.exe' elif sys.platform == 'darwin': profiledir = get_home_dir() # profiledir = os.path.expandvars('${HOME}') defaults['mintray'] = '0' # tray doesn't make sense on Mac vlcpath = find_prog_in_PATH("vlc") if vlcpath is None: defaults['videoplayerpath'] = "/Applications/QuickTime Player.app" else: defaults['videoplayerpath'] = vlcpath ffmpegpath = find_prog_in_PATH("ffmpeg") if ffmpegpath is None: defaults['videoanalyserpath'] = "macbinaries/ffmpeg" else: defaults['videoanalyserpath'] = ffmpegpath else: defaults['mintray'] = '0' # Still crashes on Linux sometimes vlcpath = find_prog_in_PATH("vlc") if vlcpath is None: defaults['videoplayerpath'] = "vlc" else: defaults['videoplayerpath'] = vlcpath ffmpegpath = find_prog_in_PATH("ffmpeg") if ffmpegpath is None: defaults['videoanalyserpath'] = "ffmpeg" else: defaults['videoanalyserpath'] = ffmpegpath configfilepath = os.path.join(self.getConfigPath(), "abc.conf") self.config = ConfigReader(configfilepath, "ABC", defaults)
def test_home_dir(self): home_dir = get_home_dir() self.assertIsInstance(home_dir, unicode) self.assertTrue(os.path.isdir(home_dir))
def InitStage1(self, installdir, autoload_discovery=True, use_torrent_search=True, use_channel_search=True): """ Stage 1 start: pre-start the session to handle upgrade. """ self.gui_image_manager = GuiImageManager.getInstance(installdir) # Start Tribler Session defaultConfig = SessionStartupConfig() state_dir = defaultConfig.get_state_dir() # Switch to the state dir so relative paths can be used (IE, in LevelDB store paths) if not os.path.exists(state_dir): os.makedirs(state_dir) os.chdir(state_dir) cfgfilename = Session.get_default_config_filename(state_dir) self._logger.debug(u"Session config %s", cfgfilename) self.sconfig = SessionStartupConfig.load(cfgfilename) self.sconfig.set_install_dir(self.installdir) if not self.sconfig.get_watch_folder_path(): default_watch_folder_dir = os.path.join(get_home_dir(), u'Downloads', u'TriblerWatchFolder') self.sconfig.set_watch_folder_path(default_watch_folder_dir) if not os.path.exists(default_watch_folder_dir): os.makedirs(default_watch_folder_dir) # TODO(emilon): Do we still want to force limit this? With the new # torrent store it should be pretty fast even with more that that. # Arno, 2010-03-31: Hard upgrade to 50000 torrents collected self.sconfig.set_torrent_collecting_max_torrents(50000) dlcfgfilename = get_default_dscfg_filename( self.sconfig.get_state_dir()) self._logger.debug("main: Download config %s", dlcfgfilename) if os.path.exists(dlcfgfilename): defaultDLConfig = DefaultDownloadStartupConfig.load(dlcfgfilename) else: defaultDLConfig = DefaultDownloadStartupConfig.getInstance() if not defaultDLConfig.get_dest_dir(): defaultDLConfig.set_dest_dir(get_default_dest_dir()) if not os.path.isdir(defaultDLConfig.get_dest_dir()): try: os.makedirs(defaultDLConfig.get_dest_dir()) except: # Could not create directory, ask user to select a different location dlg = wx.DirDialog( None, "Could not find download directory, please select a new location to store your downloads", style=wx.DEFAULT_DIALOG_STYLE) dlg.SetPath(get_default_dest_dir()) if dlg.ShowModal() == wx.ID_OK: new_dest_dir = dlg.GetPath() defaultDLConfig.set_dest_dir(new_dest_dir) defaultDLConfig.save(dlcfgfilename) self.sconfig.save(cfgfilename) else: # Quit self.onError = lambda e: self._logger.error( "tribler: quitting due to non-existing destination directory" ) raise Exception() if not use_torrent_search: self.sconfig.set_enable_torrent_search(False) if not use_channel_search: self.sconfig.set_enable_channel_search(False) session = Session(self.sconfig, autoload_discovery=autoload_discovery) session.add_observer(self.show_upgrade_dialog, NTFY_UPGRADER, [NTFY_STARTED]) while not session.upgrader.is_done: wx.SafeYield() sleep(0.1) return session
def test_home_dir(self): home_dir = get_home_dir() self.assertIsInstance(home_dir, six.text_type) self.assertTrue(os.path.isdir(home_dir))