0
|
1 |
#!/usr/bin/env python
|
|
2 |
#
|
|
3 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
# All rights reserved.
|
|
5 |
# This component and the accompanying materials are made available
|
|
6 |
# under the terms of "Eclipse Public License v1.0"
|
|
7 |
# which accompanies this distribution, and is available
|
|
8 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
#
|
|
10 |
# Initial Contributors:
|
|
11 |
# Nokia Corporation - initial contribution.
|
|
12 |
#
|
|
13 |
# Contributors:
|
|
14 |
#
|
3
|
15 |
# Description:
|
|
16 |
#
|
|
17 |
##
|
|
18 |
# @author Teemu Rytkonen
|
0
|
19 |
|
|
20 |
import os
|
|
21 |
import logging
|
|
22 |
import codecs
|
|
23 |
|
|
24 |
from optparse import OptionParser, OptionGroup
|
|
25 |
|
|
26 |
import cone_common
|
|
27 |
from cone.public import api, plugin, utils, exceptions, container
|
|
28 |
|
|
29 |
VERSION = '1.0'
|
|
30 |
|
|
31 |
logger = logging.getLogger('cone')
|
|
32 |
elems = {
|
|
33 |
'Type': 0,
|
|
34 |
'Name': 1,
|
|
35 |
'ParentFolderName': 2,
|
|
36 |
'URL': 3,
|
|
37 |
'AccessPoint': 4,
|
|
38 |
'UserName': 5,
|
|
39 |
'Password': 6,
|
|
40 |
'ReadOnly': 7,
|
|
41 |
'FactoryItem': 8,
|
|
42 |
'ContextId': 9,
|
|
43 |
'Preferred': 10
|
|
44 |
}
|
|
45 |
|
|
46 |
def main():
|
|
47 |
parser = OptionParser(version="%%prog %s" % VERSION)
|
|
48 |
|
|
49 |
parser.add_option("-c", "--configuration",\
|
|
50 |
dest="configuration",\
|
|
51 |
help="defines the name of the configuration for the action",\
|
|
52 |
metavar="CONFIG")
|
|
53 |
|
|
54 |
parser.add_option("-v", "--verbose",\
|
|
55 |
dest="verbose",\
|
|
56 |
help="Print error,warning and information on system out. \
|
|
57 |
Possible choises: Default is 3.\
|
|
58 |
NONE 0.\
|
|
59 |
CRITICAL 1\
|
|
60 |
ERROR 2\
|
|
61 |
WARNING 3\
|
|
62 |
INFO 4\
|
|
63 |
DEBUG 5\
|
|
64 |
",\
|
|
65 |
default=3,\
|
|
66 |
metavar="LEVEL")
|
|
67 |
parser.add_option("-p", "--project",\
|
|
68 |
dest="project",\
|
|
69 |
help="defines the location of current project. Default is the current working directory.",\
|
|
70 |
default=".",\
|
|
71 |
metavar="STORAGE")
|
|
72 |
|
|
73 |
bgroup = OptionGroup(parser, 'Import browser bookmarks options',
|
|
74 |
'The import_browserbookmarks functionality is meant to import browser bookmarks to a given configuration.')
|
|
75 |
|
|
76 |
bgroup.add_option("-i", "--input",\
|
|
77 |
dest="input",\
|
|
78 |
type="string",
|
|
79 |
help="input BrowserBookmarks file for the importing.",
|
|
80 |
metavar="FILE",\
|
|
81 |
default=None)
|
|
82 |
|
|
83 |
layers = None
|
|
84 |
current = None
|
|
85 |
|
|
86 |
parser.add_option_group(bgroup)
|
|
87 |
(options, args) = parser.parse_args()
|
|
88 |
|
|
89 |
api.get_console_logger().setLevel(cone_common.get_log_level(options.verbose))
|
|
90 |
|
|
91 |
if not options.input:
|
|
92 |
parser.error("Input file must be given!")
|
|
93 |
|
|
94 |
logger.info('Open file %s.' % options.input)
|
|
95 |
|
|
96 |
|
|
97 |
current = api.Project(api.Storage.open(options.project,"a"))
|
|
98 |
active_root = current.get_storage().get_active_configuration()
|
|
99 |
if not options.configuration:
|
|
100 |
if active_root == "":
|
|
101 |
parser.error("configuration must be given")
|
|
102 |
else:
|
|
103 |
logging.getLogger('cone').info('No configuration given! Using active root configuration %s' % active_root)
|
|
104 |
options.configuration = active_root
|
|
105 |
config = current.get_configuration(options.configuration)
|
|
106 |
dview = config.get_default_view()
|
|
107 |
bookmarkfea = dview.get_feature('BookmarkItems.BookmarkItem')
|
|
108 |
|
|
109 |
inputfile = codecs.open(options.input,encoding="utf16")
|
|
110 |
firstelem = True
|
|
111 |
for line in inputfile.readlines():
|
|
112 |
# skip comments
|
|
113 |
data = line.split('#',1)
|
|
114 |
dataelem = data[0]
|
|
115 |
dataelem = dataelem.strip()
|
|
116 |
dataelem = dataelem.rstrip('\n')
|
|
117 |
|
|
118 |
if dataelem != "":
|
|
119 |
# Split the datarow in to data elems
|
|
120 |
#print "DATAELEM: %s!" % dataelem
|
|
121 |
dataelems = dataelem.split(',')
|
|
122 |
print "Elem found %s" % str(dataelems[elems['Name']])
|
|
123 |
# Build the new data sequence
|
|
124 |
browserseq = []
|
|
125 |
for feaname in bookmarkfea.list_features():
|
|
126 |
try:
|
|
127 |
browserseq.append(str(dataelems[elems[feaname]]))
|
|
128 |
except IndexError:
|
|
129 |
pass
|
|
130 |
|
|
131 |
print browserseq
|
|
132 |
if firstelem:
|
|
133 |
bookmarkfea.add_sequence(browserseq, policy=container.REPLACE)
|
|
134 |
data = bookmarkfea.get_data()[-1]
|
|
135 |
data._get_data().policy = 'replace'
|
|
136 |
firstelem = False
|
|
137 |
else:
|
|
138 |
bookmarkfea.add_sequence(browserseq, policy=container.APPEND)
|
|
139 |
|
|
140 |
config.save()
|
|
141 |
|
|
142 |
logger.info('Done!')
|
|
143 |
|
|
144 |
if __name__ == "__main__":
|
|
145 |
main()
|
|
146 |
|
|
147 |
|