Atom install package error

Prerequisites Put an X between the brackets on this line if you have done all of the following: Reproduced the problem in Safe Mode: http://flight-manual.atom.io/hacking-atom/sections/debugging/#us...

I could not install packages in Atom, either. Nobody else’s tips worked for me, so below, I am posting what I did to get it to work.

I am running Fedora. Initially, I downloaded the Atom rpm package from the website, atom.io. I tried to install it by double-clicking it, but apper gave an error at the end.

I resort to Copr. There is a mosquito/atom package there. I enabled the repo and installed. At this point in the story, Atom is installed and working great.

The point of all this was just to edit a ReadMe with Markdown. I had the plain text on the left and the Markdown preview on the right, working spectacularly. Then something happens, an auto-update, I assume. After «the happening», whenever I edited the plain text, the preview would scroll to the bottom — extremely counter-productive and very annoying. I find the markdown-sync-scroll package, which was created to remedy this exact problem. I try to install the package, and it fails. I get an error about a version being undefined. The last line said «not ok».

I try installing the package from terminal using apm, with and without sudo, same error. I try updating nodejs and doing «npm rebuild». Same error. Uninstalling, reinstalling atom — same error.

Finally, I sudo dnf remove --purge atom. Then I delete /etc/yum.repos.d/_copr_mosquito-atom.repo. Then I go to the atom/atom ReadMe on github. I follow its link, download, and install that rpm by double-clicking it. This is not the one from the website, atom.io. Again, apper fails. But by luck, somehow I notice that it actually installed anyhow. I purged with dnf and tried to install the package via double-click several times before noticing that it actually does install, despite the apper error.

And this time, packages install. Now, I have Markdown editing how I want it! Yay!

I got an error when i install packages in Atom

    npm ERR! Windows_NT 6.2.9200
npm ERR! argv "C:\Users\Jarvis\AppData\Local\atom\app-1.5.3\resources\app\apm\bin\node.exe" "C:\Users\Jarvis\AppData\Local\atom\app-1.5.3\resources\app\apm\node_modules\npm\bin\npm-cli.js" "--globalconfig" "C:\Users\Jarvis\.atom\.apm\.apmrc" "--userconfig" "C:\Users\Jarvis\.atom\.apmrc" "install" "C:\Users\Jarvis\AppData\Local\Temp\d-116128-3752-1lwywgv\package.tgz" "--target=0.34.5" "--arch=ia32"
npm ERR! node v0.10.40
npm ERR! npm  v2.13.3
npm ERR! file C:UsersJarvis.atom.apmnopt3.0.6packagepackage.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token 'u0000' at 1:1
npm ERR! 
npm ERR! ^
npm ERR! File: C:UsersJarvis.atom.apmnopt3.0.6packagepackage.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

I am trying to install lots of packages in atom Editor but i got above error.

Richard Slater's user avatar

asked Feb 28, 2016 at 7:41

Sonu Kaushal's user avatar

If you open the C:UsersJarvis.atom.apmnopt3.0.6packagepackage.json with Notpad++ ( or any other editor your choice — just don’t do it in atom, it will crash, at least in Version 1.6.2 it did for me ) and look for the non printable characters. You will see that the file contain a lot of NUL. I had the same error suddenly one day, when trying to install updates for my packages.

Here is what i did to resolve the error. Be warned however that you have to install all packages again. Personally i use sync-settings (which backups my packages etc.), so it was no big deal for me.

  • Delete the entire C:UsersJarvis.atompackages folder
  • Delete the entier C:UsersJarvis.atom.apm folder
  • Reinstall all packages (.apm folders will then installed automatically)

It can be hard to delete those folders because of the Path too long restriction. In this case there helps a Stackexchange answer: How to delete a file in Windows with a too long filename?

Community's user avatar

answered Apr 5, 2016 at 17:27

user6162715's user avatar

