Tuesday, December 4, 2012

GNOME Power Manager: install problem

In the upper right corner of my login screen, I get the following error in Ubuntu:

INSTALL PROBLEM! The configuration defaults for GNOME Power Manager have not been installed correctly. Please contact your computer administrator.

When I type in my password. It seems to do something, the screen turns black and a cursor appears for a second but then it returns to the login screen. The theme also appears to be bluish.

I noticed that this is more related to my hard disk memory reaching its limits.

So I followed the following steps:

  • Start the computer
  • On the login screen, press CTRL+ALT+F1. This will take you to the command line
  • Login with your username and password
  • Check the disk usage using the following command: df -h
  • Clear some space by deleting a directory that you do not need. It has to be a big directory, say 1GB. In my case, I used the following command: rm -vR /home/frank/very_big_dir
  • Then reboot: sudo reboot.
Hopefully, this should have fixed your problem

Friday, April 13, 2012

Modifying Existing Content Types using archetypes.schemaextender

I was working with Plone 4 and needed to extend the Folder Content type to add an image and a title.

Being a newbie in Plone, I rummaged through the internet (Google) and was fortunate to find the tutorial below. It has been a real help and helped solve my issue in less than 30 mins.

Tweaking Existing Content Types using archetypes.schemaextender

Enjoy!!!

Thursday, April 5, 2012

Unix/Linux Commands every developer should know

General Commands:

1. date: shows date and time
2. history: lists the previously executed commands
3. man ls: shows online documentation by program name
4. who: who is on the system and what they are doing
5. whoami: who is logged onto this terminal
6. cal: calendar
7. banner DZone 
8. clear: clears the screen
9. tty: displays your terminal

Directory Management Commands:

1. pwd: will print your home directory on screen. pwd means print working directory
2. ls: displays the contents of directory
3. cd: change to new directory
4. mkdir dirNameCreate: creates new directory
5. mv dirNameChange dirNameChange2: renames the directory           
6. rmdir dirNameremove: removes empty directory (you must remove files first)
7. dircmp dir1 dir2: compares two directories

File Management Commands:

1. find myFile.txt: finds files that match specific criteria  
2. file myFile.txt: displays about the contents of a given file, whether it is a text (Ascii) or binary file.
3. head myFile.txt: by default it will display the first 10 lines of a file.
If you want first 50 lines you can use head -50 filename or for 37 lines head -37 filename and so forth.
4. tail myFile.txt: by default it will display the last 10 lines of a file.
If you want last 50 lines then you can use tail -50 filename.
5. more myFile.txt: will display a page at a time and then wait for input which is spacebar. For example if you have a file which is 500 lines and you want to read it all.
6. wc myFile.txt: counts the characters, words and lines in a file depending upon the option
7. mv myFile.txt yourFile.txt: is used to move a file from one directory to another directory or to rename a file
8. cp myFile.txt yourFile.txt: is used to copy a file from one directory to another directory/same directory
9. rm myFile.txt: removes the file
10. cmp myfile.txt yourfile.txt: compares two files


Source : Important Linux/Unix Commands

Tuesday, April 3, 2012

Creating Local SVN Repository

In this tutorial I will explain how to create a local Subversion (SVN) repository, intended for a single user. I assume that you already know the benefits of keeping track of old revision of projects or important documents such as a resume or a thesis you have been writing. Subversion offers you a very convenient yet strong method to do so, and the easiest way to do so with Subversion (SVN) is to create a local, home, repository intended for a single user – you.

The repository we are going to create will be used by a single user, working locally on the machine. In this tutorial I will assume the repository will be created for a project called “project1″. “project1″ can be a real project you are doing, a paper you are writing or any thing else that can be stored under revision control (that almost everything).

Creating the repository

We will start by creating the repository. From the command line do the following:
$ mkdir /home/user/svnrep
$ cd ~/svnrep
$ svnadmin create project1

