Skip to content
This repository
  • 2 commits
  • 13 files changed
  • 0 comments
  • 1 contributor
Apr 04, 2012
hoozecn 1. modify forbidden response
2.
e7aa6e1
hoozecn resolve setting.py
Merge branch 'master' of github.com:hoozecn/migrationtool

Conflicts:
	settings.py
cae809f
1  .gitignore
@@ -2,6 +2,7 @@
2 2
 *.swp
3 3
 secret.py
4 4
 *.log
  5
+.*
5 6
 
6 7
 # Packages
7 8
 *.egg
10  auth/views.py
@@ -29,8 +29,8 @@ def __init__(self, title = "403 Forbidden"):
29 29
 
30 30
 class Http405(HttpResponseNotAllowed):
31 31
   """My NotAllowed class"""
32  
-  def __init__(self, title = "405 Not Allowed"):
33  
-    HttpResponseNotAllowed.__init__(self, '<h1>%s<h1>' % title)
  32
+  def __init__(self, title = ""):
  33
+    HttpResponseNotAllowed.__init__(self, ['GET'])
34 34
 
35 35
 def login(request, template = 'login.html'):
36 36
   """using openid to login
@@ -179,7 +179,8 @@ def installApp(request, app_user, redirect = quote_plus("/")):
179 179
                                firstname = app_user.firstname,
180 180
                                lastname = app_user.lastname,
181 181
                                language = app_user.language,
182  
-                               create_date = datetime.today())
  182
+                               create_date = datetime.today(),
  183
+                               last_login_time = datetime.now())
183 184
       domain_admin.save()
184 185
 
185 186
     storeLoginUser(request, domain_admin)
@@ -188,7 +189,8 @@ def installApp(request, app_user, redirect = quote_plus("/")):
188 189
 
189 190
   except Unauthorized: # install app from marketplace
190 191
     return HttpResponseBadRequest("Please install the app from marketplace.")
191  
-  except Error:
  192
+  except Error, e:
  193
+    logger.error(e)
192 194
     return HttpResponseBadRequest("Some error happends, "
193 195
                                   "when installing the app.")
194 196
   except Exception, e:
48  engine/google.py
@@ -16,30 +16,44 @@
16 16
 from gdata.contacts.client import ContactsClient
17 17
 from gdata.contacts.data import ContactsFeed
18 18
 from globalutils import parseEmail
19  
-from globalvars import MIGRATION_STATUS as STATS
  19
+from globalvars import MIGRATION_STATUS as STATS, BATCH_MAX_NUM
20 20
 from oauth_services import NewContactsClient, NewCalendarClient
21 21
 
22  
-max_num = 90
  22
+
  23
+class GoogleContactsMap(object):
  24
+  def __init__(self, contacts, groups):
  25
+    self._contacts = contacts
  26
+    self._groups = groups
  27
+
  28
+  @property
  29
+  def contacts(self):
  30
+    return self._contacts
  31
+
  32
+  @property
  33
+  def groups(self):
  34
+    return self._groups
  35
+
23 36
 
24 37
 class GoogleMigrator(ImapMigrator):
25 38
   def __init__(self, *args, **kargs):
26 39
     ImapMigrator.__init__(self, *args, **kargs)
27 40
 
28 41
   def performLogin(self, client, service):
29  
-    try:
30  
-      client.ClientLogin(email = self.apps_user.legacy_user,
  42
+#    try:
  43
+    client.ClientLogin(email = self.apps_user.legacy_user,
31 44
                          password = self.apps_user.legacy_password,
32 45
                          source = 'gmail-migrator',
33 46
                          service = service)
34  
-    except BadAuthentication, e:
35  
-      self.getUserLog("Authentication is error. "
36  
-                      "Please check the username and password.", True)
37  
-      self.log("Authentication error. %s" % e)
38  
-      raise AuthorizeError()
39  
-    except RequestError, e:
40  
-      self.getUserLog("Unknow error happens when fetching resource.", True)
41  
-      self.log("Request error %s.", e)
42  
-      raise self.StepError()
  47
+
  48
+#    except BadAuthentication, e:
  49
+#      self.getUserLog("Invalid Authentication. "
  50
+#                      "Please check the username and password.", True)
  51
+#      self.log("Reason: %s" % e)
  52
+#      raise AuthorizeError()
  53
+#    except RequestError, e:
  54
+#      self.getUserLog("Unknow error happens when fetching resource.", True)
  55
+#      self.log("Request error %s.", e)
  56
+#      raise self.StepError()
43 57
 
44 58
   def fetchContacts(self):
45 59
     '''Throw AuthorizeError StepError
@@ -47,7 +61,7 @@ def fetchContacts(self):
47 61
     _, domain = parseEmail(self.apps_user.legacy_user)
48 62
     client = ContactsClient(domain = domain)
49 63
     _ = self.performLogin(client, 'cp') # require contacts api
50  
-    query = Query(max_results = 20000)
  64
+    query = Query(max_results = 25000)
51 65
     request = client.ModifyRequest(None)
52 66
     query.ModifyRequest(request)
53 67
     return client.GetContacts(http_request = request).entry
@@ -105,7 +119,7 @@ def migrateCalendar(self, calendar):
105 119
     new_calendar_acl_id = self._convertHttpToHttps(new_calendar.find_acl_link())
106 120
 
107 121
     if event_feeds_id:
108  
-      query = Query(max_results = max_num)
  122
+      query = Query(max_results = BATCH_MAX_NUM)
109 123
       request = client.ModifyRequest(None)
110 124
       query.ModifyRequest(request)
111 125
       feed = self.legacy_cal_client.GetCalendarEventFeed(event_feeds_id)
@@ -192,8 +206,8 @@ def _doUpload(_contacts):
192 206
 
193 207
     success_num = 0
194 208
     while len(contacts) > 0:
195  
-      batch_contacts = contacts[:max_num]
196  
-      contacts = contacts[max_num:]
  209
+      batch_contacts = contacts[:BATCH_MAX_NUM]
  210
+      contacts = contacts[BATCH_MAX_NUM:]
197 211
       success_num += len(_doUpload(batch_contacts).entry)
198 212
 
199 213
     self.getUserLog("Migrate %d contacts successfully." % success_num, True)
1  engine/imap.py
@@ -834,7 +834,6 @@ def startMigrateEmail(self):
834 834
             if email_is_real:
835 835
               content = "Migrate email %s successfully" % msg_id
836 836
               self.getUserLog(content, True)
837  
-              self.log(content, 'info')
838 837
 
839 838
             migrated_email.result = email_is_real
840 839
             migrated_email.save()
4  engine/migrator.py
@@ -86,7 +86,7 @@ def log(self, content, level = 'debug'):
86 86
     getattr(self.logger, level)(content + ". appuser: %s(%d)" % \
87 87
                                 (self.apps_user.email, self.apps_user.key))
88 88
 
89  
-  def getUserLog(self, content = "", save = False):
  89
+  def getUserLog(self, content = "", save = False, level = 'info'):
90 90
     userlog = UserLog(user = self.apps_user,
91 91
               operator = self.operator,
92 92
               time = datetime.now())
@@ -95,7 +95,7 @@ def getUserLog(self, content = "", save = False):
95 95
 
96 96
     if save:
97 97
       userlog.save()
98  
-      self.log(content, 'info')
  98
+      self.log(content, level)
99 99
 
100 100
     return userlog
101 101
 
2  enginectrl.sh 100755 → 100644
@@ -9,6 +9,7 @@ function kill(){
9 9
   if [ -f $PID ]; then
10 10
     sudo kill -TERM `cat $PID`;
11 11
     sudo rm $PID;
  12
+    sudo rm $SOCK;
12 13
     echo "kill django process succeed."
13 14
   fi
14 15
   if [ -f $DeamonPID ]; then
@@ -22,7 +23,6 @@ function start(){
22 23
   sudo env python manage.py runfcgi socket=$SOCK daemonize=true pidfile=$PID
23 24
   sudo env python deamon.py
24 25
   sudo chown www-data $SOCK
25  
-  sudo nginx -s reload 2>/dev/null || sudo nginx
26 26
 }
27 27
 
28 28
 if [ "$1x" = "startx" ]; then
1  globalvars.py
@@ -77,4 +77,5 @@ class SHEET_COLS(Enum):
77 77
 
78 78
 ENGINE = None
79 79
 
  80
+BATCH_MAX_NUM = 90
80 81
 
15  home/models.py
... ...
@@ -1,6 +1,7 @@
1 1
 from django.db import models as db
2 2
 from globalutils import parseEmail
3 3
 from globalvars import INIT_LICENSE
  4
+import datetime
4 5
 
5 6
 # Create your models here.
6 7
 class AppsDomain(db.Model):
@@ -30,7 +31,7 @@ class DomainAdmin(db.Model):
30 31
   oauth_secret = db.CharField(max_length = 30, default = "")
31 32
   access_key = db.CharField(max_length = 60, default = "")
32 33
   create_date = db.DateField(blank = False)
33  
-  last_login_time = db.DateTimeField(blank = True)
  34
+  last_login_time = db.DateTimeField()
34 35
 
35 36
   def __unicode__(self):
36 37
     return self.nickname
@@ -56,7 +57,6 @@ def domain_name(self):
56 57
 def _formatDate(date):
57 58
   return date.strftime("%m/%d/%Y")
58 59
 
59  
-import datetime
60 60
 MBytes = 1000000
61 61
 
62 62
 # Create your models here.
@@ -308,6 +308,17 @@ def __unicode__(self):
308 308
   def html(self):
309 309
     return "<p>" + cgi.escape(unicode(self)) + "</p>"
310 310
 
  311
+class MigratedData(db.Model):
  312
+  apps_user = db.ForeignKey('AppsUser')
  313
+  size = db.IntegerField(default = 0)
  314
+  uid = db.CharField(max_length = 16)
  315
+  time = db.DateTimeField()
  316
+  result = db.BooleanField(default = False)
  317
+
  318
+  class meta:
  319
+    abstract = True
  320
+
  321
+
311 322
 class MigratedEmail(db.Model):
312 323
   apps_user = db.ForeignKey('AppsUser')
313 324
   size = db.IntegerField(default = 0)
4  home/views.py
@@ -51,7 +51,7 @@ def test(request):
51 51
 @requireLogin
52 52
 def getSheetList(request):
53 53
   if request.method != 'POST':
54  
-    return HttpResponseNotAllowed("")
  54
+    return HttpResponseNotAllowed(['POST'])
55 55
   query = request.REQUEST
56 56
   start = tryParseInt(query.get('start'), 1)
57 57
 
@@ -83,7 +83,7 @@ def getSheetList(request):
83 83
 @requireLogin
84 84
 def validateFile(request, action, **kargs):
85 85
   if request.method != 'POST':
86  
-    return HttpResponseNotAllowed('Not Allowed')
  86
+    return HttpResponseNotAllowed(['POST'])
87 87
   validateAction = ValidateAction(request)
88 88
   return validateAction(action)
89 89
 
0  manage.py 100755 → 100644
File mode changed
18  migration/userviews.py
@@ -38,7 +38,7 @@ def obj(self):
38 38
 @getMigrationDecorator
39 39
 def addUser(request, template = 'usersadd.html', **kargs):
40 40
   if request.method != 'GET':
41  
-    return HttpResponseNotAllowed('')
  41
+    return HttpResponseNotAllowed(['GET'])
42 42
 
43 43
   request.title = _('Add user') % \
44 44
     {'migration': request.migration.name}
@@ -73,7 +73,7 @@ def setCookie(response, request):
73 73
     setCookie(response, request)
74 74
     return response
75 75
   else:
76  
-    return HttpResponseNotAllowed('')
  76
+    return HttpResponseNotAllowed(['GET', 'POST'])
77 77
 
78 78
 from urllib import unquote_plus
79 79
 def fetchUsers(request):
@@ -150,7 +150,7 @@ def single(request, template = 'single.html', **kargs):
150 150
   elif request.method == 'POST':
151 151
     return addOrUpdateUser(request)
152 152
   else:
153  
-    return HttpResponseNotAllowed('')
  153
+    return HttpResponseNotAllowed(['GET', 'POST'])
154 154
 
155 155
 from django.core.cache import cache
156 156
 def generateCacheKey(request):
@@ -223,12 +223,12 @@ def bulk(request, template = 'bulk.html', **kargs):
223 223
       'lic': request.migration.domain.license_remain
224 224
       }))
225 225
   else:
226  
-    return HttpResponseNotAllowed('')
  226
+    return HttpResponseNotAllowed(['GET', 'POST'])
227 227
 
228 228
 @getMigrationDecorator
229 229
 def getUploadLog(request, **kargs):
230 230
   if request.method != 'GET':
231  
-    return HttpResponseNotAllowed('')
  231
+    return HttpResponseNotAllowed(['GET'])
232 232
 
233 233
   cache_key = generateCacheKey(request)
234 234
   if not cache_key:
@@ -432,7 +432,7 @@ def modify(request, template = 'edituser.html', **kargs):
432 432
                                                    user.legacy_password,
433 433
                                                    user.app_user]}))
434 434
   else:
435  
-    return HttpResponseNotAllowed('')
  435
+    return HttpResponseNotAllowed(['GET', 'POST'])
436 436
 
437 437
 def edit_user(user, lu, pw, appu, operator):
438 438
   if user.status != MIGRATION_STATUS.NOT_STARTED:
@@ -454,7 +454,7 @@ def edit_user(user, lu, pw, appu, operator):
454 454
 @getMigrationDecorator
455 455
 def userActions(request, action, **kargs):
456 456
   if request.method != 'POST':
457  
-    return HttpResponseNotAllowed('Not Allowed')
  457
+    return HttpResponseNotAllowed(['POST'])
458 458
 
459 459
   users_json = request.REQUEST.get('users')
460 460
   if not users_json:
@@ -599,7 +599,7 @@ def userTest(request, template = "usertest.html", **kargs):
599 599
       context_instance = RequestContext(request))
600 600
 
601 601
   else:
602  
-    return HttpResponseNotAllowed('')
  602
+    return HttpResponseNotAllowed(['GET'])
603 603
 
604 604
 @getAppsUserDecorator
605 605
 def userTestActions(request, action, template = "usertest.html", **kargs):
@@ -607,7 +607,7 @@ def userTestActions(request, action, template = "usertest.html", **kargs):
607 607
     return UserTestActions(request)(action)
608 608
 
609 609
   else:
610  
-    return HttpResponseNotAllowed('')
  610
+    return HttpResponseNotAllowed(['GET', 'POST'])
611 611
 
612 612
 from engine.imap import ImapMigrator
613 613
 from engine.migrator import Migrator
6  migration/views.py
@@ -40,7 +40,7 @@ def modify(request, template = 'settings.html', **kargs):
40 40
     return HttpResponse(simplejson.dumps({'action':'del', 'result': result,
41 41
                                           'license': request.domain.license_remain, 'reason': reason}))
42 42
   else:
43  
-    return HttpResponseNotAllowed()
  43
+    return HttpResponseNotAllowed(['GET', 'POST', 'DELETE'])
44 44
 
45 45
 @requireLogin
46 46
 def create(request, template = 'settings.html'):
@@ -54,7 +54,7 @@ def create(request, template = 'settings.html'):
54 54
     return updateOrAddMigration(request)
55 55
 
56 56
   else:
57  
-    return HttpResponseNotAllowed()
  57
+    return HttpResponseNotAllowed(['GET', 'POST'])
58 58
 
59 59
 @requireLogin
60 60
 def validateName(request, migration_id):
@@ -63,7 +63,7 @@ def validateName(request, migration_id):
63 63
   #logger.debug('Post dict ' + simplejson.dumps(request.POST))
64 64
 
65 65
   if method != 'POST' or not name:
66  
-    return HttpResponseNotAllowed('')
  66
+    return HttpResponseNotAllowed(['POST'])
67 67
 
68 68
   migration = getMigration(migration_id)
69 69
   if not migration or migration.name != name:
6  settings.py
... ...
@@ -1,13 +1,13 @@
1 1
 # coding: utf8
2 2
 """Django settings for migrationtool project."""
3 3
 from os import path
4  
-from secret import PROJECT_NAME, DB_USERNAME, DB_PASSWORD, ADMIN, \
  4
+from secret import PROJECT_NAME, DB_PASSWORD, DB_USERNAME, ADMIN, \
5 5
   DB_HOST, DB_PORT
6 6
 
7 7
 try:
8 8
   from secret import Debug
9 9
 except:
10  
-  Debug = False
  10
+  Debug = True
11 11
 
12 12
 DEBUG = Debug
13 13
 TEMPLATE_DEBUG = True
@@ -49,7 +49,7 @@ def absPath(pathname):
49 49
 # timezone as the operating system.
50 50
 # If running in a Windows environment this must be set to the same as your
51 51
 # system time zone.
52  
-TIME_ZONE = 'America/Los_Angeles'
  52
+TIME_ZONE = 'Europe/Paris'
53 53
 
54 54
 # Language code for this installation. All choices can be found here:
55 55
 # http://www.i18nguy.com/unicode/language-identifiers.html

No commit comments for this range

Something went wrong with that request. Please try again.