Содержание

  1. Cannot install packages in Atom #14670
  2. Comments
  3. Prerequisites
  4. Description
  5. Steps to Reproduce
  6. Versions
  7. Unable to Install Certain Packages #5202
  8. Comments
  9. npm WARN enoent ENOENT: no such file or directory — when installing packages #14913
  10. Comments
  11. Prerequisites
  12. Description
  13. Steps to Reproduce
  14. Versions
  15. Additional Information
  16. Installing of packages failed #309
  17. Comments
  18. Can’t install Script Pckage on Atom #11798
  19. Comments
  20. Description
  21. Steps to Reproduce
  22. Versions

Cannot install packages in Atom #14670

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Reproduced the problem in Safe Mode: http://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
    • Followed all applicable steps in the debugging guide: http://flight-manual.atom.io/hacking-atom/sections/debugging/
    • Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
    • Checked that your issue isn’t already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
    • Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages

Description

Cannot install any packages, themes however install normally. This is the error I get:

I have tried on beta, and on stable none worked.

Steps to Reproduce

-Just try to install any package, and it will error. Doesn’t matter if it’s in safe mode or not.

Expected behavior: It will install the desired package.

Actual behavior: It does nothing and gives an error.

Reproduces how often: For me at least, it’s 100%.

Versions

Atom : 1.17.2
Electron: 1.3.15
Chrome : 52.0.2743.82
Node : 6.5.0

apm 1.17.0
npm 3.10.5
node 6.9.5 x64
python
git 2.13.0.windows.1
visual studio 2013

Windows 10, 10.0.10586 N/A Build 10586

The text was updated successfully, but these errors were encountered:

Just to confirm, did installing packages work fine in previous versions but started throwing this error for you as of 1.17.0 and 1.18.0-beta?

@rsese Yes, I do believe so. It worked before and then it stopped, I guess it updated automatically then.

Thanks for confirming — can you try temporarily resetting to factory defaults and see if you still get the same error?

I tried while reinstalling, I deleted the folder totally. I just tried again, unfortunately I got the same error again.

And what if you attempt to install from the command line? Syntax is apm install package-name .

Also gives the exact same error, I’ve already tried and just did again.

Not able to repro this on my machine. I think if this was happening to everybody we’d be seeing a lot more reports. Not sure what could be causing that.

I can understand, but Atom is such a great programm, I would like to install packages too 😀
Any ideas how I could fix that then?

The problem is we have no idea what could be causing which would be the first part of figuring out a fix. You could perhaps try unpacking the atom-windows.zip portable version.

I could not install packages in Atom, either. Nobody else’s tips worked for me, so below, I am posting what I did to get it to work.

I am running Fedora. Initially, I downloaded the Atom rpm package from the website, atom.io. I tried to install it by double-clicking it, but apper gave an error at the end.

I resort to Copr. There is a mosquito/atom package there. I enabled the repo and installed. At this point in the story, Atom is installed and working great.

The point of all this was just to edit a ReadMe with Markdown. I had the plain text on the left and the Markdown preview on the right, working spectacularly. Then something happens, an auto-update, I assume. After «the happening», whenever I edited the plain text, the preview would scroll to the bottom — extremely counter-productive and very annoying. I find the markdown-sync-scroll package, which was created to remedy this exact problem. I try to install the package, and it fails. I get an error about a version being undefined. The last line said «not ok».

I try installing the package from terminal using apm, with and without sudo, same error. I try updating nodejs and doing «npm rebuild». Same error. Uninstalling, reinstalling atom — same error.

Finally, I sudo dnf remove —purge atom . Then I delete /etc/yum.repos.d/_copr_mosquito-atom.repo . Then I go to the atom/atom ReadMe on github. I follow its link, download, and install that rpm by double-clicking it. This is not the one from the website, atom.io. Again, apper fails. But by luck, somehow I notice that it actually installed anyhow. I purged with dnf and tried to install the package via double-click several times before noticing that it actually does install, despite the apper error.

And this time, packages install. Now, I have Markdown editing how I want it! Yay!

Источник

Unable to Install Certain Packages #5202

I update my atom install going from the previous zip download, wiping all that away and using the new installer, but now certain packages won’t install.

Here is my error output from the install command

I have gotten Themes and some packages, like color-picker to install but most fail and it is this same error.

Is this more an NPM issue? I have looked at other issues but none seemed to throw this error.