In the first line we create a directory to house all of your repositories (I assume you are working under the username “user”). I prefer to use different repositories for different projects that are unrelated, no matter how small they are. Because I use many repositories, I prefer to have a single directory underneath all repositories will reside in an organized way (i.e. no junk files or any other kind of stuff except directories). Next thing, is to cd into the directory we created, and actually create the repository using the svnadmin command. To repository we’ve created is called “project1″.

The brand new “project1″ repository is currently empty and in revision 0. This will change once we put some data in it. The first thing you do with a new repository is to import initial project data into it.
$ svn import /home/user/project1 file:///home/user/svnrep/project1/trunk -m "Initial import of project1"

Will import the current project1′s file into the repository (assuming that project1 indeed resides in /home/user/project1). The trunk appended to the end of the repository URL, is part of the directory layout convention used by many Subversion users. The last part of the command is the message that will be attached to the import in the SVN log.

Now the repository holds data and you are ready to checkout the code from it, and start working.

Checkout a Working Copy and Start Working

When using SVN (as well as in most revision control systems) you don't work directly on the repository. Instead you checkout a working copy from it, and work on this copy. To checkout a working copy from the repository, use:
$ svn co file:///home/user/svnrep/project1/trunk /home/user/project1_work

This will create a working copy of the repository under /home/user/project1_work. You can edit this copy safely.

After you've done editing your working copy, you will want to commit those changes back to the repository. Assuming you are already inside the directory of the working copy, just do:
$ svn commit -m "Some log message"

This will send you changes back to the repository and store them there. Change the "Some log message" to some useful short description of the changes you've made.

Some Useful Commands

To view a list of log messages that were attached to the operations on the repository, use:
$ svn log
$ svn log -r 5:HEAD

The first command will print all log messages. The second command will print the log messages from revision 5 to the latest revision. You can substitute the HEAD with a number to get the log messages of the revisions up to a specific one.

To view the changes you made before committing your code, use:
$ svn diff


Another important command is the one to update your working copy with the latest revision from the repository. This can be done using:
$ svn update

However, since your are the only user of the local repository, you won't have to use this function often (if at all), unless you use two, or more, working copies for your project.

IF : A Poem by Rudyard Kipling

Today I will digress from my usual tech speak and post a beautiful poem by Rudyard Kipling.


IF

If you can keep your head when all about you
Are losing theirs and blaming it on you;
If you can trust yourself when all men doubt you,
But make allowance for their doubting too:
If you can wait and not be tired by waiting,
Or, being lied about, don't deal in lies,
Or being hated don't give way to hating,
And yet don't look too good, nor talk too wise;

If you can dream---and not make dreams your master;
If you can think---and not make thoughts your aim,
If you can meet with Triumph and Disaster
And treat those two impostors just the same:.
If you can bear to hear the truth you've spoken
Twisted by knaves to make a trap for fools,
Or watch the things you gave your life to, broken,
And stoop and build'em up with worn-out tools;

If you can make one heap of all your winnings
And risk it on one turn of pitch-and-toss,
And lose, and start again at your beginnings,
And never breathe a word about your loss:
If you can force your heart and nerve and sinew
To serve your turn long after they are gone,
And so hold on when there is nothing in you
Except the Will which says to them: "Hold on!"

If you can talk with crowds and keep your virtue,
Or walk with Kings---nor lose the common touch,
If neither foes nor loving friends can hurt you,
If all men count with you, but none too much:
If you can fill the unforgiving minute
With sixty seconds' worth of distance run,
Yours is the Earth and everything that's in it,
And---which is more---you'll be a Man, my son! 
Rudyard Kipling

Wednesday, March 28, 2012

How to hide selectively a page's description

How to hide selectively a page's content

Customize a document view

The above two links helped me in creating a table of contents that would show as a popup only on selected pages. This is achieved by selecting the appropriate dynamic view to use from the display drop-down.

Plone : Creating a Product from scratch

