public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][Patch] : Fix PG utilities with Python 2.6
4+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][Patch] : Fix PG utilities with Python 2.6
@ 2018-06-15 11:27  Khushboo Vashi <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Khushboo Vashi @ 2018-06-15 11:27 UTC (permalink / raw)
  To: pgadmin-hackers

Hi,

Please find the attached patch which fixes the PG utilities with python 2.6.

Thanks,
Khushboo


Attachments:

  [application/octet-stream] pg_utility_py26_fix.patch (553B, 3-pg_utility_py26_fix.patch)
  download | inline diff:
diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py
index 44b3362..cb98291 100644
--- a/web/pgadmin/misc/bgprocess/processes.py
+++ b/web/pgadmin/misc/bgprocess/processes.py
@@ -172,7 +172,7 @@ class BatchProcess(object):
         csv_writer = csv.writer(
             args_csv_io, delimiter=str(','), quoting=csv.QUOTE_MINIMAL
         )
-        if sys.version_info.major == 2:
+        if sys.version_info[0] == 2:
             csv_writer.writerow(
                 [
                     a.encode('utf-8')


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin4][Patch] : Fix PG utilities with Python 2.6
@ 2018-06-15 11:38  Dave Page <[email protected]>
  parent: Khushboo Vashi <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Dave Page @ 2018-06-15 11:38 UTC (permalink / raw)
  To: Khushboo Vashi <[email protected]>; +Cc: pgadmin-hackers

Thanks, applied.

On Fri, Jun 15, 2018 at 12:27 PM, Khushboo Vashi <
[email protected]> wrote:

> Hi,
>
> Please find the attached patch which fixes the PG utilities with python
> 2.6.
>
> Thanks,
> Khushboo
>



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin4][Patch] : Fix PG utilities with Python 2.6
@ 2018-06-15 13:55  Khushboo Vashi <[email protected]>
  parent: Dave Page <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Khushboo Vashi @ 2018-06-15 13:55 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave,

Please find the attached patch for PG utilities - PY 2.6.

Thanks,
Khushboo

On Fri, Jun 15, 2018 at 5:08 PM, Dave Page <[email protected]> wrote:

> Thanks, applied.
>
> On Fri, Jun 15, 2018 at 12:27 PM, Khushboo Vashi <
> [email protected]> wrote:
>
>> Hi,
>>
>> Please find the attached patch which fixes the PG utilities with python
>> 2.6.
>>
>> Thanks,
>> Khushboo
>>
>
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


Attachments:

  [text/x-patch] pg_utilities_fix_ver2.patch (4.0K, 3-pg_utilities_fix_ver2.patch)
  download | inline diff:
diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py
index cb98291..c6151e3 100644
--- a/web/pgadmin/misc/bgprocess/processes.py
+++ b/web/pgadmin/misc/bgprocess/processes.py
@@ -463,7 +463,7 @@ class BatchProcess(object):
                 stime = parser.parse(self.stime)
                 etime = parser.parse(self.etime or get_current_time())
 