The text was updated successfully, but these errors were encountered:

You need to install git. If you’re on Windows, type «Git for Windows» in Google, it’s the first result.

Beware, when i tried opening the git installer ti seemed to hang. Apparently «doing stuff» makes it work, so just browse the web for a few minutes and you’ll eventually get the installer to pop up. It was weird.

You will also need to close and reopen Atom once git is installed.

Finally, make sure to select the option to add git to your PATH variable. (the middle option, where it says «considered safe»)

I already have git. WIth Github for windows, plus I can install other packages, that as far as i can tell don’t have the harmony-collections package. I may be wrong about that part though.

Is git in your PATH?
On Jan 22, 2015 8:30 AM, «Lucas Brendel» notifications@github.com wrote:

I already have git. WIth Github for windows, plus I can install other
packages, that as far as i can tell don’t have the harmony-collections
package. I may be wrong about that part though.


Reply to this email directly or view it on GitHub
#5202 (comment).

Источник

npm WARN enoent ENOENT: no such file or directory — when installing packages #14913

Prerequisites

  • [ X ] Put an X between the brackets on this line if you have done all of the following:
    • Reproduced the problem in Safe Mode: http://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
    • Followed all applicable steps in the debugging guide: http://flight-manual.atom.io/hacking-atom/sections/debugging/
    • Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
    • Checked that your issue isn’t already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
    • Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages

Description

I recently updated to 1.18 with the Windows installer — note I am running as a non-Administrator on a corporate system. This changed the way I had previously installed to now installed in $HOMEAppDataLocal which is great. My existing packages survived, but I was getting errors when updating packages. I also cannot install packages. I can reproduce this reliably and I have reset to factory defaults (removed .atom ) and this problem persists.

The error appears to be related to the failed creation of the «apm-install» directory under $HOMEAppDataLocalTemp .

Steps to Reproduce

  1. Click Install on any community package
  2. Wait

Expected behavior: Package installs

Actual behavior: Install fails

Reproduces how often: 92.732%

This might reproduce 40 times in a row, then work 4 in a row.

Versions

Atom : 1.18.0
Electron: 1.3.15
Chrome : 52.0.2743.82
Node : 6.5.0

apm 1.18.1
npm 3.10.10
node 6.9.5 x64
python
git
visual studio

Additional Information

Error output from failed install:

