コード例 #1
0
ファイル: accountstore.py プロジェクト: Tidosho/zoundryraven
    def addAccount(self, account):
        # Generate a new id for this account
        accountId = generate()
        # Determine the account's directory
        userProfile = self.applicationModel.getUserProfile()
        accountsDirPath = userProfile.getDirectory(u"accounts")  # $NON-NLS-1$
        accountDirPath = os.path.join(accountsDirPath, accountId)
        os.makedirs(accountDirPath)

        account.setId(accountId)
        account.setDirectoryPath(accountDirPath)

        # auto assign media stores
        try:
            accUtil = ZAccountUtil()
            accountList = [account]
            blogList = accUtil.getBlogsWithOutMediaStore(accountList)
            for blog in blogList:
                accUtil.autoAssignMediaStoreToBlog(blog)
        except:
            pass

        self.accounts.append(account)
        self._saveAccount(account)
        self._fireAccountAddedEvent(account)
コード例 #2
0
ファイル: user.py プロジェクト: Tidosho/zoundryraven
 def getGuid(self):
     prefs = self.getPreferences()
     guid = prefs.getUserPreference(IZAppUserPrefsKeys.GUID)
     if not guid:
         guid = generate()
         prefs.setUserPreference(IZAppUserPrefsKeys.GUID, guid)
     return guid
コード例 #3
0
ファイル: accountstore.py プロジェクト: mpm2050/Raven
    def addAccount(self, account):
        # Generate a new id for this account
        accountId = generate()
        # Determine the account's directory
        userProfile = self.applicationModel.getUserProfile()
        accountsDirPath = userProfile.getDirectory(u"accounts")  #$NON-NLS-1$
        accountDirPath = os.path.join(accountsDirPath, accountId)
        os.makedirs(accountDirPath)

        account.setId(accountId)
        account.setDirectoryPath(accountDirPath)

        # auto assign media stores
        try:
            accUtil = ZAccountUtil()
            accountList = [account]
            blogList = accUtil.getBlogsWithOutMediaStore(accountList)
            for blog in blogList:
                accUtil.autoAssignMediaStoreToBlog(blog)
        except:
            pass

        self.accounts.append(account)
        self._saveAccount(account)
        self._fireAccountAddedEvent(account)
コード例 #4
0
ファイル: templatesvcimpl.py プロジェクト: mpm2050/Raven
 def createTemplate(self):
     guid = generate()
     templateDir = self._getDirForNewTemplate(guid)
     template = ZTemplate(templateDir, guid)
     template.setCreationTime(ZSchemaDateTime())
     template.setLastModifiedTime(ZSchemaDateTime())
     return template
コード例 #5
0
ファイル: user.py プロジェクト: mpm2050/Raven
 def getGuid(self):
     prefs = self.getPreferences()
     guid = prefs.getUserPreference(IZAppUserPrefsKeys.GUID)
     if not guid:
         guid = generate()
         prefs.setUserPreference(IZAppUserPrefsKeys.GUID, guid)
     return guid
コード例 #6
0
 def createTemplate(self):
     guid = generate()
     templateDir = self._getDirForNewTemplate(guid)
     template = ZTemplate(templateDir, guid)
     template.setCreationTime(ZSchemaDateTime())
     template.setLastModifiedTime(ZSchemaDateTime())
     return template
コード例 #7
0
 def _createMediaStorage(self, name, mediaSiteId, properties):
     site = self.getMediaSite(mediaSiteId)
     if site is None:
         raise ZBlogAppException(_extstr(u"mediastoragesrvc.NoMediaSiteFound") % mediaSiteId) #$NON-NLS-1$
     id = generate()
     storageTypeId = site.getMediaStorageTypeId()
     storageType = self._getMediaStorageType(storageTypeId)
     storage = ZMediaStorage(id, name, mediaSiteId, properties)
     registryFile = os.path.join(self.mediaStoresDirectory, id + u".store.registry") #$NON-NLS-1$
     storage.init(site, storageType, registryFile)
     return storage
コード例 #8
0
ファイル: datastore.py プロジェクト: mpm2050/Raven
    def addDocument(self, document):
        if document.getId():
            self.saveDocument(document)
            return

        document.setId(guid.generate())
        if document.getCreationTime() is None:
            document.setCreationTime(ZSchemaDateTime())
        if document.getLastModifiedTime() is None:
            document.setLastModifiedTime(ZSchemaDateTime())

        documentXmlPath = self._getDocumentPath( document.getId() )
        saveDocument(document, documentXmlPath)
        self._fireDocumentAddedEvent(document)
コード例 #9
0
    def addTask(self, task):
        task.setId(generate())
        taskLogFilename = os.path.join(self.tasksDirectory, task.getId() + u".task.log") #$NON-NLS-1$
        task.setLogLocation(taskLogFilename)
        self.tasks.append(task)

        self.listeners.doCallback(u"onTaskAdded", [task]) #$NON-NLS-1$
        self._resumeTask(task)

        # Wait until the num work units has been set by the task (but only
        # wait for up to 30 seconds).
        numWaits = 0
        while task.getNumWorkUnits() <= 0 and numWaits < 60:
            time.sleep(0.5)
            numWaits = numWaits + 1
        if task.getNumWorkUnits() <= 0:
            raise ZAppFrameworkException(_extstr(u"backgroundtaskimpl.TaskFailedToStartError") % task.getName()) #$NON-NLS-1$
コード例 #10
0
ファイル: resourcestoreimpl.py プロジェクト: mpm2050/Raven
 def _createResourceId(self, fileShortName):
     fileShortName = sanitizeFileName(fileShortName)
     if not os.path.exists(self._getStorePath(fileShortName)):
         return fileShortName
     (name, ext) = os.path.splitext(fileShortName)
     # ext include "." (dot)
     if not ext:
         ext = u""  #$NON-NLS-1$
     count = 1
     while count < 10000:
         fileShortName = u"%s_%04d%s" % (name, count, ext)  #$NON-NLS-1$
         if not os.path.exists(self._getStorePath(fileShortName)):
             return fileShortName
         count = count + 1
     # filename on numbering failed. used guids
     fileShortName = u"%s_%s%s" % (name, generate(), ext)  #$NON-NLS-1$
     return fileShortName
コード例 #11
0
 def _createResourceId(self, fileShortName):
     fileShortName = sanitizeFileName(fileShortName)
     if not os.path.exists( self._getStorePath(fileShortName) ):
         return fileShortName
     (name, ext) = os.path.splitext(fileShortName)
     # ext include "." (dot)
     if not ext:
         ext = u"" #$NON-NLS-1$
     count = 1
     while count < 10000:
         fileShortName = u"%s_%04d%s" % (name, count, ext) #$NON-NLS-1$
         if not os.path.exists( self._getStorePath(fileShortName) ):
             return fileShortName
         count = count + 1
     # filename on numbering failed. used guids
     fileShortName = u"%s_%s%s" % (name, generate(), ext) #$NON-NLS-1$
     return fileShortName
コード例 #12
0
ファイル: httpdownload.py プロジェクト: Tidosho/zoundryraven
 def _generateResourceName(self, outputDir, url, type=u"text/html"):  # $NON-NLS-1$
     url = ZUrl(url)
     file = url.getFile()
     if file and u"." in file:  # $NON-NLS-1$
         baseName = os.path.basename(file)
         path = os.path.join(outputDir, baseName)
         count = 1
         while os.path.exists(path):
             (fname, ext) = os.path.splitext(baseName)
             path = os.path.join(outputDir, u"%s-%d%s" % (fname, count, ext))  # $NON-NLS-1$
         return path
     else:
         ext = u".html"  # $NON-NLS-1$
         if type == IZResourceDependencyTypes.CSS:
             ext = u".css"  # $NON-NLS-1$
         elif type == IZResourceDependencyTypes.SCRIPT:
             ext = u".js"  # $NON-NLS-1$
         elif type == IZResourceDependencyTypes.IMAGE:
             ext = u".bin"  # $NON-NLS-1$
         return os.path.join(outputDir, generate() + ext)
