#!/usr/bin/env python
"""
Mark some package to be unmasked and unstable at the same time.
You need to run this as sudo.
"""


def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-c', '--comment', action='store',
                      default=None,
                      help="Comment to be added to the log file.")

    opts, args = parser.parse_args()
    if len(args) != 1:
        parser.error("You must specify a full package name.")
    package = args[0]


    f = open('/etc/portage/package.unmask', 'a+')
    f.seek(0, 2) # SEEK_END

    comment = opts.comment and ('# %s\n' % opts.comment.replace('\n', ';')) or None

    if comment:
        f.write(comment)
    f.write(package)
    f.write('\n')
    f.close()
    
    f = open('/etc/portage/package.keywords', 'a+')
    if comment:
        f.write(comment)
    f.write(package)
    f.write(' ~x86\n')
    f.close()


if __name__ == '__main__':
    main()