-                execution_time = (etime - stime).total_seconds()
+                execution_time = BatchProcess.total_seconds(etime - stime)
 
             if process_output:
                 out, out_completed = read_log(
@@ -558,7 +558,7 @@ class BatchProcess(object):
             stime = parser.parse(p.start_time)
             etime = parser.parse(p.end_time or get_current_time())
 
-            execution_time = (etime - stime).total_seconds()
+            execution_time = BatchProcess.total_seconds(etime - stime)
             desc = ""
             try:
                 desc = loads(p.desc.encode('latin-1')) if \
@@ -601,6 +601,16 @@ class BatchProcess(object):
         return res
 
     @staticmethod
+    def total_seconds(dt):
+        # Keep backward compatibility with Python 2.6 which doesn't have
+        # this method
+        if hasattr(dt, 'total_seconds'):
+            return dt.total_seconds()
+        else:
+            return (dt.microseconds + (dt.seconds + dt.days * 24 * 3600) *
+                    10**6) / 10**6
+
+    @staticmethod
     def acknowledge(_pid):
         """
         Acknowledge from the user, he/she has alredy watched the status.
diff --git a/web/pgadmin/tools/backup/tests/test_batch_process.py b/web/pgadmin/tools/backup/tests/test_batch_process.py
index b020819..25342d4 100644
--- a/web/pgadmin/tools/backup/tests/test_batch_process.py
+++ b/web/pgadmin/tools/backup/tests/test_batch_process.py
@@ -119,7 +119,10 @@ class BatchProcessTest(BaseTestGenerator):
         current_app_mock.PGADMIN_RUNTIME = False
 
         def db_session_add_mock(j):
-            cmd_obj = loads(j.desc)
+            if sys.version_info < (2, 7):
+                cmd_obj = loads(str(j.desc))
+            else:
+                cmd_obj = loads(j.desc)
             self.assertTrue(isinstance(cmd_obj, IProcessDesc))
             self.assertEqual(cmd_obj.backup_type, self.class_params['type'])
             self.assertEqual(cmd_obj.bfile, self.class_params['bfile'])
diff --git a/web/pgadmin/tools/maintenance/tests/test_batch_process_maintenance.py b/web/pgadmin/tools/maintenance/tests/test_batch_process_maintenance.py
index f785c87..3700d96 100644
--- a/web/pgadmin/tools/maintenance/tests/test_batch_process_maintenance.py
+++ b/web/pgadmin/tools/maintenance/tests/test_batch_process_maintenance.py
@@ -73,7 +73,10 @@ class BatchProcessTest(BaseTestGenerator):
                 self.port = port
 
         def db_session_add_mock(j):
-            cmd_obj = loads(j.desc)
+            if sys.version_info < (2, 7):
+                cmd_obj = loads(str(j.desc))
+            else:
+                cmd_obj = loads(j.desc)
             self.assertTrue(isinstance(cmd_obj, IProcessDesc))
             self.assertEqual(cmd_obj.query, self.class_params['cmd'])
             self.assertEqual(cmd_obj.message, self.expected_msg)
diff --git a/web/pgadmin/tools/restore/tests/test_batch_process.py b/web/pgadmin/tools/restore/tests/test_batch_process.py
index ea33af2..8bc5ede 100644
--- a/web/pgadmin/tools/restore/tests/test_batch_process.py
+++ b/web/pgadmin/tools/restore/tests/test_batch_process.py
@@ -64,7 +64,10 @@ class BatchProcessTest(BaseTestGenerator):
         current_app_mock.PGADMIN_RUNTIME = False
 
         def db_session_add_mock(j):
-            cmd_obj = loads(j.desc)
+            if sys.version_info < (2, 7):
+                cmd_obj = loads(str(j.desc))
+            else:
+                cmd_obj = loads(j.desc)
             self.assertTrue(isinstance(cmd_obj, IProcessDesc))
             self.assertEqual(cmd_obj.bfile, self.class_params['bfile'])
             self.assertEqual(cmd_obj.cmd,


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin4][Patch] : Fix PG utilities with Python 2.6
@ 2018-06-15 14:06  Dave Page <[email protected]>
  parent: Khushboo Vashi <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Dave Page @ 2018-06-15 14:06 UTC (permalink / raw)
  To: Khushboo Vashi <[email protected]>; +Cc: pgadmin-hackers

Thanks, applied.

On Fri, Jun 15, 2018 at 2:55 PM, Khushboo Vashi <
[email protected]> wrote:

> Hi Dave,
>
> Please find the attached patch for PG utilities - PY 2.6.
>
> Thanks,
> Khushboo
>
> On Fri, Jun 15, 2018 at 5:08 PM, Dave Page <[email protected]> wrote:
>
>> Thanks, applied.
>>
>> On Fri, Jun 15, 2018 at 12:27 PM, Khushboo Vashi <
>> [email protected]> wrote:
>>
>>> Hi,
>>>
>>> Please find the attached patch which fixes the PG utilities with python
>>> 2.6.
>>>
>>> Thanks,
>>> Khushboo
>>>
>>
>>
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-06-15 14:06 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-15 11:27 [pgAdmin4][Patch] : Fix PG utilities with Python 2.6 Khushboo Vashi <[email protected]>
2018-06-15 11:38 ` Dave Page <[email protected]>
2018-06-15 13:55   ` Khushboo Vashi <[email protected]>
2018-06-15 14:06     ` Dave Page <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox