prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  allow non-root installation on Linux
  I want to install Electrum on my Ubuntu machine in my user's `$HOME` directory, i.e., not via `sudo`.  If I run the command
  
  ```
  pip install https://download.electrum.org/2.5.4/Electrum-2.5.4.tar.gz
  ```
  
  I get an error when the installation tries to create a desktop shortcut:
  
  ```
  copying electrum.desktop -> /usr/share/applications/
  
  error: [Errno 13] Permission denied: '/usr/share/applications/electrum.desktop'
  ```
  
  Maybe the installation script could `try` if this copy operation works, and try again at `$HOME/.local/share/applications` (or, better, `$XDG_DATA_HOME/applications`) in case it doesn't.
  
  If you agree this would make sense and point me to the file where I would need to do this, I'd be happy to provide a PR.
  
  
  </issue>
  <code>
  [start of setup.py]
  1 #!/usr/bin/env python2
  2 
  3 # python setup.py sdist --format=zip,gztar
  4 
  5 from setuptools import setup
  6 import os
  7 import sys
  8 import platform
  9 import imp
  10 
  11 version = imp.load_source('version', 'lib/version.py')
  12 
  13 if sys.version_info[:3] < (2, 7, 0):
  14     sys.exit("Error: Electrum requires Python version >= 2.7.0...")
  15 
  16 data_files = []
  17 
  18 if platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:
  19     usr_share = os.path.join(sys.prefix, "share")
  20     data_files += [
  21         (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),
  22         (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])
  23     ]
  24 
  25 setup(
  26     name="Electrum",
  27     version=version.ELECTRUM_VERSION,
  28     install_requires=[
  29         'slowaes>=0.1a1',
  30         'ecdsa>=0.9',
  31         'pbkdf2',
  32         'requests',
  33         'qrcode',
  34         'protobuf',
  35         'dnspython',
  36         'jsonrpclib',
  37     ],
  38     packages=[
  39         'electrum',
  40         'electrum_gui',
  41         'electrum_gui.qt',
  42         'electrum_plugins',
  43         'electrum_plugins.audio_modem',
  44         'electrum_plugins.cosigner_pool',
  45         'electrum_plugins.email_requests',
  46         'electrum_plugins.exchange_rate',
  47         'electrum_plugins.greenaddress_instant',
  48         'electrum_plugins.keepkey',
  49         'electrum_plugins.labels',
  50         'electrum_plugins.ledger',
  51         'electrum_plugins.plot',
  52         'electrum_plugins.trezor',
  53         'electrum_plugins.trustedcoin',
  54         'electrum_plugins.virtualkeyboard',
  55     ],
  56     package_dir={
  57         'electrum': 'lib',
  58         'electrum_gui': 'gui',
  59         'electrum_plugins': 'plugins',
  60     },
  61     package_data={
  62         'electrum': [
  63             'www/index.html',
  64             'wordlist/*.txt',
  65             'locale/*/LC_MESSAGES/electrum.mo',
  66         ]
  67     },
  68     scripts=['electrum'],
  69     data_files=data_files,
  70     description="Lightweight Bitcoin Wallet",
  71     author="Thomas Voegtlin",
  72     author_email="thomasv@electrum.org",
  73     license="GNU GPLv3",
  74     url="https://electrum.org",
  75     long_description="""Lightweight Bitcoin Wallet"""
  76 )
  77
  [end of setup.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/setup.py b/setup.py
  old mode 100644
  new mode 100755
  --- a/setup.py
  +++ b/setup.py
  @@ -17,6 +17,11 @@
   
   if platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:
       usr_share = os.path.join(sys.prefix, "share")
  +    if not os.access(usr_share, os.W_OK):
  +        if 'XDG_DATA_HOME' in os.environ.keys():
  +            usr_share = os.environ['$XDG_DATA_HOME']
  +        else:
  +            usr_share = os.path.expanduser('~/.local/share')
       data_files += [
           (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),
           (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])
  
verification_info: {"golden_diff": "diff --git a/setup.py b/setup.py\nold mode 100644\nnew mode 100755\n--- a/setup.py\n+++ b/setup.py\n@@ -17,6 +17,11 @@\n \n if platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:\n     usr_share = os.path.join(sys.prefix, \"share\")\n+    if not os.access(usr_share, os.W_OK):\n+        if 'XDG_DATA_HOME' in os.environ.keys():\n+            usr_share = os.environ['$XDG_DATA_HOME']\n+        else:\n+            usr_share = os.path.expanduser('~/.local/share')\n     data_files += [\n         (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),\n         (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])\n", "issue": "allow non-root installation on Linux\nI want to install Electrum on my Ubuntu machine in my user's `$HOME` directory, i.e., not via `sudo`.  If I run the command\n\n```\npip install https://download.electrum.org/2.5.4/Electrum-2.5.4.tar.gz\n```\n\nI get an error when the installation tries to create a desktop shortcut:\n\n```\ncopying electrum.desktop -> /usr/share/applications/\n\nerror: [Errno 13] Permission denied: '/usr/share/applications/electrum.desktop'\n```\n\nMaybe the installation script could `try` if this copy operation works, and try again at `$HOME/.local/share/applications` (or, better, `$XDG_DATA_HOME/applications`) in case it doesn't.\n\nIf you agree this would make sense and point me to the file where I would need to do this, I'd be happy to provide a PR.\n\n", "before_files": [{"content": "#!/usr/bin/env python2\n\n# python setup.py sdist --format=zip,gztar\n\nfrom setuptools import setup\nimport os\nimport sys\nimport platform\nimport imp\n\nversion = imp.load_source('version', 'lib/version.py')\n\nif sys.version_info[:3] < (2, 7, 0):\n    sys.exit(\"Error: Electrum requires Python version >= 2.7.0...\")\n\ndata_files = []\n\nif platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:\n    usr_share = os.path.join(sys.prefix, \"share\")\n    data_files += [\n        (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),\n        (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])\n    ]\n\nsetup(\n    name=\"Electrum\",\n    version=version.ELECTRUM_VERSION,\n    install_requires=[\n        'slowaes>=0.1a1',\n        'ecdsa>=0.9',\n        'pbkdf2',\n        'requests',\n        'qrcode',\n        'protobuf',\n        'dnspython',\n        'jsonrpclib',\n    ],\n    packages=[\n        'electrum',\n        'electrum_gui',\n        'electrum_gui.qt',\n        'electrum_plugins',\n        'electrum_plugins.audio_modem',\n        'electrum_plugins.cosigner_pool',\n        'electrum_plugins.email_requests',\n        'electrum_plugins.exchange_rate',\n        'electrum_plugins.greenaddress_instant',\n        'electrum_plugins.keepkey',\n        'electrum_plugins.labels',\n        'electrum_plugins.ledger',\n        'electrum_plugins.plot',\n        'electrum_plugins.trezor',\n        'electrum_plugins.trustedcoin',\n        'electrum_plugins.virtualkeyboard',\n    ],\n    package_dir={\n        'electrum': 'lib',\n        'electrum_gui': 'gui',\n        'electrum_plugins': 'plugins',\n    },\n    package_data={\n        'electrum': [\n            'www/index.html',\n            'wordlist/*.txt',\n            'locale/*/LC_MESSAGES/electrum.mo',\n        ]\n    },\n    scripts=['electrum'],\n    data_files=data_files,\n    description=\"Lightweight Bitcoin Wallet\",\n    author=\"Thomas Voegtlin\",\n    author_email=\"thomasv@electrum.org\",\n    license=\"GNU GPLv3\",\n    url=\"https://electrum.org\",\n    long_description=\"\"\"Lightweight Bitcoin Wallet\"\"\"\n)\n", "path": "setup.py"}]}