I was fortunate enough to find the link below which helped me a great deal to create my own product ... from scratch. Here is the link:

Creating a Plone Product from scratch

It is written in a nice format easy to follow and understand.

Enjoy!

Tuesday, February 21, 2012

Plone : Limit tal:repeat iterations

So, I am still working with Plone.

I had a portlet which simply showed all documents of a certain type in the current folder. I needed a way to limit the portlet to show no more than 10 documents.
I knew I had to edit the tal:repeat statement to limit the results to 10 only.

Below is my original code:

<h2>Recent Items</h2>
      
    <ul class="recentItemsListing">
 <li class="recentItem"
 tal:repeat="ritem view/getRecentItems">
     <a tal:content="ritem/Title"
     tal:attributes="href ritem/getURL"></a>
        </li>
    </ul>

I changed it to the following:
<h2>Recent Items</h2>
      
    <ul class="recentItemsListing"
           tal:define="restricetdRecentItems python:view.getRecentItems()[:10]">
 <li class="recentItem"
 tal:repeat="ritem restricetdRecentItems">
     <a tal:content="ritem/Title"
     tal:attributes="href ritem/getURL"></a>
        </li>
    </ul>

Good Luck to whoever founds this code useful.

Friday, February 17, 2012

Plone : Check if a form was submitted

I'm still continuing my journey with Plone.

Recently, I was implementing a search form in one of my templates. So, I wanted my form to submit to the same page but I didn't know how. The reason for wanting this feature was because I needed to enable certain parts of the page to be viewed i.e. the search results DIV, only when the form in the page has been submitted.

Below are the steps I used to achieve the functionality.

The Steps
I used a tal:condition and checked for data that is inside the request object upon form submission. To examine what is in the request object, simply put the following on your page:
<div tal:replace="structure request" />
Note: when the request object is called, it renders a readable, HTML version of the data. We use "structure" to prevent escaping the HTML.

Now, for my case, I needed to check whether my search form was submitted. So inside the DIV tag, I checked if the query string was empty or not. Below is a sample of the code:
<!-- Form has been submitted -->
<div tal:condition="python:request.environ.get('QUERY_STRING') != ''"></div>

<!-- Form has not been submitted -->
<div tal:condition="python:request.environ.get('QUERY_STRING') == ''"></div>

Note that you can use any variable you want. I simply chose to use the QUERY_STRING from the request object.

This might not be perfect, but I hope it will give direction to someone else.

UPDATE : 17-02-2012

You can also add a hidden field, name for example "submitedform" with value="1" and then, make a condition on :
request.get('submitedform', 0)

Tuesday, January 24, 2012

Plone 4: Overriding a class viewlet

I am a newbie Plone Developer. Recently, I needed to override a viewlet in Plone that had a python class in its definition instead of a simple template. This is what I did to customize the viewlet.

The steps for overriding a class viewlet does not differ much from overriding a simple template. So, I'll just cover the practical points of our use case.

Introduction
I suppose you are already familiar with how to find the viewlet you want to override, using @@manage-viewlets view. For this particular example let'e override plone.path_bar viewlet that is managed by plone.portaltop viewlet manager. It's the viewlet that renders a path bar (better known as the breadcrumbs) below the global navigation. In this example we will get rid of "You are here:" text in plone.path_bar viewlet.

1. Code that renders the viewlet
Let's have a look at how this viewlet is declared in configure.zcml inside the plone.app.layout.viewlets package:

    <!-- The breadcrumbs -->
    <browser:viewlet
        name="plone.path_bar"
        manager=".interfaces.IAboveContent"
        class=".common.PathBarViewlet"
        permission="zope2.View"
        />

As you can see this viewlet is rendered by a Zope 3 view, defined in common.PathBarViewlet class inside the plone.app.layout.viewlets package.