Installing “vim-mode-plus@0.93.0” failed.Hide output…
C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udi
`— (empty)

npm WARN enoent ENOENT: no such file or directory, open ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udipackage.json’
npm WARN apm-install-dir-117528-20320-xdopcx.9igkl0udi No description
npm WARN apm-install-dir-117528-20320-xdopcx.9igkl0udi No repository field.
npm WARN apm-install-dir-117528-20320-xdopcx.9igkl0udi No README data
npm WARN apm-install-dir-117528-20320-xdopcx.9igkl0udi No license field.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv «C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmbinnode.exe» «C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmnode_modulesnpmbinnpm-cli.js» «—globalconfig» «C:Usersusername.atom.apm.apmrc» «—userconfig» «C:Usersusername.atom.apmrc» «install» «C:UsersusernameAppDataLocalTempd-117528-20320-15ra7t7.j2pxecdipackage.tgz» «—runtime=electron» «—target=1.3.15» «—arch=x64» «—global-style»
npm ERR! node v6.9.5
npm ERR! npm v3.10.10
npm ERR! path C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modulesvim-mode-plus
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename

npm ERR! Error: EPERM: operation not permitted, rename ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modulesvim-mode-plus’ -> ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modules.vim-mode-plus.DELETE’
npm ERR! at moveAway (C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmnode_modulesnpmlibinstallactionfinalize.js:38:5)
npm ERR! at destStatted (C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmnode_modulesnpmlibinstallactionfinalize.js:27:7)
npm ERR! at C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmnode_modulesnpmnode_modulesgraceful-fspolyfills.js:267:18
npm ERR! at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR!
npm ERR! Error: EPERM: operation not permitted, rename ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modulesvim-mode-plus’ -> ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modules.vim-mode-plus.DELETE’
npm ERR! at Error (native)
npm ERR! Error: EPERM: operation not permitted, rename ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modulesvim-mode-plus’ -> ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modules.vim-mode-plus.DELETE’
npm ERR! at moveAway (C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmnode_modulesnpmlibinstallactionfinalize.js:38:5)
npm ERR! at destStatted (C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmnode_modulesnpmlibinstallactionfinalize.js:27:7)
npm ERR! at C:UsersusernameAppDataLocalatomapp-1.18.0resourcesappapmnode_modulesnpmnode_modulesgraceful-fspolyfills.js:267:18
npm ERR! at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR!
npm ERR! Error: EPERM: operation not permitted, rename ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modulesvim-mode-plus’ -> ‘C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinode_modules.vim-mode-plus.DELETE’
npm ERR! at Error (native)
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR! C:UsersusernameAppDataLocalTempapm-install-dir-117528-20320-xdopcx.9igkl0udinpm-debug.log
npm ERR! code 1

The text was updated successfully, but these errors were encountered:

Источник

Installing of packages failed #309

Atom 0.182.0
Windows 7

When i try to install any package atom outputs:

apm install —check outputs:

I deinstalled atom, removed all atom folders an reinstalled again but without success.

The text was updated successfully, but these errors were encountered:

On my Win 8.1 machine, I did a fresh install of Atom 0.182. Then a download of atom_beautify failed:

Installing “atom-beautify@0.21.3” failed.Hide output…

npm ERR! git clone git://github.com/ariya/esprima.git Cloning into bare repository ‘C:Users.atom.apm_git-remotesgit-github-com-ariya-esprima-git-9077e517’.
npm ERR! git clone git://github.com/ariya/esprima.git fatal: unable to connect to github.com:
npm ERR! git clone git://github.com/ariya/esprima.git github.com[0: 192.30.252.131]: errno=No such file or directory
npm ERR! Windows_NT 6.2.9200
npm ERR! argv «C:Users AppDataLocalatomapp-0.182.0resourcesappapmbinnode.exe» «C:Users AppDataLocalatomapp-0.182.0resourcesappapmnode_modulesnpmbinnpm-cli.js» «—globalconfig» «C:Users .atom.apm.apmrc» «—userconfig» «C:Users .atom.apmrc» «install» «C:Users AppDataLocalTempd-115123-14324-i7y0mspackage.tgz» «—target=0.21.0» «—arch=ia32» «—msvs_version=2013»
npm ERR! node v0.10.35
npm ERR! npm v2.5.1
npm ERR! code 128

npm ERR! Command failed: Cloning into bare repository ‘C:Users.atom.apm_git-remotesgit-github-com-ariya-esprima-git-9077e517’.
npm ERR! fatal: unable to connect to github.com:
npm ERR! github.com[0: 192.30.252.131]: errno=No such file or directory
npm ERR!
npm ERR!
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! http://github.com/npm/npm/issues

I am behind a company proxy server. My .apmrc file that worked with older versions of Atom is at:

https-proxy=http://
http-proxy=http://
strict-ssl=false

apm now seems to be using:

but when I paste in proxy details there, apm or Atom deletes them when I try to install a package, and the package download fails.

Источник

Can’t install Script Pckage on Atom #11798

Description

I had installed latest version of atom text editor but can’t install Script Package in it.

Steps to Reproduce

Expected behavior: Successfully Install

Actual behavior:

Versions

Atom : 1.7.3
Electron: 0.36.8
Chrome : 47.0.2526.110
Node : 5.1.1

The text was updated successfully, but these errors were encountered:

@janoop have you tried running npm cache clean as the ERR message suggests and then trying to install the script?

yes but that makes no difference

Why are you using root to install the script in the home directory btw? Have you tried running the install command without sudo? or directly through Atom Editor?

apm install script

yes but it gives same error

Alright, since you tried installing apm package with sudo, try running sudo npm cache clean Also, clean cache folders in your atom editor.

/.atom/.npm) are download cache folders. Based on this info it’s safe to delete what’s inside those folders since it’s package caches. Try clearing out those and then try installing package through atom editor again.

make sure you quit atom editor before clearing folders.

Cool it worked thanks. Nikki1993,
so what i did is sudo npm cache clean
and then deleted all folders from

/.atom/.apm
and there was no directory named .npm so i created it and the
executed the command sudo apm install script
and this time output is Installing script to /home/nobodyu/.atom/packages ✓

Источник

I am having trouble installing any form of package in atom. I used a fresh install of Atom and Python 3.7.3 in Windows 10 64-bit.
I tried installing Platformio-ide-terminal but it resulted in an error
Then also tried installing atom-ide-terminal resulting in a similar error.

When going through the error I noticed one common line in both the errors:

gyp ERR! stack Error: Can't find Python executable "C:UsersAshwin BelbaseAppDataLocalProgramsPythonPython37python.EXE", you can set the PYTHON env variable.

(edit)
tried both through the atom>preferences>install and the CLI using apm install same errors.

Albin's user avatar

Albin

8,5645 gold badges41 silver badges76 bronze badges

asked Jul 27, 2019 at 14:12

CrYbAbY's user avatar

Update, August 20, 2019

The issue was fixed in Atom v1.40.1

Old answer

The said package is currently not working with Atom v1.39, since it includes a major update for the underlying Electron framework.

You can try and rebuild some of the package’s native modules. To do so, run apm rebuild inside the ~/.atom/packages/platformio-ide-terminal folder.

If that doesn’t work, a workaround is to downgrade Atom to v1.38.x and wait for a fix. You can follow this discussion or subscribe to the issue on GitHub for updates.

answered Jul 27, 2019 at 17:38

idleberg's user avatar

idlebergidleberg

1,3221 gold badge11 silver badges17 bronze badges

Today, suddenly, Atom can’t install any packages at all. It used to work fine earlier and I have a few packages installed already. But now it’s failing with Exit status 134. This is happening no matter what package I try to install. I tried Hydrogen and Atom Beautify,

I tried both the GUI from Atom’s settings as well as apm install ... (with and without sudo).

Here’s the stack trace:

> core-js@2.6.11 postinstall /tmp/apm-install-dir-120129-5590-622axg.s39i7/node_modules/atom-beautify/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"


npm WARN deprecated graceful-fs@2.0.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated jscs-preset-wikimedia@1.0.1: No longer maintained. We recomment migrating to ESLint with eslint-config-wikimedia.
npm WARN deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info.
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
Aborted (core dumped)
npm WARN enoent ENOENT: no such file or directory, open '/tmp/apm-install-dir-120129-5590-622axg.s39i7/package.json'
npm WARN apm-install-dir-120129-5590-622axg.s39i7 No description
npm WARN apm-install-dir-120129-5590-622axg.s39i7 No repository field.
npm WARN apm-install-dir-120129-5590-622axg.s39i7 No README data
npm WARN apm-install-dir-120129-5590-622axg.s39i7 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! core-js@2.6.11 postinstall: `node -e "try{require('./postinstall')}catch(e){}"`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the core-js@2.6.11 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.atom/.apm/_logs/2020-02-29T09_58_40_245Z-debug.log

The last lines of the log file has the very same stack.

The one thing that I have my suspicion on is the fact that I installed NodeJS and npm recently for an Angular project. Could this be causing the issue?

I’m on Pop!_OS (Ubuntu) 19.10, using npm 6.13.6, and Node v10.15.2.
Hitting atom -v gives me this (notice the difference between Node version from the one above):
Atom : 1.43.0
Electron: 4.2.7
Chrome : 69.0.3497.128
Node : 10.11.0

Update:
apm install language-vue worked but apm install atom-beautify and apm install hydrogen are still failing. No idea what’s wrong here.

Any suggestion would be lovely. Thanks in advance. :)

Я использую Ubuntu 16.04, и у меня возникла эта проблема. У меня был каталог / etc / hosts /, который был клонированной версией это репо.

Ясно, что каталог, названный так же, как файл, не совсем разумный ход, но я смог решить проблему, переместив каталог и снова запустив сценарий установки для репо. Сценарий установки вызывает a, который очищает файл DNS, находящийся в строке 1193 этот файл здесь.

Я извлек скрипт / функцию, которая должна помочь;

#!/usr/bin/env python3

# Script by Ben Limmer
# https://github.com/l1m5
#
# This Python script will combine all the host files you provide
# as sources into one, unique host file to keep you internet browsing happy.

import argparse
import fnmatch
import json
import locale
import os
import platform
import re
import shutil
import socket
import subprocess
import sys
import tempfile
import time
from glob import glob

import lxml  # noqa: F401
from bs4 import BeautifulSoup

# Detecting Python 3 for version-dependent implementations
PY3 = sys.version_info >= (3, 0)

if PY3:
    from urllib.request import urlopen
else:
    raise Exception("We do not support Python 2 anymore.")

# Syntactic sugar for "sudo" command in UNIX / Linux
if platform.system() == "OpenBSD":
    SUDO = ["/usr/bin/doas"]
else:
    SUDO = ["/usr/bin/env", "sudo"]


# Project Settings
BASEDIR_PATH = os.path.dirname(os.path.realpath(__file__))

def flush_dns_cache():
    """
    Flush the DNS cache.
    """

    print("Flushing the DNS cache to utilize new hosts file...")
    print(
        "Flushing the DNS cache requires administrative privileges. You might need to enter your password."
    )

    dns_cache_found = False

    if platform.system() == "Darwin":
        if subprocess.call(SUDO + ["killall", "-HUP", "mDNSResponder"]):
            print_failure("Flushing the DNS cache failed.")
    elif os.name == "nt":
        print("Automatically flushing the DNS cache is not yet supported.")
        print(
            "Please copy and paste the command 'ipconfig /flushdns' in "
            "administrator command prompt after running this script."
        )
    else:
        nscd_prefixes = ["/etc", "/etc/rc.d"]
        nscd_msg = "Flushing the DNS cache by restarting nscd {result}"

        for nscd_prefix in nscd_prefixes:
            nscd_cache = nscd_prefix + "/init.d/nscd"

            if os.path.isfile(nscd_cache):
                dns_cache_found = True

                if subprocess.call(SUDO + [nscd_cache, "restart"]):
                    print_failure(nscd_msg.format(result = "failed"))
                else:
                    print_success(nscd_msg.format(result = "succeeded"))

        centos_file = "/etc/init.d/network"
        centos_msg = "Flushing the DNS cache by restarting network {result}"

        if os.path.isfile(centos_file):
            if subprocess.call(SUDO + [centos_file, "restart"]):
                print_failure(centos_msg.format(result = "failed"))
            else:
                print_success(centos_msg.format(result = "succeeded"))

        system_prefixes = ["/usr", ""]
        service_types = ["NetworkManager", "wicd", "dnsmasq", "networking"]

        for system_prefix in system_prefixes:
            systemctl = system_prefix + "/bin/systemctl"
            system_dir = system_prefix + "/lib/systemd/system"

            for service_type in service_types:
                service = service_type + ".service"
                service_file = path_join_robust(system_dir, service)
                service_msg = (
                    "Flushing the DNS cache by restarting " + service + " {result}"
                )

                if os.path.isfile(service_file):
                    dns_cache_found = True

                    if subprocess.call(SUDO + [systemctl, "restart", service]):
                        print_failure(service_msg.format(result = "failed"))
                    else:
                        print_success(service_msg.format(result = "succeeded"))

        dns_clean_file = "/etc/init.d/dns-clean"
        dns_clean_msg = "Flushing the DNS cache via dns-clean executable {result}"

        if os.path.isfile(dns_clean_file):
            dns_cache_found = True

            if subprocess.call(SUDO + [dns_clean_file, "start"]):
                print_failure(dns_clean_msg.format(result = "failed"))
            else:
                print_success(dns_clean_msg.format(result = "succeeded"))

        if not dns_cache_found:
            print_failure("Unable to determine DNS management tool.")

Понравилась статья? Поделить с друзьями:
  • Atmosphere error code 2162 0002
  • Atmega chip enable program error
  • Audiodg exe ошибка
  • Audioclip error unsupported file format
  • Audio system was not initialized correctly error code 0 mount and blade