コード例 #13
0
ファイル: fileutil.py プロジェクト: Tidosho/zoundryraven
def generateFilename(prefix, suffix):
    global filename_lock, filename_count
    num = 0
    try:
        filename_lock.acquire()
        num = filename_count
        filename_count = filename_count + 1 
    finally:
        filename_lock.release()
    if not prefix:
        prefix = u"zraven" #$NON-NLS-1$
    if not suffix:
        suffix = u".bin" #$NON-NLS-1$
    h = hash( generate() ) 
    hx = u"" #$NON-NLS-1$
    if h >= 0:
        hx = u"p%x" % h #$NON-NLS-1$
    else:    
        hx = u"n%x" % -h #$NON-NLS-1$
    name =  u"%s_%03d%s%s" % (prefix, num, hx, suffix) #$NON-NLS-1$
    return name
コード例 #14
0
ファイル: fileutil.py プロジェクト: mpm2050/Raven
def generateFilename(prefix, suffix):
    global filename_lock, filename_count
    num = 0
    try:
        filename_lock.acquire()
        num = filename_count
        filename_count = filename_count + 1
    finally:
        filename_lock.release()
    if not prefix:
        prefix = u"zraven"  #$NON-NLS-1$
    if not suffix:
        suffix = u".bin"  #$NON-NLS-1$
    h = hash(generate())
    hx = u""  #$NON-NLS-1$
    if h >= 0:
        hx = u"p%x" % h  #$NON-NLS-1$
    else:
        hx = u"n%x" % -h  #$NON-NLS-1$
    name = u"%s_%03d%s%s" % (prefix, num, hx, suffix)  #$NON-NLS-1$
    return name
コード例 #15
0
    def addTask(self, task):
        task.setId(generate())
        taskLogFilename = os.path.join(self.tasksDirectory,
                                       task.getId() +
                                       u".task.log")  #$NON-NLS-1$
        task.setLogLocation(taskLogFilename)
        self.tasks.append(task)

        self.listeners.doCallback(u"onTaskAdded", [task])  #$NON-NLS-1$
        self._resumeTask(task)

        # Wait until the num work units has been set by the task (but only
        # wait for up to 30 seconds).
        numWaits = 0
        while task.getNumWorkUnits() <= 0 and numWaits < 60:
            time.sleep(0.5)
            numWaits = numWaits + 1
        if task.getNumWorkUnits() <= 0:
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.TaskFailedToStartError") %
                task.getName())  #$NON-NLS-1$
コード例 #16
0
ファイル: httpdownload.py プロジェクト: mpm2050/Raven
 def _generateResourceName(self,
                           outputDir,
                           url,
                           type=u"text/html"):  #$NON-NLS-1$
     url = ZUrl(url)
     file = url.getFile()
     if file and u"." in file:  #$NON-NLS-1$
         baseName = os.path.basename(file)
         path = os.path.join(outputDir, baseName)
         count = 1
         while os.path.exists(path):
             (fname, ext) = os.path.splitext(baseName)
             path = os.path.join(outputDir, u"%s-%d%s" %
                                 (fname, count, ext))  #$NON-NLS-1$
         return path
     else:
         ext = u".html"  #$NON-NLS-1$
         if type == IZResourceDependencyTypes.CSS:
             ext = u".css"  #$NON-NLS-1$
         elif type == IZResourceDependencyTypes.SCRIPT:
             ext = u".js"  #$NON-NLS-1$
         elif type == IZResourceDependencyTypes.IMAGE:
             ext = u".bin"  #$NON-NLS-1$
         return os.path.join(outputDir, generate() + ext)
コード例 #17
0
ファイル: usage.py プロジェクト: mpm2050/Raven
 def __init__(self, type):
     self.attributes = {}
     self.id = generate()
     
     self.addAttribute(u"packet.packet-type", type) #$NON-NLS-1$
     self.addAttribute(u"packet.timestamp", unicode(ZSchemaDateTime())) #$NON-NLS-1$
コード例 #18
0
    def _createAccountFromWLWBlogInfo(self, wlwBlogInfo):
        accountId = generate()
        accountDir = os.path.join(self.accountDir, accountId)
        account = ZWindowsLiveWriterAccount(accountDir)
        account.setId(accountId)
        account.setUsername(wlwBlogInfo.username) 
        (siteName, siteId) = LIVE_WRITER_PROVIDER_MAP[wlwBlogInfo.providerId] #@UnusedVariable
        # Over rides fop WP 2.2
        if wlwBlogInfo.clientType == u"WordPress" and wlwBlogInfo.serviceName == u"WordPress": #$NON-NLS-1$ #$NON-NLS-2$
            siteId = u"zoundry.blogapp.pubsystems.publishers.site.wordpress22" #$NON-NLS-1$
        apiInfo = ZAccountAPIInfo()
        apiInfo.setType(siteId)
        apiInfo.setUrl(wlwBlogInfo.postApiUrl)
        account.setAPIInfo(apiInfo)
        account.setName(wlwBlogInfo.blogName + u" Account") #$NON-NLS-1$

        blog = ZBlogFromAccount()
        blog.setAccount(account)
        blogId = u"{urn:zoundry:acc:%s}%s" % (account.getId(), wlwBlogInfo.blogId) #$NON-NLS-1$
        blog.setId(blogId)
        blog.setName(wlwBlogInfo.blogName)
        blog.setUrl(wlwBlogInfo.homepageUrl)

        # set WLW import attributes
        blog.setAttribute(u"clientType", unicode(wlwBlogInfo.clientType), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$
        blog.setAttribute(u"serviceName", unicode(wlwBlogInfo.serviceName), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$
        blog.setAttribute(u"providerId", unicode(wlwBlogInfo.providerId), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$
        blog.setAttribute(u"fileUploadSupport", unicode(wlwBlogInfo.fileUploadSupport), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$
        if wlwBlogInfo.fileUploadSupport == 2:
            blog.setAttribute(u"ftpServer", unicode(wlwBlogInfo.ftpServer), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"ftpPath", unicode(wlwBlogInfo.ftpPath), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"ftpUrl", unicode(wlwBlogInfo.ftpUrl), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"ftpUsername", unicode(wlwBlogInfo.ftpUsername), IZBlogAppNamespaces.WLW_ACCOUNT_NAMESPACE) #$NON-NLS-1$

        blog.setAttribute(u"id", wlwBlogInfo.blogId, IZBlogAppNamespaces.CMS_PUBLISHER_NAMESPACE) #$NON-NLS-1$
        blog.setAttribute(u"name", unicode(wlwBlogInfo.blogName), IZBlogAppNamespaces.CMS_PUBLISHER_NAMESPACE) #$NON-NLS-1$

        if siteId == DefaultSites.BLOGGER:
            # WLW may have the blogger legacy URL. Use the new url for api
            apiInfo.setUrl(u"http://www.blogger.com/feeds/default/blogs") #$NON-NLS-1$
            linkBase = wlwBlogInfo.homepageUrl
            if not linkBase.endswith(u"/"): #$NON-NLS-1$
                linkBase = linkBase + u"/" #$NON-NLS-1$
            feedLink = linkBase + u"feeds/posts/default" #$NON-NLS-1$
            altLink = wlwBlogInfo.homepageUrl
            postLink = wlwBlogInfo.postApiUrl
            catsLink = feedLink
            feedTitle = wlwBlogInfo.blogName
            atomId = wlwBlogInfo.blogId
            blog.setAttribute(u"feed-link", feedLink, IZBlogAppNamespaces.ATOM_PUBLISHER_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"alt-link", altLink, IZBlogAppNamespaces.ATOM_PUBLISHER_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"post-link", postLink, IZBlogAppNamespaces.ATOM_PUBLISHER_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"categories-link", catsLink, IZBlogAppNamespaces.ATOM_PUBLISHER_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"feed-title", feedTitle, IZBlogAppNamespaces.ATOM_PUBLISHER_NAMESPACE) #$NON-NLS-1$
            blog.setAttribute(u"id", atomId, IZBlogAppNamespaces.ATOM_PUBLISHER_NAMESPACE) #$NON-NLS-1$

        for (catId, catName) in wlwBlogInfo.categories:
            category = ZCategory()
            category.setId(catId)
            category.setName(catName)
            blog.addCategory(category)

        account.addBlog(blog)
        # CANNOT CREATE MEDIA STORES HERE: as it needs mediastore service - which is not started until after
        # profile has started (i.e. after profile manager)
        # This part of the code needs to be run after the app has started.

        return account