Here is how this class looks like:
class PathBarViewlet(ViewletBase):
    render = ViewPageTemplateFile('path_bar.pt')

    def update(self):
        portal_state = getMultiAdapter((self.context, self.request),
                                            name=u'plone_portal_state')

        self.navigation_root_url = portal_state.navigation_root_url()

        self.is_rtl = portal_state.is_rtl()

        breadcrumbs_view = getMultiAdapter((self.context, self.request),
                                           name='breadcrumbs_view')
        self.breadcrumbs = breadcrumbs_view.breadcrumbs()

We are not going to edit standard behavior of the viewlet in this example. The only thing we want is getting rid of "You are here:" text. Thus render = ViewPageTemplateFile('path_bar.pt') is exactly what we are interested in.

2. Customize the viewlet's template
render = ViewPageTemplateFile('path_bar.pt') line defines the page template for plone.path_bar viewlet. You can find path_bar.pt template inside the plone.app.layout.viewlets package. Let's make a copy of this template in the browser/ directory of MyTheme. No need to give it a different name.

Edit the template to remove the text we do not need:
<div id="portal-breadcrumbs"
     i18n:domain="plone">

    <!-- We use a comment to show what part we remove
    <span i18n:translate="you_are_here" id="breadcrumbs-you-are-here">
        You are here:
    </span>
    -->

    <a i18n:translate="tabs_home" tal:attributes="href
    view/navigation_root_url">Home</a>
    <span tal:condition="view/breadcrumbs" class="breadcrumbSeparator">
        <tal:ltr condition="not: view/is_rtl">→</tal:ltr>
        <tal:rtl condition="view/is_rtl">»</tal:rtl>
    </span>
    <span tal:repeat="crumb view/breadcrumbs"
        ...
    </span>

</div>

Now we need to make the plone.path_bar viewlet use this template for rendering.

3. Overriding a class that renders the template
Since ZCML declaration for plone.path_bar in lib/python/plone/app/layout/viewlets/configure.zcml uses a class instead of a simple template the core of customization is overriding that class also. For doing this we will simply subclass the default viewlet's class and apply our changes, so that they could override default ones. You have seen the default class used for this viewlet above in this page.

So, to subclass PathBarViewlet class we should add a new viewlets.py into MyTheme/browser/. This will be the place where you override classes, used for viewlets. Add the following to your viewlets.py:
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

from plone.app.layout.viewlets import common

class PathBarViewlet(common.PathBarViewlet):
    """A custom version of the path bar class
    """

    render = ViewPageTemplateFile('path_bar.pt')

As you can see we create a new class PathBarViewlet, that is a subclass of common.PathBarViewlet default class for the plone.path_bar viewlet. The only thing we need to override is the template used for rendering the viewlet. We already have customized path_bar.pt inside MyTheme/browser/, thus our new class reffers to our customized template.

3.1. Theme compatibility between different 3.x versions of Plone
Version 1.1.3 of the plone.app.layout egg was released in July of 2008. As of this version, the viewlet template is controlled via the 'index' attribute rather than 'render', because 'index' can be overridden by using the ZCML template attribute, removing the need for a special viewlet subclass. If you need to make a subclass anyway, you can continue to use the render directive as mentioned above if you want to, or you can use "index" instead, like this:
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

from plone.app.layout.viewlets import common

class PathBarViewlet(common.PathBarViewlet):
    """A custom version of the path bar class
    """

    index = ViewPageTemplateFile('path_bar.pt')

If you're going to distribute your theme and need to maintain backwards compatibility with the Plone 3.0.x series, additional code needs to be included. You should add the following lines that make the render method defer to the 'index' attribute. (This is done in ViewletBase in Plone 3.1.x, but not in Plone 3.0.x.):
from plone.app.layout.viewlets import common

class PathBarViewlet(common.PathBarViewlet):
    """A custom version of the path bar class
    """

    def render(self):
        # defer to index method, because that's what gets overridden by the template ZCML attribute
        return self.index()

    index = ViewPageTemplateFile('path_bar.pt')

