daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Nov 14th, 2018 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import std.process;
  2. import std.stdio;
  3. import std.range;
  4. import std.string;
  5. import std.algorithm.searching;
  6. import std.format;
  7. import std.conv;
  8. import std.file;
  9. import std.parallelism;
  10. import core.thread;
  11.  
  12. int ddOp(const string logFileName)
  13. {
  14.     immutable string fileName = "/run/media/user1101/portable_drive/software/os/archlinux-2018.11.01-x86_64.iso";
  15.     immutable string device = "/dev/sdd";
  16.     immutable string command = format("pkexec dd if=/%s of=%s bs=4M status=progress 2>%s && sync",
  17.             fileName, device, logFileName);
  18.  
  19.     return executeShell(command).status;
  20. }
  21.  
  22. uint parseLog(string logFileName)
  23. {
  24.     try
  25.     {
  26.         if (!(logFileName.exists))
  27.             return 0;
  28.         auto text = logFileName.readText();
  29.         if (text.splitLines().length == 0)
  30.             return 0;
  31.         if (text.text.splitLines.back.split.front.isNumeric)
  32.             return text.splitLines.back.split.front.to!uint;
  33.     }
  34.     catch (Exception e)
  35.     {
  36.         return 0;
  37.     }
  38.     return 0;
  39. }
  40.  
  41. void main()
  42. {
  43.     auto logFileName = "/tmp/.dd_op.txt";
  44.     auto invokedd = task!ddOp(logFileName);
  45.     invokedd.executeInNewThread();
  46.     while (!(invokedd.done))
  47.     {
  48.         Thread.sleep(500.msecs);
  49.         writeln(parseLog(logFileName));
  50.  
  51.     }
  52.     if (logFileName.exists())
  53.     {
  54.         logFileName.remove;
  55.         ddStarted = false;
  56.     }
  57.  
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top