Otherwise, themes created with newer versions of plone.app.layout will not be compatible with older versions of Plone.

That's it with the class. In case you need to customize not only the template, but viewlet's behavior, this is the right place to do so.

So far so good - we have the customized class, that uses the customized template. Now we need to register these customizations with MyTheme/browser/configure.zcml.

4. Register the custom viewlet in configure.zcml
In order to register the customized class with the plone.path_bar viewlet, we simply copy the portion of ZCML code that we found in lib/python/plone/app/layout/viewlets/configure.zcml (see above in this page) into MyTheme/browser/configure.zcml, and edit it to make sure it uses the right class and right interfaces for the manager and the Zope 3 skin layer:
<!-- The customized breadcrumbs -->
<browser:viewlet
    name="plone.path_bar"
    manager="plone.app.layout.viewlets.interfaces.IPortalTop"
    class=".viewlets.PathBarViewlet"
    layer=".interfaces.IThemeSpecific"
    permission="zope2.View"
    />

name and permission remain the same as in the default viewlet declaration. Although you could change name to make it clear that this is not a standard viewlet. You could use something like "MyTheme.path_bar" as the name here.

For manager we use the full dotted path to IPortalTop interface, implemented by plone.portaltop viewlet manager.

And the core part of our customization - we switch class to our customized class from MyTheme/browser/viewlets.py.

5. Additional step (Only if you have changed name for viewlet in ZCML)
If you have renamed your custom viewlet to "MyTheme.path_bar", you have created a new viewlet that has to be registered in your Generic Setup profile. To not have 2 path bars in your site, you should also hide the default plone.path_bar viewlet.

6. Done
Now you can restart your Zope. If you have your theme installed already, you need to reinstall it from Site Setup > Add-on Products.

Many thanks to this article.

Wednesday, January 18, 2012

Plone 4: Adding vocabulary to a Content Type field (Archetype)

A while back, I needed to use vocabularies with Archetypes. Being still new in Plone, I rummaged the internet for a while. This is the way I did it on Plone 4.

  1. First, I create a vocab.py in the package's root, alongside configure.zcml, then put my vocabularies there:
    from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 
    
    def MyVocabulary(context): 
    
       items = [ 
         ("value1", u"This is label for item"), 
         ("value2", u"This is   label for value 2")] 
    
       terms = [ SimpleTerm(value=pair[0], token=pair[0], 
                         title=pair[1]) for pair in items ] 
    
       return SimpleVocabulary(terms) 

    A 'titled' vocabulary like this one will, for example, allow you to use a UID as a form's returned value but display a human-readable title by a checkbox.
    I've generally found it easiest to use the SimpleVocab classes.
  2. This needs registering as a named IVocabularyFactory utility in configure.zcml:
     <utility 
             provides="zope.schema.interfaces.IVocabularyFactory" 
             component=".vocab.MyVocabulary" 
             name="MyVocabularyName" 
             /> 
    
  3. Then you can use this in a schema:
    class MyWidgetSchema(interface.Interface): 
    
         categories = schema.Set( 
             value_type = schema.Choice(
                           vocabulary = u"MyVocabularyName", 
                           title = u"Favourite Things"), 
             default = set(), 
             title = u"Favourite Things" 
         ) 
    
    or
    atapi.StringField('item_favourite',
            required = 1,
            vocabulary_factory = u"MyVocabularyName",
            widget = atapi.SelectionWidget(
                label = _('Favourite Things'),
                description = _('Favourite Things'),
            ),
        ),
     
I hope this might help some poor soul out there.

Wednesday, January 4, 2012

Linux Server Hardening Security Tips

Securing your Linux server is important to protect your data, intellectual property, and time, from the hands of crackers (hackers). The system administrator is responsible for security Linux box.


The link below provides 20 hardening tips for default installation of Linux system.


20 Linux Server Hardening Security Tips

You can thank me later.